Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit a52641b

Browse files
committed
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>
1 parent 893bae9 commit a52641b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

drivers/thermal/thermal_sysfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
139139
if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1)
140140
return -EINVAL;
141141

142-
return sprintf(buf, "%d\n", tz->trips[trip_id].trip.temperature);
142+
return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.temperature));
143143
}
144144

145145
static ssize_t
@@ -163,7 +163,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
163163
trip = &tz->trips[trip_id].trip;
164164

165165
if (hyst != trip->hysteresis) {
166-
trip->hysteresis = hyst;
166+
WRITE_ONCE(trip->hysteresis, hyst);
167167

168168
thermal_zone_trip_updated(tz, trip);
169169
}
@@ -183,7 +183,7 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
183183
if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1)
184184
return -EINVAL;
185185

186-
return sprintf(buf, "%d\n", tz->trips[trip_id].trip.hysteresis);
186+
return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.hysteresis));
187187
}
188188

189189
static ssize_t

drivers/thermal/thermal_trip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void thermal_zone_set_trip_temp(struct thermal_zone_device *tz,
161161
if (trip->temperature == temp)
162162
return;
163163

164-
trip->temperature = temp;
164+
WRITE_ONCE(trip->temperature, temp);
165165
thermal_notify_tz_trip_change(tz, trip);
166166

167167
if (temp == THERMAL_TEMP_INVALID) {

0 commit comments

Comments
 (0)