thermal: thermal_of: Fix device node reference leak in thermal_of_cm_lookup
Subsystems (2)
PATCH 1/1 thermal: thermal_of: Fix device node reference leak in thermal_of_cm_lookup
In thermal_of_cm_lookup(), of_parse_phandle() returns a device node with its reference count incremented. The caller is responsible for releasing this reference when the node is no longer needed.
Add of_node_put(tr_np) to fix the reference leaks.
Found via static analysis.
--- drivers/thermal/thermal_of.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/thermal/thermal_of.c +4 -1
@@ -284,8 +284,11 @@ 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 ; + } +of_node_put (tr_np);/* The trip has been found, look up the cdev. */ count = of_count_phandle_with_args(child, "cooling-device",
Signature · 1 line
2.39.5 (Apple Git-154)
Rafael J. Wysocki
maintainerQuoted 21 lines · Miaoqian Lin
In
thermal_of_cm_lookup(),of_parse_phandle()returns a device node with its reference count incremented. The caller is responsible for releasing this reference when the node is no longer needed.Add
of_node_put(tr_np)to fix the reference leaks.Found via static analysis.
Fixes 3fd6d6e2b4e8 ("thermal/of: Rework the thermal device tree initialization")Signed-off-by Miaoqian Lin <[email protected]>--- drivers/thermal/thermal_of.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/thermal/thermal_of.c +0
-0
drivers/thermal/thermal_of.c static bool thermal_of_cm_lookup(struct device_node *cm_np, · line 291
Quoted 9 lines
drivers/thermal/thermal_of.c +4
-1@@ -284,8 +284,11 @@ 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 ; + } +of_node_put (tr_np);
This will also work because tr_np is not dereferenced below:
tr_np = of_parse_phandle(child, "trip", 0);
of_node_put(tr_np);
if (tr_np != trip->priv)
continue;but a more general question is whether or not device nodes used for populating thermal zone trip points can be let go.
If not, then this change needs to be combined with another one that will prevent them from going away.
Presumably they need to be reference counted inthermal_of_populate_trip(). Daniel?
Quoted 4 lines
drivers/thermal/thermal_of.c +0
-1/* The trip has been found, look up the cdev. */ count = of_count_phandle_with_args(child, "cooling-device", --