Skip to contentSkip to conversation

net: sungem: fix probe error cleanup

PATCH Superseded Ruoyu Wang 2 participants 2 messages Jun 20 – Jun 22

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

PATCH 1/1 net: sungem: fix probe error cleanup

gem_init_one() calls gem_remove_one() when register_netdev() fails. That path unregisters and frees resources owned by the net_device, then probe continues into its own cleanup labels and touches the same state again.

Clear the driver data and remove the NAPI instance on this error path, then let the existing probe cleanup labels release the resources once.

---
 drivers/net/ethernet/sun/sungem.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/ethernet/sun/sungem.c +9 -4
index 8e69d917d827..26974ee71352 100644
@@ -2986,10 +2986,10 @@ static int gem_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	dev->max_mtu = GEM_MAX_MTU;
 
 	/* Register with kernel */
-	if (register_netdev(dev)) {
+	err = register_netdev(dev);
+	if (err) {
 		pr_err("Cannot register net device, aborting\n");
-		err = -ENOMEM;
-		goto err_out_free_consistent;
+		goto err_out_clear_drvdata;
 	}
 
 	/* Undo the get_cell with appropriate locking (we could use
@@ -3003,8 +3003,13 @@ static int gem_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		    dev->dev_addr);
 	return 0;
 
+err_out_clear_drvdata:
+	pci_set_drvdata(pdev, NULL);
+	netif_napi_del(&gp->napi);
+
 err_out_free_consistent:
-	gem_remove_one(pdev);
+	dma_free_coherent(&pdev->dev, sizeof(struct gem_init_block),
+			  gp->init_block, gp->gblock_dvma);
 err_out_iounmap:
 	gem_put_cell(gp);
 	iounmap(gp->regs);
reviewer
#1 lore raw
Quoted 7 lines · Ruoyu Wang

gem_init_one() calls gem_remove_one() when register_netdev() fails. That path unregisters and frees resources owned by the net_device, then probe continues into its own cleanup labels and touches the same state again.

Clear the driver data and remove the NAPI instance on this error path, then let the existing probe cleanup labels release the resources once.

Hi Ruoyu,

I think it would be useful to explain how this problem was found, naming any publicly available tools that were used.

And to explain what testing has occurred.

Quoted 1 line

A fixes tag should go here (no blank line between it and your Signed-off-by line).

Quoted 1 line

...

Signature · 1 line
pw-bot: changes-requested