leds: leds-ns2: Add of_node_put() before return
PATCH 1/1 leds: leds-ns2: Add of_node_put() before return
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 <[email protected]>
--- drivers/leds/leds-ns2.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/leds/leds-ns2.c +10 -3
@@ -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,
Signature · 1 line
2.19.1
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
Quoted 55 lines · Nishka Dasgupta
Each iteration of
for_each_child_of_nodeputs 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 anof_node_putbefore the return in four places.
Issue found with Coccinelle.Signed-off-by Nishka Dasgupta <[email protected]>--- drivers/leds/leds-ns2.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/leds/leds-ns2.c +10
-3@@ -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,