diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2024-05-28 18:52:13 +0200 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2024-06-11 21:06:44 +0200 |
commit | a52641bc6293a24f25956a597e7f32148b0e2bb8 (patch) | |
tree | 4072e64c6d45ca89da601c3904911129ac7a7e2a /drivers/thermal/thermal_sysfs.c | |
parent | thermal: trip: Make thermal_zone_set_trips() use trip thresholds (diff) | |
download | linux-a52641bc6293a24f25956a597e7f32148b0e2bb8.tar.xz linux-a52641bc6293a24f25956a597e7f32148b0e2bb8.zip |
thermal: trip: Use READ_ONCE() for lockless access to trip properties
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>
Diffstat (limited to 'drivers/thermal/thermal_sysfs.c')
-rw-r--r-- | drivers/thermal/thermal_sysfs.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index e65bbbbf0054..434b577950be 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -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 |