[SCSI] ipr: reorder error handling code to include iounmap
authorJulia Lawall <julia@diku.dk>
Mon, 11 Jul 2011 21:08:25 +0000 (14:08 -0700)
committerJames Bottomley <JBottomley@Parallels.com>
Wed, 27 Jul 2011 13:45:08 +0000 (17:45 +0400)
The out_msi_disable label should be before cleanup_nomem to additionally
benefit from the call to iounmap.  Subsequent gotos are adjusted to go to
out_msi_disable instead of cleanup_nomem, which now follows it.  This is
safe because pci_disable_msi does nothing if pci_enable_msi was not called.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
expression e1,e2;
statement S;
@@

e1 = pci_ioremap_bar(...);
... when != e1 = e2
    when != iounmap(e1)
    when any
(
 if (<+...e1...+>) S
|
 if(...) { ... return 0; }
|
 if (...) { ... when != iounmap(e1)
                when != if (...) { ... iounmap(e1) ... }
* return ...;
 } else S
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Acked-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/ipr.c

index 888086c4e709497e6d8c7ae9e02dcf06b5bbca18..8d636301e32c4ba289bffe22300739b396ccd566 100644 (file)
@@ -8778,14 +8778,14 @@ static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
        if (rc != PCIBIOS_SUCCESSFUL) {
                dev_err(&pdev->dev, "Failed to save PCI config space\n");
                rc = -EIO;
-               goto cleanup_nomem;
+               goto out_msi_disable;
        }
 
        if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
-               goto cleanup_nomem;
+               goto out_msi_disable;
 
        if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
-               goto cleanup_nomem;
+               goto out_msi_disable;
 
        if (ioa_cfg->sis64)
                ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
@@ -8800,7 +8800,7 @@ static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
        if (rc < 0) {
                dev_err(&pdev->dev,
                        "Couldn't allocate enough memory for device driver!\n");
-               goto cleanup_nomem;
+               goto out_msi_disable;
        }
 
        /*
@@ -8845,10 +8845,10 @@ out:
 
 cleanup_nolog:
        ipr_free_mem(ioa_cfg);
-cleanup_nomem:
-       iounmap(ipr_regs);
 out_msi_disable:
        pci_disable_msi(pdev);
+cleanup_nomem:
+       iounmap(ipr_regs);
 out_release_regions:
        pci_release_regions(pdev);
 out_scsi_host_put: