Skip to contentSkip to conversation

leds: netxbig: Fix refcount leak in netxbig_leds_get_of_pdata

PATCH Superseded Miaoqian Lin 2 participants 2 messages May 12, 2022 LED

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: netxbig: Fix refcount leak in netxbig_leds_get_of_pdata

of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not needed anymore. When of_find_device_by_node() fails, of_node_put() is missing.

Fixes 9af512e81964 ("leds: netxbig: Convert to use GPIO descriptors")
---
 drivers/leds/leds-netxbig.c | 1 +
 1 file changed, 1 insertion(+)
drivers/leds/leds-netxbig.c +1 -0
index 77213b79f84d..ceb046500469 100644
@@ -441,6 +441,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
 	gpio_ext_pdev = of_find_device_by_node(gpio_ext_np);
 	if (!gpio_ext_pdev) {
 		dev_err(dev, "Failed to find platform device for gpio-ext\n");
+		of_node_put(gpio_ext_np);
 		return -ENODEV;
 	}
 	gpio_ext_dev = &gpio_ext_pdev->dev;
Signature · 1 line
2.25.1
#1 lore raw

Hi!

Quoted 3 lines

of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not needed anymore. When of_find_device_by_node() fails, of_node_put() is missing.

Can you take a look at the code and simplify it? AFAICT the node_put should go right after

       gpio_ext_pdev = of_find_device_by_node(gpio_ext_np);

. Best regards,
Pavel

Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.