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

power: supply: rk817: Fix node refcount leak

Dan Carpenter reports that the Smatch static checker warning has found
that there is another refcount leak in the probe function. While
of_node_put() was added in one of the return paths, it should in
fact be added for ALL return paths that return an error and at driver
removal time.

Fixes: 54c03bfd094f ("power: supply: Fix refcount leak in rk817_charger_probe")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Closes: https://lore.kernel.org/linux-pm/dc0bb0f8-212d-4be7-be69-becd2a3f9a80@kili.mountain/
Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
Link: https://lore.kernel.org/r/20230920145644.57964-1-macroalpha82@gmail.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Chris Morgan and committed by
Sebastian Reichel
488ef44c 3dc0bab2

+12 -3
+12 -3
drivers/power/supply/rk817_charger.c
··· 1045 1045 queue_delayed_work(system_wq, &charger->work, msecs_to_jiffies(8000)); 1046 1046 } 1047 1047 1048 + static void rk817_cleanup_node(void *data) 1049 + { 1050 + struct device_node *node = data; 1051 + 1052 + of_node_put(node); 1053 + } 1054 + 1048 1055 static int rk817_charger_probe(struct platform_device *pdev) 1049 1056 { 1050 1057 struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); ··· 1068 1061 if (!node) 1069 1062 return -ENODEV; 1070 1063 1064 + ret = devm_add_action_or_reset(&pdev->dev, rk817_cleanup_node, node); 1065 + if (ret) 1066 + return ret; 1067 + 1071 1068 charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); 1072 - if (!charger) { 1073 - of_node_put(node); 1069 + if (!charger) 1074 1070 return -ENOMEM; 1075 - } 1076 1071 1077 1072 charger->rk808 = rk808; 1078 1073