Skip to content

Commit 01e82d4

Browse files
committed
thermal/of: Fix cdev lookup in thermal_of_should_bind()
JIRA: https://issues.redhat.com/browse/RHEL-79821 commit 423de5b Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Date: Fri Feb 21 17:57:11 2025 +0100 thermal/of: Fix cdev lookup in thermal_of_should_bind() Since thermal_of_should_bind() terminates the loop after processing the first child found in cooling-maps, it will never match more than one cdev to a given trip point which is incorrect, as there may be cooling-maps associating one trip point with multiple cooling devices. Address this by letting the loop continue until either all children have been processed or a matching one has been found. To avoid adding conditionals or goto statements, put the loop in question into a separate function and make that function return right away after finding a matching cooling-maps entry. Fixes: 94c6110 ("thermal/of: Use the .should_bind() thermal zone callback") Link: https://lore.kernel.org/linux-pm/20250219-fix-thermal-of-v1-1-de36e7a590c4@chromium.org/ Reported-by: Yu-Che Cheng <giver@chromium.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Yu-Che Cheng <giver@chromium.org> Tested-by: Yu-Che Cheng <giver@chromium.org> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com> Tested-by: Lukasz Luba <lukasz.luba@arm.com> Link: https://patch.msgid.link/2788228.mvXUDI8C0e@rjwysocki.net Signed-off-by: David Arcari <darcari@redhat.com>
1 parent 15f0395 commit 01e82d4

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

drivers/thermal/thermal_of.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,34 @@ static bool thermal_of_get_cooling_spec(struct device_node *map_np, int index,
296296
return true;
297297
}
298298

299+
static bool thermal_of_cm_lookup(struct device_node *cm_np,
300+
const struct thermal_trip *trip,
301+
struct thermal_cooling_device *cdev,
302+
struct cooling_spec *c)
303+
{
304+
for_each_child_of_node_scoped(cm_np, child) {
305+
struct device_node *tr_np;
306+
int count, i;
307+
308+
tr_np = of_parse_phandle(child, "trip", 0);
309+
if (tr_np != trip->priv)
310+
continue;
311+
312+
/* The trip has been found, look up the cdev. */
313+
count = of_count_phandle_with_args(child, "cooling-device",
314+
"#cooling-cells");
315+
if (count <= 0)
316+
pr_err("Add a cooling_device property with at least one device\n");
317+
318+
for (i = 0; i < count; i++) {
319+
if (thermal_of_get_cooling_spec(child, i, cdev, c))
320+
return true;
321+
}
322+
}
323+
324+
return false;
325+
}
326+
299327
static bool thermal_of_should_bind(struct thermal_zone_device *tz,
300328
const struct thermal_trip *trip,
301329
struct thermal_cooling_device *cdev,
@@ -315,27 +343,7 @@ static bool thermal_of_should_bind(struct thermal_zone_device *tz,
315343
goto out;
316344

317345
/* Look up the trip and the cdev in the cooling maps. */
318-
for_each_child_of_node_scoped(cm_np, child) {
319-
struct device_node *tr_np;
320-
int count, i;
321-
322-
tr_np = of_parse_phandle(child, "trip", 0);
323-
if (tr_np != trip->priv)
324-
continue;
325-
326-
/* The trip has been found, look up the cdev. */
327-
count = of_count_phandle_with_args(child, "cooling-device", "#cooling-cells");
328-
if (count <= 0)
329-
pr_err("Add a cooling_device property with at least one device\n");
330-
331-
for (i = 0; i < count; i++) {
332-
result = thermal_of_get_cooling_spec(child, i, cdev, c);
333-
if (result)
334-
break;
335-
}
336-
337-
break;
338-
}
346+
result = thermal_of_cm_lookup(cm_np, trip, cdev, c);
339347

340348
of_node_put(cm_np);
341349
out:

0 commit comments

Comments
 (0)