diff mbox series

thermal: armada: fix incorrect check for drvdata allocation failure

Message ID 20180730122716.6267-1-colin.king@canonical.com (mailing list archive)
State Rejected
Delegated to: Eduardo Valentin
Headers show
Series thermal: armada: fix incorrect check for drvdata allocation failure | expand

Commit Message

Colin King July 30, 2018, 12:27 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Currently the drvdata allocation failure is being incorrectly checked by
checking priv and not drvdata.  Fix this and also free priv to fix a
memory leak.

Detected by Coverity Scan, CID#1472102 ("Logically dead code")

Fixes: c9899c183921 ("thermal: armada: use the resource managed registration helper alternative")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/thermal/armada_thermal.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Daniel Lezcano July 30, 2018, 2:14 p.m. UTC | #1
Hi Colin,

On 30/07/2018 14:27, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently the drvdata allocation failure is being incorrectly checked by
> checking priv and not drvdata.  Fix this and also free priv to fix a
> memory leak.
> 
> Detected by Coverity Scan, CID#1472102 ("Logically dead code")
> 
> Fixes: c9899c183921 ("thermal: armada: use the resource managed registration helper alternative")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/thermal/armada_thermal.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
> index 4164a5a4e480..b164fd9f21ac 100644
> --- a/drivers/thermal/armada_thermal.c
> +++ b/drivers/thermal/armada_thermal.c
> @@ -611,8 +611,10 @@ static int armada_thermal_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  
>  	drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
> -	if (!priv)
> +	if (!drvdata) {
> +		devm_kfree(&pdev->dev, priv);

This is not necessary, resources will be free when the driver is
destroyed after the probe fails.

>  		return -ENOMEM;
> +	}
>  
>  	priv->dev = &pdev->dev;
>  	priv->data = (struct armada_thermal_data *)match->data;

Thanks for sending this fix. However, another fix was already submitted
for this.

  -- Daniel
Eduardo Valentin Aug. 20, 2018, 6:52 p.m. UTC | #2
hello Colin,

On Mon, Jul 30, 2018 at 01:27:16PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently the drvdata allocation failure is being incorrectly checked by
> checking priv and not drvdata.  Fix this and also free priv to fix a
> memory leak.
> 
> Detected by Coverity Scan, CID#1472102 ("Logically dead code")
> 
> Fixes: c9899c183921 ("thermal: armada: use the resource managed registration helper alternative")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/thermal/armada_thermal.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
> index 4164a5a4e480..b164fd9f21ac 100644
> --- a/drivers/thermal/armada_thermal.c
> +++ b/drivers/thermal/armada_thermal.c
> @@ -611,8 +611,10 @@ static int armada_thermal_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  
>  	drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
> -	if (!priv)
> +	if (!drvdata) {

Thanks for the fix but, I already collected this patch:

84b64de597bc ("thermal: armada: fix copy-paste error in armada_thermal_probe()")

which fixes the same issue you are addressing here.

> +		devm_kfree(&pdev->dev, priv);

As already mentioned by Daniel, the above is not necessary, as it is a
devm_* helper.

BR,
>  		return -ENOMEM;
> +	}
>  
>  	priv->dev = &pdev->dev;
>  	priv->data = (struct armada_thermal_data *)match->data;
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
index 4164a5a4e480..b164fd9f21ac 100644
--- a/drivers/thermal/armada_thermal.c
+++ b/drivers/thermal/armada_thermal.c
@@ -611,8 +611,10 @@  static int armada_thermal_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
-	if (!priv)
+	if (!drvdata) {
+		devm_kfree(&pdev->dev, priv);
 		return -ENOMEM;
+	}
 
 	priv->dev = &pdev->dev;
 	priv->data = (struct armada_thermal_data *)match->data;