summaryrefslogtreecommitdiff
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorPei Xiao <xiaopei01@kylinos.cn>2025-12-05 11:15:13 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-01-02 12:57:03 +0100
commit76bced5efbf429c1f70475b4e29840b08ad816f2 (patch)
tree9345d85517e175548e959e9af09da020b0dc3aae /drivers/hwmon
parent4f7d90c7184a14dda6c1d38b5017ed0184357e9a (diff)
hwmon: (emc2305) fix device node refcount leak in error path
[ Upstream commit 4910da6b36b122db50a27fabf6ab7f8611b60bf8 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/emc2305.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/hwmon/emc2305.c b/drivers/hwmon/emc2305.c
index 60809289f816..84cb9b72cb6c 100644
--- a/drivers/hwmon/emc2305.c
+++ b/drivers/hwmon/emc2305.c
@@ -685,8 +685,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 {