Skip to contentSkip to conversation

r6040: disable pci device if the subsequent calls (after pci_enable_device) fails

PATCH Applied Devendra Naga 3 participants 8 messages May 28, 2012 – May 29, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 r6040: disable pci device if the subsequent calls (after pci_enable_device) fails

the calls after the pci_enable_device may fail, and will error out with out disabling it. disable the device at error paths.

---
 drivers/net/ethernet/rdc/r6040.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/ethernet/rdc/r6040.c +6 -4
index 4de7364..8f5079a 100644
@@ -1096,20 +1096,20 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
 	if (err) {
 		dev_err(&pdev->dev, "32-bit PCI DMA addresses"
 				"not supported by the card\n");
-		goto err_out;
+		goto err_out_disable_dev;
 	}
 	err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
 	if (err) {
 		dev_err(&pdev->dev, "32-bit PCI DMA addresses"
 				"not supported by the card\n");
-		goto err_out;
+		goto err_out_disable_dev;
 	}
 
 	/* IO Size check */
 	if (pci_resource_len(pdev, bar) < io_size) {
 		dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n");
 		err = -EIO;
-		goto err_out;
+		goto err_out_disable_dev;
 	}
 
 	pci_set_master(pdev);
@@ -1117,7 +1117,7 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
 	dev = alloc_etherdev(sizeof(struct r6040_private));
 	if (!dev) {
 		err = -ENOMEM;
-		goto err_out;
+		goto err_out_disable_dev;
 	}
 	SET_NETDEV_DEV(dev, &pdev->dev);
 	lp = netdev_priv(dev);
@@ -1238,6 +1238,8 @@ err_out_free_res:
 	pci_release_regions(pdev);
 err_out_free_dev:
 	free_netdev(dev);
+err_out_disable_dev:
+	pci_disable_device(dev);
 err_out:
 	return err;
 }
Signature · 1 line
1.7.9.5
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · On Monday 28 May 2012 17:27:03 Devendra Naga wrote:

the calls after the pci_enable_device may fail, and will error out with out disabling it. disable the device at error paths.

Looks good, thanks Devendra!

Quoted 2 lines

Review

Quoted 5 lines
---
 drivers/net/ethernet/rdc/r6040.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/rdc/r6040.c

