From e34129681754b17c4a2d5a1693f96500e27bbad2 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 11 Mar 2025 08:51:19 +0900 Subject: [PATCH] thermal: core: Represent suspend-related thermal zone flags as bits BugLink: https://bugs.launchpad.net/bugs/2101915 [ Upstream commit 26c9ab8090cda1eb3d42f491cc32d227404897da ] Instead of using two separate fields in struct thermal_zone_device for representing flags related to thermal zone suspend, represent them explicitly as bits in one u8 "state" field. Subsequently, that field will be used for addressing race conditions related to thermal zone initialization and exit. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/7733910.EvYhyI6sBW@rjwysocki.net Reviewed-by: Lukasz Luba Stable-dep-of: 7837fa8115e0 ("thermal: core: Mark thermal zones as initializing to start with") Signed-off-by: Sasha Levin [koichiroden: applied changes for drivers/thermal/thermal_core.h to include/linux/thermal.h due to the missing backport of commit: b1ae92dcfa8e ("thermal: core: Make struct thermal_zone_device definition internal") with adjustments for the absent commit: 9b0a62758665 ("thermal: core: Store zone trips table in struct thermal_zone_device")] Signed-off-by: Koichiro Den Signed-off-by: Stefan Bader --- drivers/thermal/thermal_core.c | 11 +++++------ include/linux/thermal.h | 11 +++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 2b096974ec7d..1e6ec3e0c5b0 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -480,7 +480,7 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz, { struct thermal_trip *trip; - if (tz->suspended || tz->mode != THERMAL_DEVICE_ENABLED) + if (tz->state != TZ_STATE_READY || tz->mode != THERMAL_DEVICE_ENABLED) return; update_temperature(tz); @@ -1573,13 +1573,12 @@ static void thermal_zone_device_resume(struct work_struct *work) mutex_lock(&tz->lock); - tz->suspended = false; + tz->state &= ~(TZ_STATE_FLAG_SUSPENDED | TZ_STATE_FLAG_RESUMING); thermal_zone_device_init(tz); __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); complete(&tz->resume); - tz->resuming = false; mutex_unlock(&tz->lock); } @@ -1588,7 +1587,7 @@ static void thermal_zone_pm_prepare(struct thermal_zone_device *tz) { mutex_lock(&tz->lock); - if (tz->resuming) { + if (tz->state & TZ_STATE_FLAG_RESUMING) { /* * thermal_zone_device_resume() queued up for this zone has not * acquired the lock yet, so release it to let the function run @@ -1601,7 +1600,7 @@ static void thermal_zone_pm_prepare(struct thermal_zone_device *tz) mutex_lock(&tz->lock); } - tz->suspended = true; + tz->state |= TZ_STATE_FLAG_SUSPENDED; mutex_unlock(&tz->lock); } @@ -1613,7 +1612,7 @@ static void thermal_zone_pm_complete(struct thermal_zone_device *tz) cancel_delayed_work(&tz->poll_queue); reinit_completion(&tz->resume); - tz->resuming = true; + tz->state |= TZ_STATE_FLAG_RESUMING; /* * Replace the work function with the resume one, which will restore the diff --git a/include/linux/thermal.h b/include/linux/thermal.h index ed28089b50af..346b9cdd0b5d 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -119,6 +119,11 @@ struct thermal_cooling_device { #endif }; +#define TZ_STATE_FLAG_SUSPENDED BIT(0) +#define TZ_STATE_FLAG_RESUMING BIT(1) + +#define TZ_STATE_READY 0 + /** * struct thermal_zone_device - structure for a thermal zone * @id: unique id number for each thermal zone @@ -160,8 +165,7 @@ struct thermal_cooling_device { * @node: node in thermal_tz_list (in thermal_core.c) * @poll_queue: delayed work for polling * @notify_event: Last notification event - * @suspended: thermal zone suspend indicator - * @resuming: indicates whether or not thermal zone resume is in progress + * @state: current state of the thermal zone */ struct thermal_zone_device { int id; @@ -199,8 +203,7 @@ struct thermal_zone_device { #ifdef CONFIG_THERMAL_DEBUGFS struct thermal_debugfs *debugfs; #endif - bool suspended; - bool resuming; + u8 state; }; /**