scsi: ufshcd: release resources if probe fails
authorSubhash Jadavani <subhashj@codeaurora.org>
Fri, 28 Oct 2016 00:25:58 +0000 (17:25 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 8 Nov 2016 22:30:00 +0000 (17:30 -0500)
If ufshcd pltfrm/pci driver's probe fails for some reason then ensure
that scsi host is released to avoid memory leak but managed memory
allocations (via devm_* calls) need not to be freed explicitly on probe
failure as memory allocated with these functions is automatically freed
on driver detach.

Reviewed-by: Sahitya Tummala <stummala@codeaurora.org>
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/ufs/ufshcd-pci.c
drivers/scsi/ufs/ufshcd-pltfrm.c
drivers/scsi/ufs/ufshcd.c

index d15eaa466c59ffc7f48dda6a642c68de98de0b6d..52b546fb509b7a3636b8a9b65ee7f6c03dc10171 100644 (file)
@@ -104,6 +104,7 @@ static void ufshcd_pci_remove(struct pci_dev *pdev)
        pm_runtime_forbid(&pdev->dev);
        pm_runtime_get_noresume(&pdev->dev);
        ufshcd_remove(hba);
+       ufshcd_dealloc_host(hba);
 }
 
 /**
@@ -147,6 +148,7 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        err = ufshcd_init(hba, mmio_base, pdev->irq);
        if (err) {
                dev_err(&pdev->dev, "Initialization failed\n");
+               ufshcd_dealloc_host(hba);
                return err;
        }
 
index db53f38da864f76baa3c5f697b1673d109539c32..a72a4ba78125b09a135c781533d46b1cbf0bc042 100644 (file)
@@ -163,7 +163,7 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name,
        if (ret) {
                dev_err(dev, "%s: unable to find %s err %d\n",
                                __func__, prop_name, ret);
-               goto out_free;
+               goto out;
        }
 
        vreg->min_uA = 0;
@@ -185,9 +185,6 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name,
 
        goto out;
 
-out_free:
-       devm_kfree(dev, vreg);
-       vreg = NULL;
 out:
        if (!ret)
                *out_vreg = vreg;
index 5c931d1ba28830bba22da245cc98b8e270e1cad1..6c0082e2591e96f499d0bf9c2728571f2b4f09fc 100644 (file)
@@ -6253,8 +6253,6 @@ void ufshcd_remove(struct ufs_hba *hba)
        ufshcd_disable_intr(hba, hba->intr_mask);
        ufshcd_hba_stop(hba, true);
 
-       scsi_host_put(hba->host);
-
        ufshcd_exit_clk_gating(hba);
        if (ufshcd_is_clkscaling_enabled(hba))
                devfreq_remove_device(hba->devfreq);
@@ -6616,7 +6614,6 @@ exit_gating:
        ufshcd_exit_clk_gating(hba);
 out_disable:
        hba->is_irq_enabled = false;
-       scsi_host_put(host);
        ufshcd_hba_exit(hba);
 out_error:
        return err;