Patchwork 3c59x: consolidate error cleanup in vortex_init_one()

login
register
mail settings
Submitter Sergei Shtylyov
Date June 9, 2013, 8:16 p.m.
Message ID <201306100016.52820.sergei.shtylyov@cogentembedded.com>
Download mbox | patch
Permalink /patch/250133/
State Accepted
Delegated to: David Miller
Headers show

Comments

Sergei Shtylyov - June 9, 2013, 8:16 p.m.
The PCI driver's probe() method  duplicates the error cleanup code each time it
has to do error exit. Consolidate the error cleanup code  in  one place and use
*goto* to jump to the right places.

Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

---
The patch is against Dave Miller's 'net-next.git' repo. 
Andrew Morton asked me to do this years ago.  It's high time to finally do this.
Too bad it doesn't save much...

 drivers/net/ethernet/3com/3c59x.c |   25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Steffen Klassert - June 10, 2013, 11:57 a.m.
On Mon, Jun 10, 2013 at 12:16:52AM +0400, Sergei Shtylyov wrote:
> The PCI driver's probe() method  duplicates the error cleanup code each time it
> has to do error exit. Consolidate the error cleanup code  in  one place and use
> *goto* to jump to the right places.
> 
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> 

Looks ok,

Acked-by: Steffen Klassert <klassert@mathematik.tu-chemnitz.de>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - June 12, 2013, 8:54 a.m.
From: Steffen Klassert <klassert@mathematik.tu-chemnitz.de>
Date: Mon, 10 Jun 2013 13:57:09 +0200

> On Mon, Jun 10, 2013 at 12:16:52AM +0400, Sergei Shtylyov wrote:
>> The PCI driver's probe() method  duplicates the error cleanup code each time it
>> has to do error exit. Consolidate the error cleanup code  in  one place and use
>> *goto* to jump to the right places.
>> 
>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>> 
> 
> Looks ok,
> 
> Acked-by: Steffen Klassert <klassert@mathematik.tu-chemnitz.de>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

Index: net-next/drivers/net/ethernet/3com/3c59x.c
===================================================================
--- net-next.orig/drivers/net/ethernet/3com/3c59x.c
+++ net-next/drivers/net/ethernet/3com/3c59x.c
@@ -1012,10 +1012,8 @@  static int vortex_init_one(struct pci_de
 		goto out;
 
 	rc = pci_request_regions(pdev, DRV_NAME);
-	if (rc < 0) {
-		pci_disable_device(pdev);
-		goto out;
-	}
+	if (rc < 0)
+		goto out_disable;
 
 	unit = vortex_cards_found;
 
@@ -1032,23 +1030,24 @@  static int vortex_init_one(struct pci_de
 	if (!ioaddr) /* If mapping fails, fall-back to BAR 0... */
 		ioaddr = pci_iomap(pdev, 0, 0);
 	if (!ioaddr) {
-		pci_release_regions(pdev);
-		pci_disable_device(pdev);
 		rc = -ENOMEM;
-		goto out;
+		goto out_release;
 	}
 
 	rc = vortex_probe1(&pdev->dev, ioaddr, pdev->irq,
 			   ent->driver_data, unit);
-	if (rc < 0) {
-		pci_iounmap(pdev, ioaddr);
-		pci_release_regions(pdev);
-		pci_disable_device(pdev);
-		goto out;
-	}
+	if (rc < 0)
+		goto out_iounmap;
 
 	vortex_cards_found++;
+	goto out;
 
+out_iounmap:
+	pci_iounmap(pdev, ioaddr);
+out_release:
+	pci_release_regions(pdev);
+out_disable:
+	pci_disable_device(pdev);
 out:
 	return rc;
 }