Skip to content

Commit 488ef44

Browse files
macromorgansre
authored andcommitted
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: 54c03bf ("power: supply: Fix refcount leak in rk817_charger_probe") Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/linux-pm/[email protected]/ Signed-off-by: Chris Morgan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 3dc0bab commit 488ef44

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/power/supply/rk817_charger.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,13 @@ static void rk817_charging_monitor(struct work_struct *work)
10451045
queue_delayed_work(system_wq, &charger->work, msecs_to_jiffies(8000));
10461046
}
10471047

1048+
static void rk817_cleanup_node(void *data)
1049+
{
1050+
struct device_node *node = data;
1051+
1052+
of_node_put(node);
1053+
}
1054+
10481055
static int rk817_charger_probe(struct platform_device *pdev)
10491056
{
10501057
struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
@@ -1061,11 +1068,13 @@ static int rk817_charger_probe(struct platform_device *pdev)
10611068
if (!node)
10621069
return -ENODEV;
10631070

1071+
ret = devm_add_action_or_reset(&pdev->dev, rk817_cleanup_node, node);
1072+
if (ret)
1073+
return ret;
1074+
10641075
charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
1065-
if (!charger) {
1066-
of_node_put(node);
1076+
if (!charger)
10671077
return -ENOMEM;
1068-
}
10691078

10701079
charger->rk808 = rk808;
10711080

0 commit comments

Comments
 (0)