thermal/of: Fix reference count leak in thermal_of_cm_lookup
Subsystems (2)
PATCH 1/1 thermal/of: Fix reference count leak in thermal_of_cm_lookup
The function calls of_parse_phandle() to get a
device node, which increments the reference count of the node. However, the function fails to call of_node_put() to decrement the reference. This leads to a reference count leak.
This is found by static analysis and similar to the commit a508e33956b5 ("ipmi:ipmb: Fix refcount leak in ipmi_ipmb_probe")
--- drivers/thermal/thermal_of.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/thermal/thermal_of.c +5 -1
@@ -284,8 +284,12 @@ 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
The function calls
of_parse_phandle()to get a
device node, which increments the reference count of the node. However, the function fails to callof_node_put()to decrement the reference. This leads to a reference count leak.This is found by static analysis and similar to the commit
a508e33956b5("ipmi:ipmb: Fix refcount leak inipmi_ipmb_probe")Fixes 423de5b5bc5b ("thermal/of: Fix cdev lookup in thermal_of_should_bind()")Signed-off-by Miaoqian Lin <[email protected]>--- drivers/thermal/thermal_of.c | 6 +++++- 1 file changed, 5 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 292
Quoted 10 lines
drivers/thermal/thermal_of.c +5
-1@@ -284,8 +284,12 @@ 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);
If it can be done here, it may as well be done before the check above.
drivers/thermal/thermal_of.c static bool thermal_of_cm_lookup(struct device_node *cm_np,
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", --
It would be more prudent to hold this reference throughout the scope though and release it when the scope is left.