Skip to contentSkip to conversation

leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata()

PATCH Applied Nishka Dasgupta 3 participants 4 messages Jul 29, 2019 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata()

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.

---
 drivers/leds/leds-netxbig.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/leds/leds-netxbig.c +4 -2
index 10497a466775..654d83bbc450 100644
@@ -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) */
Signature · 1 line
2.19.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · 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.

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

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw
In reply to Nishka Dasgupta

Hi Nishka,

Thank you for the patch.

Quoted 24 lines · 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.

---
 drivers/leds/leds-netxbig.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/leds/leds-netxbig.c +2 -1
index 10497a466775..654d83bbc450 100644
@@ -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);

drivers/leds/leds-netxbig.c static int netxbig_leds_get_of_pdata(struct device *dev, · line 401

Quoted 10 lines
drivers/leds/leds-netxbig.c +2 -1
 		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.

Signature · 2 lines
Best regards,
Jacek Anaszewski
#3 lore raw
In reply to Nishka Dasgupta

Hi Nishka,

Thank you for the patch.

Quoted 24 lines · 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.

---
 drivers/leds/leds-netxbig.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/leds/leds-netxbig.c +2 -1
index 10497a466775..654d83bbc450 100644
@@ -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);

drivers/leds/leds-netxbig.c static int netxbig_leds_get_of_pdata(struct device *dev, · line 401

Quoted 10 lines
drivers/leds/leds-netxbig.c +2 -1
 		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.

Signature · 2 lines
Best regards,
Jacek Anaszewski