]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
thermal: core: Represent suspend-related thermal zone flags as bits
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 4 Oct 2024 19:11:53 +0000 (21:11 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2024 12:52:50 +0000 (13:52 +0100)
[ 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 <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/7733910.EvYhyI6sBW@rjwysocki.net
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Stable-dep-of: 7837fa8115e0 ("thermal: core: Mark thermal zones as initializing to start with")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/thermal/thermal_core.c
drivers/thermal/thermal_core.h

index 728eca88a56afc0b8f541330345b936047ce1574..7218bcbaf656ec6b6f65134d2c54651cbb621081 100644 (file)
@@ -553,7 +553,7 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
        LIST_HEAD(way_up_list);
        int temp, ret;
 
-       if (tz->suspended || tz->mode != THERMAL_DEVICE_ENABLED)
+       if (tz->state != TZ_STATE_READY || tz->mode != THERMAL_DEVICE_ENABLED)
                return;
 
        ret = __thermal_zone_get_temp(tz, &temp);
@@ -1693,7 +1693,7 @@ 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_debug_tz_resume(tz);
        thermal_zone_device_init(tz);
@@ -1701,7 +1701,6 @@ static void thermal_zone_device_resume(struct work_struct *work)
        __thermal_zone_device_update(tz, THERMAL_TZ_RESUME);
 
        complete(&tz->resume);
-       tz->resuming = false;
 
        mutex_unlock(&tz->lock);
 }
@@ -1710,7 +1709,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
@@ -1723,7 +1722,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);
 }
@@ -1735,7 +1734,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
index e93a7641736ed8dc850b6c4a9535fa3df6266cc6..1cf722ba4b71d40e3fa12c72b89a97cf35486908 100644 (file)
@@ -61,6 +61,11 @@ struct thermal_governor {
        struct list_head        governor_list;
 };
 
+#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
@@ -100,8 +105,7 @@ struct thermal_governor {
  * @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
  * @trips:     array of struct thermal_trip objects
  */
 struct thermal_zone_device {
@@ -134,8 +138,7 @@ struct thermal_zone_device {
        struct list_head node;
        struct delayed_work poll_queue;
        enum thermal_notify_event notify_event;
-       bool suspended;
-       bool resuming;
+       u8 state;
 #ifdef CONFIG_THERMAL_DEBUGFS
        struct thermal_debugfs *debugfs;
 #endif