Patch "thermal: core: Mark thermal zones as initializing to start with" has been added to the 6.11-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    thermal: core: Mark thermal zones as initializing to start with

to the 6.11-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     thermal-core-mark-thermal-zones-as-initializing-to-s.patch
and it can be found in the queue-6.11 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit b55ac87dfed87e842b6217ec3d57a4acc305fbc5
Author: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Date:   Fri Oct 4 21:15:04 2024 +0200

    thermal: core: Mark thermal zones as initializing to start with
    
    [ Upstream commit 7837fa8115e0273d3cfbd3d17b3f7b7291ceac08 ]
    
    After thermal_zone_device_register_with_trips() has called
    device_register() and it has registered the new thermal zone device
    with the driver core, user space may access its sysfs attributes and,
    among other things, it may enable the thermal zone before it is ready.
    
    To address this, introduce a new thermal zone state flag for
    initialization and set it before calling device_register() in
    thermal_zone_device_register_with_trips().  This causes
    __thermal_zone_device_update() to return early until the new flag
    is cleared.
    
    To clear it when the thermal zone is ready, introduce a new
    function called thermal_zone_init_complete() that will also invoke
    __thermal_zone_device_update() after clearing that flag (both under the
    thernal zone lock) and make thermal_zone_device_register_with_trips()
    call the new function instead of checking need_update and calling
    thermal_zone_device_update() when it is set.
    
    After this change, if user space enables the thermal zone prematurely,
    __thermal_zone_device_update() will return early for it until
    thermal_zone_init_complete() is called.  In turn, if the thermal zone
    is not enabled by user space before thermal_zone_init_complete() is
    called, the __thermal_zone_device_update() call in it will return early
    because the thermal zone has not been enabled yet, but that function
    will be invoked again by thermal_zone_device_set_mode() when the thermal
    zone is enabled and it will not return early this time.
    
    The checking of need_update is not necessary any more because the
    __thermal_zone_device_update() calls potentially triggered by cooling
    device binding take place before calling thermal_zone_init_complete(),
    so they all will return early, which means that
    thermal_zone_init_complete() must call __thermal_zone_device_update()
    in case the thermal zone is enabled prematurely by user space.
    
    Fixes: 203d3d4aa482 ("the generic thermal sysfs driver")
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
    Link: https://patch.msgid.link/9360231.CDJkKcVGEf@xxxxxxxxxxxxx
    Reviewed-by: Lukasz Luba <lukasz.luba@xxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 7218bcbaf656e..91512a8cb49d9 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1351,6 +1351,16 @@ int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp)
 }
 EXPORT_SYMBOL_GPL(thermal_zone_get_crit_temp);
 
+static void thermal_zone_init_complete(struct thermal_zone_device *tz)
+{
+	mutex_lock(&tz->lock);
+
+	tz->state &= ~TZ_STATE_FLAG_INIT;
+	__thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
+
+	mutex_unlock(&tz->lock);
+}
+
 /**
  * thermal_zone_device_register_with_trips() - register a new thermal zone device
  * @type:	the thermal zone device type
@@ -1474,6 +1484,8 @@ thermal_zone_device_register_with_trips(const char *type,
 	tz->passive_delay_jiffies = msecs_to_jiffies(passive_delay);
 	tz->recheck_delay_jiffies = THERMAL_RECHECK_DELAY;
 
+	tz->state = TZ_STATE_FLAG_INIT;
+
 	/* sys I/F */
 	/* Add nodes that are always present via .groups */
 	result = thermal_zone_create_device_groups(tz);
@@ -1534,9 +1546,7 @@ thermal_zone_device_register_with_trips(const char *type,
 
 	mutex_unlock(&thermal_list_lock);
 
-	/* Update the new thermal zone and mark it as already updated. */
-	if (atomic_cmpxchg(&tz->need_update, 1, 0))
-		thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
+	thermal_zone_init_complete(tz);
 
 	thermal_notify_tz_create(tz);
 
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 1cf722ba4b71d..1605a930814a5 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -63,6 +63,7 @@ struct thermal_governor {
 
 #define	TZ_STATE_FLAG_SUSPENDED	BIT(0)
 #define	TZ_STATE_FLAG_RESUMING	BIT(1)
+#define	TZ_STATE_FLAG_INIT	BIT(2)
 
 #define TZ_STATE_READY		0
 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux