Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ffc9b693 authored by Subhash Jadavani's avatar Subhash Jadavani
Browse files

scsi: ufshcd: release resources if probe fails



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.

Change-Id: Ic88c3e1d29a6b03e9a79201d3790f26bc4ccae61
Signed-off-by: default avatarSubhash Jadavani <subhashj@codeaurora.org>
parent 360013b1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -107,6 +107,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);
	pci_set_drvdata(pdev, NULL);
}

@@ -151,6 +152,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;
	}

+9 −11
Original line number Diff line number Diff line
@@ -111,19 +111,19 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
	if (ret && (ret != -EINVAL)) {
		dev_err(dev, "%s: error reading array %d\n",
				"freq-table-hz", ret);
		goto free_clkfreq;
		goto out;
	}

	for (i = 0; i < sz; i += 2) {
		ret = of_property_read_string_index(np,
				"clock-names", i/2, (const char **)&name);
		if (ret)
			goto free_clkfreq;
			goto out;

		clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL);
		if (!clki) {
			ret = -ENOMEM;
			goto free_clkfreq;
			goto out;
		}

		clki->min_freq = clkfreq[i];
@@ -133,8 +133,6 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
				clki->min_freq, clki->max_freq, clki->name);
		list_add_tail(&clki->list, &hba->clk_list_head);
	}
free_clkfreq:
	kfree(clkfreq);
out:
	return ret;
}
@@ -173,7 +171,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;
@@ -195,9 +193,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;
@@ -325,13 +320,13 @@ static int ufshcd_pltfrm_probe(struct platform_device *pdev)
	if (err) {
		dev_err(&pdev->dev, "%s: clock parse failed %d\n",
				__func__, err);
		goto out;
		goto dealloc_host;
	}
	err = ufshcd_parse_regulator_info(hba);
	if (err) {
		dev_err(&pdev->dev, "%s: regulator init failed %d\n",
				__func__, err);
		goto out;
		goto dealloc_host;
	}

	pm_runtime_set_active(&pdev->dev);
@@ -353,6 +348,8 @@ static int ufshcd_pltfrm_probe(struct platform_device *pdev)
out_disable_rpm:
	pm_runtime_disable(&pdev->dev);
	pm_runtime_set_suspended(&pdev->dev);
dealloc_host:
	ufshcd_dealloc_host(hba);
out:
	return err;
}
@@ -369,6 +366,7 @@ static int ufshcd_pltfrm_remove(struct platform_device *pdev)

	pm_runtime_get_sync(&(pdev)->dev);
	ufshcd_remove(hba);
	ufshcd_dealloc_host(hba);
	return 0;
}

+10 −3
Original line number Diff line number Diff line
@@ -5751,8 +5751,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);
@@ -5796,6 +5794,16 @@ out_error:
}
EXPORT_SYMBOL(ufshcd_alloc_host);

/**
 * ufshcd_dealloc_host - deallocate Host Bus Adapter (HBA)
 * @hba: pointer to Host Bus Adapter (HBA)
 */
void ufshcd_dealloc_host(struct ufs_hba *hba)
{
	scsi_host_put(hba->host);
}
EXPORT_SYMBOL(ufshcd_dealloc_host);

/**
 * ufshcd_set_dma_mask - Set dma mask based on the controller
 *			 addressing capability
@@ -6096,7 +6104,6 @@ exit_gating:
	ufshcd_exit_clk_gating(hba);
out_disable:
	hba->is_irq_enabled = false;
	scsi_host_put(host);
	UFSDBG_REMOVE_DEBUGFS(hba)
	ufshcd_hba_exit(hba);
out_error:
+1 −0
Original line number Diff line number Diff line
@@ -598,6 +598,7 @@ static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg)
}

int ufshcd_alloc_host(struct device *, struct ufs_hba **);
void ufshcd_dealloc_host(struct ufs_hba *);
int ufshcd_init(struct ufs_hba * , void __iomem * , unsigned int);
void ufshcd_remove(struct ufs_hba *);
int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask,