From: Rafael J. Wysocki Date: Wed, 22 Apr 2026 15:39:19 +0000 (+0200) Subject: thermal: core: Simplify unregistration of governors X-Git-Tag: v7.2-rc1~209^2~1^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e12b7be7f051f639b79a8c449c81519c975cd50;p=thirdparty%2Fkernel%2Flinux.git thermal: core: Simplify unregistration of governors Thermal governors are only unregistered in the thermal_init() error path and they actually are only deleted from thermal_governor_list. Put the entire code needed to do that to thermal_unregister_governors() and rearrange thermal_init() to call that function also when thermal_register_governors() returns an error. This allows thermal_unregister_governor() to be dropped and thermal_register_governor() that is only called by thermal_register_governors() can be made static __init, so the headers of these two functions can be dropped from thermal_core.h. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/9615355.CDJkKcVGEf@rafael.j.wysocki --- diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 23d460a5da585..427a76223c6fe 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -116,14 +116,12 @@ static int thermal_set_governor(struct thermal_zone_device *tz, return ret; } -int thermal_register_governor(struct thermal_governor *governor) +static int __init thermal_register_governor(struct thermal_governor *governor) { if (!governor) return -EINVAL; - guard(mutex)(&thermal_governor_lock); - if (__find_governor(governor->name)) return -EBUSY; @@ -138,19 +136,6 @@ int thermal_register_governor(struct thermal_governor *governor) return 0; } -void thermal_unregister_governor(struct thermal_governor *governor) -{ - if (!governor) - return; - - guard(mutex)(&thermal_governor_lock); - - if (!__find_governor(governor->name)) - return; - - list_del(&governor->governor_list); -} - int thermal_zone_device_set_policy(struct thermal_zone_device *tz, char *policy) { @@ -186,40 +171,34 @@ int thermal_build_list_of_policies(char *buf) static void __init thermal_unregister_governors(void) { - struct thermal_governor **governor; + struct thermal_governor *gov, *pos; + + guard(mutex)(&thermal_governor_lock); - for_each_governor_table(governor) - thermal_unregister_governor(*governor); + list_for_each_entry_safe(gov, pos, &thermal_governor_list, governor_list) + list_del(&gov->governor_list); } static int __init thermal_register_governors(void) { - int ret = 0; struct thermal_governor **governor; + guard(mutex)(&thermal_governor_lock); + for_each_governor_table(governor) { + int ret; + ret = thermal_register_governor(*governor); if (ret) { pr_err("Failed to register governor: '%s'", (*governor)->name); - break; + return ret; } - pr_info("Registered thermal governor '%s'", - (*governor)->name); + pr_info("Registered thermal governor '%s'", (*governor)->name); } - if (ret) { - struct thermal_governor **gov; - - for_each_governor_table(gov) { - if (gov == governor) - break; - thermal_unregister_governor(*gov); - } - } - - return ret; + return 0; } static int __thermal_zone_device_set_mode(struct thermal_zone_device *tz, @@ -1858,7 +1837,7 @@ static int __init thermal_init(void) result = thermal_register_governors(); if (result) - goto destroy_workqueue; + goto unregister_governors; result = class_register(&thermal_class); if (result) @@ -1870,7 +1849,6 @@ static int __init thermal_init(void) unregister_governors: thermal_unregister_governors(); -destroy_workqueue: destroy_workqueue(thermal_wq); unregister_netlink: thermal_netlink_exit(); diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index d3acff602f9ce..0acb7d9587ca5 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -258,8 +258,6 @@ struct thermal_instance { #define to_cooling_device(_dev) \ container_of(_dev, struct thermal_cooling_device, device) -int thermal_register_governor(struct thermal_governor *); -void thermal_unregister_governor(struct thermal_governor *); int thermal_zone_device_set_policy(struct thermal_zone_device *, char *); int thermal_build_list_of_policies(char *buf); void __thermal_zone_device_update(struct thermal_zone_device *tz,