thermal/of: fix device node refcount leak in thermal_of_cm_lookup()
Subsystems (2)
PATCH 1/1 thermal/of: fix device node refcount leak in thermal_of_cm_lookup()
of_parse_phandle() returns a device_node pointer with refcount incremented. The caller must use of_node_put() when done.
thermal_of_cm_lookup() acquires a reference to tr_np via of_parse_phandle() but fails to release it on multiple paths:
- When tr_np != trip->priv (continue path)
- When thermal_of_get_cooling_spec() returns true (early return)
- At the end of each loop iteration
Add the missing of_node_put() calls on all paths to prevent the reference count leak.
Fixes 423de5b5bc5b ("thermal/of: Fix cdev lookup in thermal_of_should_bind()")
Signed-off-by Weigang He <[email protected]>
--- drivers/thermal/thermal_of.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/thermal/thermal_of.c +7 -2
@@ -284,8 +284,10 @@ static bool thermal_of_cm_lookup(struct device_node *cm_np,int count, i; tr_np =of_parse_phandle (child,"trip" ,0 ); -if (tr_np != trip->priv) +if (tr_np != trip->priv) { +of_node_put (tr_np);continue ; + }/* The trip has been found, look up the cdev. */ count = of_count_phandle_with_args(child, "cooling-device",
@@ -294,9 +296,12 @@ static bool thermal_of_cm_lookup(struct device_node *cm_np,pr_err ("Add a cooling_device property with at least one device\n" );for (i =0 ; i < count; i++) { -if (thermal_of_get_cooling_spec (child, i, cdev, c)) +if (thermal_of_get_cooling_spec (child, i, cdev, c)) { +of_node_put (tr_np);return true; + } } +of_node_put (tr_np); }return false;
Signature · 1 line
2.34.1