drivers/net/ethernet/rdc/r6040.c static int __devinit r6040_init_one(struct pci_dev

Quoted 4 lines

index 4de7364..8f5079a 100644

drivers/net/ethernet/rdc/r6040.c +0 -0
@@ -1096,20 +1096,20 @@ static int __devinit r6040_init_one(struct pci_dev 

*pdev,

drivers/net/ethernet/rdc/r6040.c static int __devinit r6040_init_one(struct pci_dev

Quoted 24 lines
drivers/net/ethernet/rdc/r6040.c +3 -3
 	if (err) {
 		dev_err(&pdev->dev, "32-bit PCI DMA addresses"
 				"not supported by the card\n");
-		goto err_out;
+		goto err_out_disable_dev;
 	}
 	err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
 	if (err) {
 		dev_err(&pdev->dev, "32-bit PCI DMA addresses"
 				"not supported by the card\n");
-		goto err_out;
+		goto err_out_disable_dev;
 	}
 
 	/* IO Size check */
 	if (pci_resource_len(pdev, bar) < io_size) {
 		dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n");
 		err = -EIO;
-		goto err_out;
+		goto err_out_disable_dev;
 	}
 
 	pci_set_master(pdev);
@@ -1117,7 +1117,7 @@ static int __devinit r6040_init_one(struct pci_dev 

*pdev,

Quoted 20 lines
drivers/net/ethernet/rdc/r6040.c +3 -1
 	dev = alloc_etherdev(sizeof(struct r6040_private));
 	if (!dev) {
 		err = -ENOMEM;
-		goto err_out;
+		goto err_out_disable_dev;
 	}
 	SET_NETDEV_DEV(dev, &pdev->dev);
 	lp = netdev_priv(dev);
@@ -1238,6 +1238,8 @@ err_out_free_res:
 	pci_release_regions(pdev);
 err_out_free_dev:
 	free_netdev(dev);
+err_out_disable_dev:
+	pci_disable_device(dev);
 err_out:
 	return err;
 }
Signature · 1 line
1.7.9.5
#2 lore raw

Hello Florian,

Quoted 59 lines · Florian Fainelli
Quoted 2 lines · On Monday 28 May 2012 17:27:03 Devendra Naga wrote:

the calls after the pci_enable_device may fail, and will error out with out disabling it. disable the device at error paths.

Looks good, thanks Devendra!

Quoted 2 lines

Review

Quoted 5 lines

---
 drivers/net/ethernet/rdc/r6040.c |   10 ++++++----

 1 file changed, 6 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/rdc/r6040.c

drivers/net/ethernet/rdc/r6040.c static int __devinit r6040_init_one(struct pci_dev

Quoted 4 lines

index 4de7364..8f5079a 100644

drivers/net/ethernet/rdc/r6040.c +0 -0
@@ -1096,20 +1096,20 @@ static int __devinit r6040_init_one(struct pci_dev

*pdev,

drivers/net/ethernet/rdc/r6040.c static int __devinit r6040_init_one(struct pci_dev

Quoted 24 lines
drivers/net/ethernet/rdc/r6040.c +0 -0
       if (err) {

              dev_err(&pdev->dev, "32-bit PCI DMA addresses" "not supported by the card\n");
-             goto err_out;
+             goto err_out_disable_dev;
      }
      err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); if (err) {
              dev_err(&pdev->dev, "32-bit PCI DMA addresses" "not supported by the card\n");
-             goto err_out;
+             goto err_out_disable_dev;
      }

      /* IO Size check */
      if (pci_resource_len(pdev, bar) < io_size) { dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n"); err = -EIO;
-             goto err_out;
+             goto err_out_disable_dev;
      }

      pci_set_master(pdev);

drivers/net/ethernet/rdc/r6040.c +0 -0
@@ -1117,7 +1117,7 @@ static int __devinit r6040_init_one(struct pci_dev

*pdev,

Quoted 12 lines
drivers/net/ethernet/rdc/r6040.c +1 -1
       dev = alloc_etherdev(sizeof(struct r6040_private));
       if (!dev) {
               err = -ENOMEM;
-             goto err_out;
+             goto err_out_disable_dev;
       }
       SET_NETDEV_DEV(dev, &pdev->dev);
       lp = netdev_priv(dev);
@@ -1238,6 +1238,8 @@ err_out_free_res:
       pci_release_regions(pdev);

 err_out_free_dev:
      free_netdev(dev);

Quoted 8 lines
Quoted 8 lines

+err_out_disable_dev:
+     pci_disable_device(dev);
 err_out:
      return err;
 }
--
1.7.9.5

Thanks for the Ack.
I found one more problem. Its when mdiobus_alloc fails in r6040_init_one, we need to do call to the netif_napi_del and set the NULL to pci_set_drvdata, at err_out_unmap.

Thanks,
Devendra.

#3 lore raw
Quoted 3 lines · On Tuesday 29 May 2012 15:28:51 devendra.aaru wrote:

Hello Florian,

On Tue, May 29, 2012 at 2:50 PM, Florian Fainelli <[email protected]>

Quoted 5 lines · wrote:

Thanks for the Ack.
I found one more problem. Its when mdiobus_alloc fails in r6040_init_one, we need to do call to the netif_napi_del and set the NULL to pci_set_drvdata, at err_out_unmap.

Ok, can you please submit a patch to fix this issue as well? Thanks! --
Florian

#4 lore raw

Hi Florian,

Quoted 11 lines
Quoted 1 line

On Tue, May 29, 2012 at 2:50 PM, Florian Fainelli <[email protected]>

Quoted 5 lines · wrote:

Thanks for the Ack.
I found one more problem. Its when mdiobus_alloc fails in r6040_init_one, we need to do call to the netif_napi_del and set the NULL to pci_set_drvdata, at  err_out_unmap.

Ok, can you please submit a patch to fix this issue as well? Thanks! --

Ok sure. will be doing it shortly.

Quoted 1 line

Florian

Thanks,
Devendra.

maintainer Applied
#5 lore raw
In reply to Florian Fainelli

From: Florian Fainelli <[email protected]>
Date: Tue, 29 May 2012 11:20:50 +0200

Quoted 10 lines · On Monday 28 May 2012 17:27:03 Devendra Naga wrote:
Quoted 2 lines

the calls after the pci_enable_device may fail, and will error out with out disabling it. disable the device at error paths.

Looks good, thanks Devendra!

Quoted 2 lines

Applied.

maintainer
#6 lore raw

From: David Miller <[email protected]>
Date: Tue, 29 May 2012 17:22:29 -0400 (EDT)

Quoted 7 lines

From: Florian Fainelli <[email protected]>
Date: Tue, 29 May 2012 11:20:50 +0200

Quoted 4 lines · On Monday 28 May 2012 17:27:03 Devendra Naga wrote:
Quoted 2 lines

the calls after the pci_enable_device may fail, and will error out with out disabling it. disable the device at error paths.

Quoted 8 lines
Quoted 6 lines

Looks good, thanks Devendra!

Quoted 2 lines

Applied.

Actually, reverted, you didn't test this patch at all.

You didn't even look at the warnings emitted by the compiler with your changes installed.

You're passing a network device pointer into the PCI device disable routine, which takes a PCI device pointer.

I can't express to you how extremely irritating it is when people submit patches like this.

The bug in question is 1,000 times less harmful than your fix.

#7 lore raw

Hi David,

Quoted 8 lines · David Miller

From: David Miller <[email protected]>
Date: Tue, 29 May 2012 17:22:29 -0400 (EDT)

Actually, reverted, you didn't test this patch at all.

You didn't even look at the warnings emitted by the compiler with your changes installed.

Quoted 7 lines

You're passing a network device pointer into the PCI device disable routine, which takes a PCI device pointer.

I can't express to you how extremely irritating it is when people submit patches like this.

The bug in question is 1,000 times less harmful than your fix.

Sorry about that, i agree that i didn't even tested it as i dont have r6040 network adapter here, but i didn't even compiled it.

i sent the patch again to fix this problem.

Sorry,
Devendra.