* [PATCH] leds: leds-ns2: Add of_node_put() before return
@ 2019-07-09 17:34 Nishka Dasgupta
2019-07-15 19:58 ` Jacek Anaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Nishka Dasgupta @ 2019-07-09 17:34 UTC (permalink / raw)
To: jacek.anaszewski, pavel, dmurphy, linux-leds; +Cc: Nishka Dasgupta
Each iteration of for_each_child_of_node puts the previous node, but in
the case of a return from the middle of the loop, there is no put, thus
causing a memory leak. Hence add an of_node_put before the return in
four places.
Issue found with Coccinelle.
Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
drivers/leds/leds-ns2.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index f92e2c07c1c6..6e47c21ef1c4 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -263,12 +263,16 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
struct ns2_led_modval *modval;
ret = of_get_named_gpio(child, "cmd-gpio", 0);
- if (ret < 0)
+ if (ret < 0) {
+ of_node_put(child);
return ret;
+ }
led->cmd = ret;
ret = of_get_named_gpio(child, "slow-gpio", 0);
- if (ret < 0)
+ if (ret < 0) {
+ of_node_put(child);
return ret;
+ }
led->slow = ret;
ret = of_property_read_string(child, "label", &string);
led->name = (ret == 0) ? string : child->name;
@@ -281,6 +285,7 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
if (ret < 0 || ret % 3) {
dev_err(dev,
"Missing or malformed modes-map property\n");
+ of_node_put(child);
return -EINVAL;
}
@@ -289,8 +294,10 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
num_modes,
sizeof(struct ns2_led_modval),
GFP_KERNEL);
- if (!modval)
+ if (!modval) {
+ of_node_put(child);
return -ENOMEM;
+ }
for (i = 0; i < num_modes; i++) {
of_property_read_u32_index(child,
--
2.19.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] leds: leds-ns2: Add of_node_put() before return
2019-07-09 17:34 [PATCH] leds: leds-ns2: Add of_node_put() before return Nishka Dasgupta
@ 2019-07-15 19:58 ` Jacek Anaszewski
0 siblings, 0 replies; 2+ messages in thread
From: Jacek Anaszewski @ 2019-07-15 19:58 UTC (permalink / raw)
To: Nishka Dasgupta, pavel, dmurphy, linux-leds
Hi Nishka,
Thank you for the patch.
Please apply err_node_put scheme similarly like you've already
done that for leds-max77650.
Best regards,
Jacek Anaszewski
On 7/9/19 7:34 PM, Nishka Dasgupta wrote:
> Each iteration of for_each_child_of_node puts the previous node, but in
> the case of a return from the middle of the loop, there is no put, thus
> causing a memory leak. Hence add an of_node_put before the return in
> four places.
> Issue found with Coccinelle.
>
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
> drivers/leds/leds-ns2.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
> index f92e2c07c1c6..6e47c21ef1c4 100644
> --- a/drivers/leds/leds-ns2.c
> +++ b/drivers/leds/leds-ns2.c
> @@ -263,12 +263,16 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
> struct ns2_led_modval *modval;
>
> ret = of_get_named_gpio(child, "cmd-gpio", 0);
> - if (ret < 0)
> + if (ret < 0) {
> + of_node_put(child);
> return ret;
> + }
> led->cmd = ret;
> ret = of_get_named_gpio(child, "slow-gpio", 0);
> - if (ret < 0)
> + if (ret < 0) {
> + of_node_put(child);
> return ret;
> + }
> led->slow = ret;
> ret = of_property_read_string(child, "label", &string);
> led->name = (ret == 0) ? string : child->name;
> @@ -281,6 +285,7 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
> if (ret < 0 || ret % 3) {
> dev_err(dev,
> "Missing or malformed modes-map property\n");
> + of_node_put(child);
> return -EINVAL;
> }
>
> @@ -289,8 +294,10 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
> num_modes,
> sizeof(struct ns2_led_modval),
> GFP_KERNEL);
> - if (!modval)
> + if (!modval) {
> + of_node_put(child);
> return -ENOMEM;
> + }
>
> for (i = 0; i < num_modes; i++) {
> of_property_read_u32_index(child,
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-15 19:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-09 17:34 [PATCH] leds: leds-ns2: Add of_node_put() before return Nishka Dasgupta
2019-07-15 19:58 ` Jacek Anaszewski
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).