[PATCH v1 1/2] thermal: core: Remove dead code from two functions

From: Rafael J. Wysocki

Date: Wed Apr 22 2026 - 11:41:37 EST


From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>

Since thermal_register_governor() is only called by
thermal_register_governors() which runs before clearing
thermal_class_unavailable, thermal_tz_list is guaranteed to be
empty when it runs, so the code walking that list in it is
effectively dead.

The same observation applies to the code walking thermal_tz_list
in thermal_unregister_governor() which is also called only if
thermal_class_unavailable hasn't been cleared.

Remove the dead code from both functions mentioned above and rearrange
thermal_register_governor() to reduce indentation level.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
---
drivers/thermal/thermal_core.c | 61 +++++++----------------------------------
1 file changed, 11 insertions(+), 50 deletions(-)

--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -119,59 +119,28 @@ static int thermal_set_governor(struct t

int thermal_register_governor(struct thermal_governor *governor)
{
- int err;
- const char *name;
- struct thermal_zone_device *pos;

if (!governor)
return -EINVAL;

guard(mutex)(&thermal_governor_lock);

- err = -EBUSY;
- if (!__find_governor(governor->name)) {
- bool match_default;
-
- err = 0;
- list_add(&governor->governor_list, &thermal_governor_list);
- match_default = !strncmp(governor->name,
- DEFAULT_THERMAL_GOVERNOR,
- THERMAL_NAME_LENGTH);
-
- if (!def_governor && match_default)
- def_governor = governor;
- }
-
- guard(mutex)(&thermal_list_lock);
-
- list_for_each_entry(pos, &thermal_tz_list, node) {
- /*
- * only thermal zones with specified tz->tzp->governor_name
- * may run with tz->govenor unset
- */
- if (pos->governor)
- continue;
-
- name = pos->tzp->governor_name;
-
- if (!strncasecmp(name, governor->name, THERMAL_NAME_LENGTH)) {
- int ret;
-
- ret = thermal_set_governor(pos, governor);
- if (ret)
- dev_err(&pos->device,
- "Failed to set governor %s for thermal zone %s: %d\n",
- governor->name, pos->type, ret);
- }
- }
+ if (__find_governor(governor->name))
+ return -EBUSY;

- return err;
+ list_add(&governor->governor_list, &thermal_governor_list);
+
+ if (strncmp(governor->name, DEFAULT_THERMAL_GOVERNOR, THERMAL_NAME_LENGTH))
+ return 0;
+
+ if (!def_governor)
+ def_governor = governor;
+
+ return 0;
}

void thermal_unregister_governor(struct thermal_governor *governor)
{
- struct thermal_zone_device *pos;
-
if (!governor)
return;

@@ -181,14 +150,6 @@ void thermal_unregister_governor(struct
return;

list_del(&governor->governor_list);
-
- guard(mutex)(&thermal_list_lock);
-
- list_for_each_entry(pos, &thermal_tz_list, node) {
- if (!strncasecmp(pos->governor->name, governor->name,
- THERMAL_NAME_LENGTH))
- thermal_set_governor(pos, NULL);
- }
}

int thermal_zone_device_set_policy(struct thermal_zone_device *tz,