Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

memory: tegra: Fix an error handling path in tegra186_emc_probe()

The call to tegra_bpmp_get() must be balanced by a call to
tegra_bpmp_put() in case of error, as already done in the remove
function.

Add an error handling path and corresponding goto.

Fixes: 52d15dd23f0b ("memory: tegra: Support DVFS on Tegra186 and later")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Thierry Reding <treding@nvidia.com>

authored by

Christophe JAILLET and committed by
Thierry Reding
c3d4eb3b 930c6818

+11 -5
+11 -5
drivers/memory/tegra/tegra186-emc.c
··· 185 185 if (IS_ERR(emc->clk)) { 186 186 err = PTR_ERR(emc->clk); 187 187 dev_err(&pdev->dev, "failed to get EMC clock: %d\n", err); 188 - return err; 188 + goto put_bpmp; 189 189 } 190 190 191 191 platform_set_drvdata(pdev, emc); ··· 201 201 err = tegra_bpmp_transfer(emc->bpmp, &msg); 202 202 if (err < 0) { 203 203 dev_err(&pdev->dev, "failed to EMC DVFS pairs: %d\n", err); 204 - return err; 204 + goto put_bpmp; 205 205 } 206 206 207 207 emc->debugfs.min_rate = ULONG_MAX; ··· 211 211 212 212 emc->dvfs = devm_kmalloc_array(&pdev->dev, emc->num_dvfs, 213 213 sizeof(*emc->dvfs), GFP_KERNEL); 214 - if (!emc->dvfs) 215 - return -ENOMEM; 214 + if (!emc->dvfs) { 215 + err = -ENOMEM; 216 + goto put_bpmp; 217 + } 216 218 217 219 dev_dbg(&pdev->dev, "%u DVFS pairs:\n", emc->num_dvfs); 218 220 ··· 239 237 "failed to set rate range [%lu-%lu] for %pC\n", 240 238 emc->debugfs.min_rate, emc->debugfs.max_rate, 241 239 emc->clk); 242 - return err; 240 + goto put_bpmp; 243 241 } 244 242 245 243 emc->debugfs.root = debugfs_create_dir("emc", NULL); ··· 256 254 emc, &tegra186_emc_debug_max_rate_fops); 257 255 258 256 return 0; 257 + 258 + put_bpmp: 259 + tegra_bpmp_put(emc->bpmp); 260 + return err; 259 261 } 260 262 261 263 static int tegra186_emc_remove(struct platform_device *pdev)