Messages in this thread Patch in this message | | | Date | Fri, 9 Apr 2021 12:33:55 +0200 | From | Pavel Machek <> | Subject | Re: [PATCH 5.10 06/41] net: pxa168_eth: Fix a potential data race in pxa168_eth_remove |
| |
Hi!
> [ Upstream commit 0571a753cb07982cc82f4a5115e0b321da89e1f3 ] > > pxa168_eth_remove() firstly calls unregister_netdev(), > then cancels a timeout work. unregister_netdev() shuts down a device > interface and removes it from the kernel tables. If the timeout occurs > in parallel, the timeout work (pxa168_eth_tx_timeout_task) performs stop > and open of the device. It may lead to an inconsistent state and memory > leaks.
AFAICT the timeout work does a lot of processing, including pxa168_eth_open(), pxa168_init_phy() and phy_connect_direct(). We probably don't want that to run with clock being disabled and DMA being unmapped.
We certainly don't want phy_disconnect() being undone by phy_connect_direct() running in the workqueue.
IOW this patch is not enough to fix the bugs, and at least fix below is needed to get something reasonable.
Signed-off-by: Pavel Machek (CIP) <pavel@denx.de>
Best regards, Pavel
> +++ b/drivers/net/ethernet/marvell/pxa168_eth.c > @@ -1544,8 +1544,8 @@ static int pxa168_eth_remove(struct platform_device *pdev) > clk_disable_unprepare(pep->clk); > mdiobus_unregister(pep->smi_bus); > mdiobus_free(pep->smi_bus); > - unregister_netdev(dev); > cancel_work_sync(&pep->tx_timeout_task); > + unregister_netdev(dev); > free_netdev(dev); > return 0; > }
diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethernet/marvell/pxa168_eth.c index d1e4d42e497d..432be22a51be 100644 --- a/drivers/net/ethernet/marvell/pxa168_eth.c +++ b/drivers/net/ethernet/marvell/pxa168_eth.c @@ -1532,7 +1532,8 @@ static int pxa168_eth_remove(struct platform_device *pdev) { struct net_device *dev = platform_get_drvdata(pdev); struct pxa168_eth_private *pep = netdev_priv(dev); - + + cancel_work_sync(&pep->tx_timeout_task); if (pep->htpr) { dma_free_coherent(pep->dev->dev.parent, HASH_ADDR_TABLE_SIZE, pep->htpr, pep->htpr_dma); @@ -1545,7 +1546,6 @@ static int pxa168_eth_remove(struct platform_device *pdev) mdiobus_unregister(pep->smi_bus); mdiobus_free(pep->smi_bus); unregister_netdev(dev); - cancel_work_sync(&pep->tx_timeout_task); free_netdev(dev); return 0; } -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany [unhandled content-type:application/pgp-signature] | |