Linux-LEDs Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata()
@ 2019-07-29  6:53 Nishka Dasgupta
  2019-07-29 11:32 ` Pavel Machek
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nishka Dasgupta @ 2019-07-29  6:53 UTC (permalink / raw)
  To: jacek.anaszewski, pavel, dmurphy, linux-leds; +Cc: Nishka Dasgupta

The variable gpio_ext_np in the function netxbig_leds_get_of_pdata takes
the value returned by of_parse_phandle; hence, it must be put in order
to prevent a memory leak. Add an of_node_put for gpio_ext_np before a
return statement, and move a pre-existing of_node_put statement to right
after the last usage of this variable.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
 drivers/leds/leds-netxbig.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
index 10497a466775..654d83bbc450 100644
--- a/drivers/leds/leds-netxbig.c
+++ b/drivers/leds/leds-netxbig.c
@@ -388,12 +388,14 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
 	}
 
 	gpio_ext = devm_kzalloc(dev, sizeof(*gpio_ext), GFP_KERNEL);
-	if (!gpio_ext)
+	if (!gpio_ext) {
+		of_node_put(gpio_ext_np);
 		return -ENOMEM;
+	}
 	ret = gpio_ext_get_of_pdata(dev, gpio_ext_np, gpio_ext);
+	of_node_put(gpio_ext_np);
 	if (ret)
 		return ret;
-	of_node_put(gpio_ext_np);
 	pdata->gpio_ext = gpio_ext;
 
 	/* Timers (optional) */
-- 
2.19.1


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

* Re: [PATCH] leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata()
  2019-07-29  6:53 [PATCH] leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata() Nishka Dasgupta
@ 2019-07-29 11:32 ` Pavel Machek
  2019-07-29 19:20 ` Jacek Anaszewski
  2019-07-29 19:20 ` Jacek Anaszewski
  2 siblings, 0 replies; 4+ messages in thread
From: Pavel Machek @ 2019-07-29 11:32 UTC (permalink / raw)
  To: Nishka Dasgupta; +Cc: jacek.anaszewski, dmurphy, linux-leds

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

On Mon 2019-07-29 12:23:56, Nishka Dasgupta wrote:
> The variable gpio_ext_np in the function netxbig_leds_get_of_pdata takes
> the value returned by of_parse_phandle; hence, it must be put in order
> to prevent a memory leak. Add an of_node_put for gpio_ext_np before a
> return statement, and move a pre-existing of_node_put statement to right
> after the last usage of this variable.
> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>

Acked-by: Pavel Machek <pavel@ucw.cz>

Note that I don't want to see this in stable: leak is tiny and is only
in unlikely error paths.

Thanks,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH] leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata()
  2019-07-29  6:53 [PATCH] leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata() Nishka Dasgupta
  2019-07-29 11:32 ` Pavel Machek
  2019-07-29 19:20 ` Jacek Anaszewski
@ 2019-07-29 19:20 ` Jacek Anaszewski
  2 siblings, 0 replies; 4+ messages in thread
From: Jacek Anaszewski @ 2019-07-29 19:20 UTC (permalink / raw)
  To: Nishka Dasgupta, pavel, dmurphy, linux-leds

Hi Nishka,

Thank you for the patch.

On 7/29/19 8:53 AM, Nishka Dasgupta wrote:
> The variable gpio_ext_np in the function netxbig_leds_get_of_pdata takes
> the value returned by of_parse_phandle; hence, it must be put in order
> to prevent a memory leak. Add an of_node_put for gpio_ext_np before a
> return statement, and move a pre-existing of_node_put statement to right
> after the last usage of this variable.
> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
>  drivers/leds/leds-netxbig.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
> index 10497a466775..654d83bbc450 100644
> --- a/drivers/leds/leds-netxbig.c
> +++ b/drivers/leds/leds-netxbig.c
> @@ -388,12 +388,14 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
>  	}
>  
>  	gpio_ext = devm_kzalloc(dev, sizeof(*gpio_ext), GFP_KERNEL);
> -	if (!gpio_ext)
> +	if (!gpio_ext) {
> +		of_node_put(gpio_ext_np);
>  		return -ENOMEM;
> +	}
>  	ret = gpio_ext_get_of_pdata(dev, gpio_ext_np, gpio_ext);
> +	of_node_put(gpio_ext_np);
>  	if (ret)
>  		return ret;
> -	of_node_put(gpio_ext_np);
>  	pdata->gpio_ext = gpio_ext;
>  
>  	/* Timers (optional) */
> 

Applied.

-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata()
  2019-07-29  6:53 [PATCH] leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata() Nishka Dasgupta
  2019-07-29 11:32 ` Pavel Machek
@ 2019-07-29 19:20 ` Jacek Anaszewski
  2019-07-29 19:20 ` Jacek Anaszewski
  2 siblings, 0 replies; 4+ messages in thread
From: Jacek Anaszewski @ 2019-07-29 19:20 UTC (permalink / raw)
  To: Nishka Dasgupta, pavel, dmurphy, linux-leds

Hi Nishka,

Thank you for the patch.

On 7/29/19 8:53 AM, Nishka Dasgupta wrote:
> The variable gpio_ext_np in the function netxbig_leds_get_of_pdata takes
> the value returned by of_parse_phandle; hence, it must be put in order
> to prevent a memory leak. Add an of_node_put for gpio_ext_np before a
> return statement, and move a pre-existing of_node_put statement to right
> after the last usage of this variable.
> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
>  drivers/leds/leds-netxbig.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
> index 10497a466775..654d83bbc450 100644
> --- a/drivers/leds/leds-netxbig.c
> +++ b/drivers/leds/leds-netxbig.c
> @@ -388,12 +388,14 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
>  	}
>  
>  	gpio_ext = devm_kzalloc(dev, sizeof(*gpio_ext), GFP_KERNEL);
> -	if (!gpio_ext)
> +	if (!gpio_ext) {
> +		of_node_put(gpio_ext_np);
>  		return -ENOMEM;
> +	}
>  	ret = gpio_ext_get_of_pdata(dev, gpio_ext_np, gpio_ext);
> +	of_node_put(gpio_ext_np);
>  	if (ret)
>  		return ret;
> -	of_node_put(gpio_ext_np);
>  	pdata->gpio_ext = gpio_ext;
>  
>  	/* Timers (optional) */
> 

Applied.

-- 
Best regards,
Jacek Anaszewski

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29  6:53 [PATCH] leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata() Nishka Dasgupta
2019-07-29 11:32 ` Pavel Machek
2019-07-29 19:20 ` Jacek Anaszewski
2019-07-29 19:20 ` Jacek Anaszewski

Linux-LEDs Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-leds/0 linux-leds/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-leds linux-leds/ https://lore.kernel.org/linux-leds \
		linux-leds@vger.kernel.org linux-leds@archiver.kernel.org
	public-inbox-index linux-leds


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-leds


AGPL code for this site: git clone https://public-inbox.org/ public-inbox