Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

hwmon: (emc2305) fix device node refcount leak in error path

The for_each_child_of_node() macro automatically manages device node
reference counts during normal iteration. However, when breaking out
of the loop early with return, the current iteration's node is not
automatically released, leading to a reference count leak.

Fix this by adding of_node_put(child) before returning from the loop
when emc2305_set_single_tz() fails.

This issue could lead to memory leaks over multiple probe cycles.

Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
Link: https://lore.kernel.org/r/tencent_5CDC08544C901D5ECA270573D5AEE3117108@qq.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Pei Xiao and committed by
Guenter Roeck
4910da6b 541dfb49

+3 -1
+3 -1
drivers/hwmon/emc2305.c
··· 683 683 i = 0; 684 684 for_each_child_of_node(dev->of_node, child) { 685 685 ret = emc2305_set_single_tz(dev, child, i); 686 - if (ret != 0) 686 + if (ret != 0) { 687 + of_node_put(child); 687 688 return ret; 689 + } 688 690 i++; 689 691 } 690 692 } else {