Skip to content

Commit 662b52b

Browse files
krzkrafaeljw
authored andcommitted
thermal: of: Fix OF node leak in thermal_of_zone_register()
thermal_of_zone_register() calls of_thermal_zone_find() which will iterate over OF nodes with for_each_available_child_of_node() to find matching thermal zone node. When it finds such, it exits the loop and returns the node. Prematurely ending for_each_available_child_of_node() loops requires dropping OF node reference, thus success of of_thermal_zone_find() means that caller must drop the reference. Fixes: 3fd6d6e ("thermal/of: Rework the thermal device tree initialization") Cc: All applicable <[email protected]> Signed-off-by: Krzysztof Kozlowski <[email protected]> Reviewed-by: Chen-Yu Tsai <[email protected]> Reviewed-by: Daniel Lezcano <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent afc954f commit 662b52b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/thermal/thermal_of.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
491491
trips = thermal_of_trips_init(np, &ntrips);
492492
if (IS_ERR(trips)) {
493493
pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id);
494-
return ERR_CAST(trips);
494+
ret = PTR_ERR(trips);
495+
goto out_of_node_put;
495496
}
496497

497498
ret = thermal_of_monitor_init(np, &delay, &pdelay);
@@ -519,6 +520,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
519520
goto out_kfree_trips;
520521
}
521522

523+
of_node_put(np);
522524
kfree(trips);
523525

524526
ret = thermal_zone_device_enable(tz);
@@ -533,6 +535,8 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node *
533535

534536
out_kfree_trips:
535537
kfree(trips);
538+
out_of_node_put:
539+
of_node_put(np);
536540

537541
return ERR_PTR(ret);
538542
}

0 commit comments

Comments
 (0)