]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hwmon: (emc2305) fix device node refcount leak in error path
authorPei Xiao <xiaopei01@kylinos.cn>
Fri, 5 Dec 2025 03:15:13 +0000 (11:15 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 7 Dec 2025 22:10:18 +0000 (14:10 -0800)
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>
drivers/hwmon/emc2305.c

index b0f2318c97e333e82ecfa99722f3b7368b878681..ceae96c07ac45baa11229d84c75cd4473ad3adfe 100644 (file)
@@ -683,8 +683,10 @@ static int emc2305_probe(struct i2c_client *client)
                        i = 0;
                        for_each_child_of_node(dev->of_node, child) {
                                ret = emc2305_set_single_tz(dev, child, i);
-                               if (ret != 0)
+                               if (ret != 0) {
+                                       of_node_put(child);
                                        return ret;
+                               }
                                i++;
                        }
                } else {