sdhci-pci: bad error handling in probe function
authorDan Carpenter <error27@gmail.com>
Fri, 10 Apr 2009 21:31:10 +0000 (23:31 +0200)
committerPierre Ossman <pierre@ossman.eu>
Sun, 3 May 2009 20:11:19 +0000 (22:11 +0200)
The goto unmap is too early, we haven't allocated host or done the
request_region().

Found by smatch (http://repo.or.cz/w/smatch.git).

[ Second error path fix by Pierre Ossman ]

Signed-off-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Pierre Ossman <pierre@ossman.eu>
drivers/mmc/host/sdhci-pci.c

index cd37962..65be279 100644 (file)
@@ -522,8 +522,8 @@ static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
 
        host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
        if (IS_ERR(host)) {
-               ret = PTR_ERR(host);
-               goto unmap;
+               dev_err(&pdev->dev, "cannot allocate host\n");
+               return ERR_PTR(PTR_ERR(host));
        }
 
        slot = sdhci_priv(host);
@@ -541,7 +541,7 @@ static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
        ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
        if (ret) {
                dev_err(&pdev->dev, "cannot request region\n");
-               return ERR_PTR(ret);
+               goto free;
        }
 
        addr = pci_resource_start(pdev, bar);
@@ -572,6 +572,8 @@ unmap:
 
 release:
        pci_release_region(pdev, bar);
+
+free:
        sdhci_free_host(host);
 
        return ERR_PTR(ret);