]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
thermal: trip: Use READ_ONCE() for lockless access to trip properties
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 28 May 2024 16:52:13 +0000 (18:52 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 11 Jun 2024 19:06:44 +0000 (21:06 +0200)
When accessing trip temperature and hysteresis without locking, it is
better to use READ_ONCE() to prevent compiler optimizations possibly
affecting the read from being applied.

Of course, for the READ_ONCE() to be effective, WRITE_ONCE() needs to
be used when updating their values.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/thermal/thermal_sysfs.c
drivers/thermal/thermal_trip.c

index e65bbbbf0054a060131eddadf6d22f522b764f46..434b577950be4bfcf78216674ac875636c51e23a 100644 (file)
@@ -139,7 +139,7 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
        if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1)
                return -EINVAL;
 
-       return sprintf(buf, "%d\n", tz->trips[trip_id].trip.temperature);
+       return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.temperature));
 }
 
 static ssize_t
@@ -163,7 +163,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
        trip = &tz->trips[trip_id].trip;
 
        if (hyst != trip->hysteresis) {
-               trip->hysteresis = hyst;
+               WRITE_ONCE(trip->hysteresis, hyst);
 
                thermal_zone_trip_updated(tz, trip);
        }
@@ -183,7 +183,7 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
        if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1)
                return -EINVAL;
 
-       return sprintf(buf, "%d\n", tz->trips[trip_id].trip.hysteresis);
+       return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.hysteresis));
 }
 
 static ssize_t
index 86f408f84f177588d1ac1c86664b0b82faafec6d..2a876d3b93aa6b3ffd47678b8c45d2c7dbb88033 100644 (file)
@@ -161,7 +161,7 @@ void thermal_zone_set_trip_temp(struct thermal_zone_device *tz,
        if (trip->temperature == temp)
                return;
 
-       trip->temperature = temp;
+       WRITE_ONCE(trip->temperature, temp);
        thermal_notify_tz_trip_change(tz, trip);
 
        if (temp == THERMAL_TEMP_INVALID) {