linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memory: tegra: Fix an error handling path in 'tegra186_emc_probe()'
@ 2020-05-06 20:09 Christophe JAILLET
  2020-05-07 19:27 ` Thierry Reding
  2020-05-08  8:49 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2020-05-06 20:09 UTC (permalink / raw)
  To: thierry.reding, jonathanh
  Cc: linux-tegra, linux-kernel, kernel-janitors, Christophe JAILLET

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>
---
 drivers/memory/tegra/tegra186-emc.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/memory/tegra/tegra186-emc.c b/drivers/memory/tegra/tegra186-emc.c
index 97f26bc77ad4..7b35bf6450f3 100644
--- a/drivers/memory/tegra/tegra186-emc.c
+++ b/drivers/memory/tegra/tegra186-emc.c
@@ -185,7 +185,7 @@ static int tegra186_emc_probe(struct platform_device *pdev)
 	if (IS_ERR(emc->clk)) {
 		err = PTR_ERR(emc->clk);
 		dev_err(&pdev->dev, "failed to get EMC clock: %d\n", err);
-		return err;
+		goto err_put_bpmp;
 	}
 
 	platform_set_drvdata(pdev, emc);
@@ -201,7 +201,7 @@ static int tegra186_emc_probe(struct platform_device *pdev)
 	err = tegra_bpmp_transfer(emc->bpmp, &msg);
 	if (err < 0) {
 		dev_err(&pdev->dev, "failed to EMC DVFS pairs: %d\n", err);
-		return err;
+		goto err_put_bpmp;
 	}
 
 	emc->debugfs.min_rate = ULONG_MAX;
@@ -211,8 +211,10 @@ static int tegra186_emc_probe(struct platform_device *pdev)
 
 	emc->dvfs = devm_kmalloc_array(&pdev->dev, emc->num_dvfs,
 				       sizeof(*emc->dvfs), GFP_KERNEL);
-	if (!emc->dvfs)
-		return -ENOMEM;
+	if (!emc->dvfs) {
+		err = -ENOMEM;
+		goto err_put_bpmp;
+	}
 
 	dev_dbg(&pdev->dev, "%u DVFS pairs:\n", emc->num_dvfs);
 
@@ -237,7 +239,7 @@ static int tegra186_emc_probe(struct platform_device *pdev)
 			"failed to set rate range [%lu-%lu] for %pC\n",
 			emc->debugfs.min_rate, emc->debugfs.max_rate,
 			emc->clk);
-		return err;
+		goto err_put_bpmp;
 	}
 
 	emc->debugfs.root = debugfs_create_dir("emc", NULL);
@@ -254,6 +256,10 @@ static int tegra186_emc_probe(struct platform_device *pdev)
 			    emc, &tegra186_emc_debug_max_rate_fops);
 
 	return 0;
+
+err_put_bpmp:
+	tegra_bpmp_put(emc->bpmp);
+	return err;
 }
 
 static int tegra186_emc_remove(struct platform_device *pdev)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] memory: tegra: Fix an error handling path in 'tegra186_emc_probe()'
  2020-05-06 20:09 [PATCH] memory: tegra: Fix an error handling path in 'tegra186_emc_probe()' Christophe JAILLET
@ 2020-05-07 19:27 ` Thierry Reding
  2020-05-08  8:49 ` Dan Carpenter
  1 sibling, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2020-05-07 19:27 UTC (permalink / raw)
  To: Christophe JAILLET; +Cc: jonathanh, linux-tegra, linux-kernel, kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

On Wed, May 06, 2020 at 10:09:07PM +0200, Christophe JAILLET wrote:
> 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>
> ---
>  drivers/memory/tegra/tegra186-emc.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)

Applied to for-5.8/memory, thanks.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] memory: tegra: Fix an error handling path in 'tegra186_emc_probe()'
  2020-05-06 20:09 [PATCH] memory: tegra: Fix an error handling path in 'tegra186_emc_probe()' Christophe JAILLET
  2020-05-07 19:27 ` Thierry Reding
@ 2020-05-08  8:49 ` Dan Carpenter
  2020-05-08  9:31   ` Marion & Christophe JAILLET
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2020-05-08  8:49 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: thierry.reding, jonathanh, linux-tegra, linux-kernel, kernel-janitors

On Wed, May 06, 2020 at 10:09:07PM +0200, Christophe JAILLET wrote:
> @@ -237,7 +239,7 @@ static int tegra186_emc_probe(struct platform_device *pdev)
>  			"failed to set rate range [%lu-%lu] for %pC\n",
>  			emc->debugfs.min_rate, emc->debugfs.max_rate,
>  			emc->clk);
> -		return err;
> +		goto err_put_bpmp;
>  	}
>  
>  	emc->debugfs.root = debugfs_create_dir("emc", NULL);

Not really related to this patch but the error handling on this
debugfs_create_dir() call is wrong.  It never returns NULL.  The error
should just be ignored.  It shouldn't try print a message when debugfs
is deliberately disabled.

As in the correct code looks like:

 
        emc->debugfs.root = debugfs_create_dir("emc", NULL);
-       if (!emc->debugfs.root) {
-               dev_err(&pdev->dev, "failed to create debugfs directory\n");
-               return 0;
-       }
-
        debugfs_create_file("available_rates", S_IRUGO, emc->debugfs.root,
                            emc, &tegra186_emc_debug_available_rates_fops);
        debugfs_create_file("min_rate", S_IRUGO | S_IWUSR, emc->debugfs.root,

debugfs_create_file() will return an error pointer if debugfs_create_dir()
fails or if debugfs is disabled.  (It is a no-op).

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] memory: tegra: Fix an error handling path in 'tegra186_emc_probe()'
  2020-05-08  8:49 ` Dan Carpenter
@ 2020-05-08  9:31   ` Marion & Christophe JAILLET
  0 siblings, 0 replies; 4+ messages in thread
From: Marion & Christophe JAILLET @ 2020-05-08  9:31 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: thierry.reding, jonathanh, linux-tegra, linux-kernel, kernel-janitors


Le 08/05/2020 à 10:49, Dan Carpenter a écrit :
> On Wed, May 06, 2020 at 10:09:07PM +0200, Christophe JAILLET wrote:
>> @@ -237,7 +239,7 @@ static int tegra186_emc_probe(struct platform_device *pdev)
>>   			"failed to set rate range [%lu-%lu] for %pC\n",
>>   			emc->debugfs.min_rate, emc->debugfs.max_rate,
>>   			emc->clk);
>> -		return err;
>> +		goto err_put_bpmp;
>>   	}
>>   
>>   	emc->debugfs.root = debugfs_create_dir("emc", NULL);
> Not really related to this patch but the error handling on this
> debugfs_create_dir() call is wrong.  It never returns NULL.  The error
> should just be ignored.  It shouldn't try print a message when debugfs
> is deliberately disabled.
>
> As in the correct code looks like:
>
>   
>          emc->debugfs.root = debugfs_create_dir("emc", NULL);
> -       if (!emc->debugfs.root) {
> -               dev_err(&pdev->dev, "failed to create debugfs directory\n");
> -               return 0;
> -       }
> -
>          debugfs_create_file("available_rates", S_IRUGO, emc->debugfs.root,
>                              emc, &tegra186_emc_debug_available_rates_fops);
>          debugfs_create_file("min_rate", S_IRUGO | S_IWUSR, emc->debugfs.root,
>
> debugfs_create_file() will return an error pointer if debugfs_create_dir()
> fails or if debugfs is disabled.  (It is a no-op).
>
> regards,
> dan carpenter

LGTM.

I let you propose a patch for it,.

CJ


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-08  9:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 20:09 [PATCH] memory: tegra: Fix an error handling path in 'tegra186_emc_probe()' Christophe JAILLET
2020-05-07 19:27 ` Thierry Reding
2020-05-08  8:49 ` Dan Carpenter
2020-05-08  9:31   ` Marion & Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).