Skip to contentSkip to conversation

net: sgi: ioc3-eth: two teardown fixes

PATCH New Imre Kaloz 1 participant 3 messages Nov 16

Subsystems (5)
lore
Share & tools
lore

Imre Kaloz

author
#0 lore raw

cover net: sgi: ioc3-eth: two teardown fixes

Two teardown fixes for ioc3-eth: probe never stores the net_device that remove fetches, and the shared IRQ outlives free_netdev().

Tested on an SGI Fuel.

Imre Kaloz (2):
net: sgi: ioc3-eth: set platform drvdata in probe
net: sgi: ioc3-eth: fix IRQ lifetime against netdev teardown

 drivers/net/ethernet/sgi/ioc3-eth.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4

Signature · 1 line
2.47.3
author
#1 lore raw

PATCH 1/2 net: sgi: ioc3-eth: set platform drvdata in probe

ioc3eth_remove() fetches the net_device with platform_get_drvdata(), but probe never stores it, so unbinding the device oopses in unregister_netdev().

Reproduced and tested on an SGI Fuel.

---
 drivers/net/ethernet/sgi/ioc3-eth.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/sgi/ioc3-eth.c +1 -0
index 009f37105eaf..ee284a4f75ff 100644
@@ -848,6 +848,7 @@ static int ioc3eth_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	SET_NETDEV_DEV(dev, &pdev->dev);
+	platform_set_drvdata(pdev, dev);
 
 	ip = netdev_priv(dev);
 	ip->dma_dev = pdev->dev.parent;
Signature · 1 line
2.47.3
author
#2 lore raw

PATCH 2/2 net: sgi: ioc3-eth: fix IRQ lifetime against netdev teardown

In reply to Imre Kaloz

The shared IRQ is requested before the lock and timer its handler uses are initialized, and stays registered past free_netdev() on the probe error paths and in remove, so the handler can run on freed memory.

Reproduced with CONFIG_DEBUG_SHIRQ=y and slub_debug=P and tested on an SGI Fuel.

Fixes 0ce5ebd24d25 ("mfd: ioc3: Add driver for SGI IOC3 chip")
---
 drivers/net/ethernet/sgi/ioc3-eth.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/sgi/ioc3-eth.c +7 -5
index ee284a4f75ff..e322a588d5c4 100644
@@ -870,16 +870,16 @@ static int ioc3eth_probe(struct platform_device *pdev)
 		goto out_free;
 	}
 
-	if (devm_request_irq(&pdev->dev, dev->irq, ioc3_interrupt,
-			     IRQF_SHARED, "ioc3-eth", dev)) {
+	spin_lock_init(&ip->ioc3_lock);
+	timer_setup(&ip->ioc3_timer, ioc3_timer, 0);
+
+	if (request_irq(dev->irq, ioc3_interrupt, IRQF_SHARED, "ioc3-eth",
+			dev)) {
 		dev_err(&pdev->dev, "Can't get irq %d\n", dev->irq);
 		err = -ENODEV;
 		goto out_free;
 	}
 
-	spin_lock_init(&ip->ioc3_lock);
-	timer_setup(&ip->ioc3_timer, ioc3_timer, 0);
-
 	ioc3_stop(ip);
 
 	/* Allocate rx ring.  4kb = 512 entries, must be 4kb aligned */
@@ -951,6 +951,7 @@ static int ioc3eth_probe(struct platform_device *pdev)
 	return 0;
 
 out_stop:
+	free_irq(dev->irq, dev);
 	timer_delete_sync(&ip->ioc3_timer);
 	if (ip->rxr)
 		dma_free_coherent(ip->dma_dev, RX_RING_SIZE, ip->rxr,
@@ -969,6 +970,7 @@ static void ioc3eth_remove(struct platform_device *pdev)
 	struct ioc3_private *ip = netdev_priv(dev);
 
 	unregister_netdev(dev);
+	free_irq(dev->irq, dev);
 	timer_delete_sync(&ip->ioc3_timer);
 
 	dma_free_coherent(ip->dma_dev, RX_RING_SIZE, ip->rxr, ip->rxr_dma);
Signature · 1 line
2.47.3