Skip to content

Commit 5fa5feb

Browse files
rafaeljwgregkh
authored andcommitted
thermal: trip: Use READ_ONCE() for lockless access to trip properties
[ Upstream commit a52641b ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent db67686 commit 5fa5feb

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/thermal/thermal_sysfs.c

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

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

156156
static ssize_t
@@ -174,7 +174,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
174174
trip = &tz->trips[trip_id].trip;
175175

176176
if (hyst != trip->hysteresis) {
177-
trip->hysteresis = hyst;
177+
WRITE_ONCE(trip->hysteresis, hyst);
178178

179179
thermal_zone_trip_updated(tz, trip);
180180
}
@@ -194,7 +194,7 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
194194
if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1)
195195
return -EINVAL;
196196

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

200200
static ssize_t

drivers/thermal/thermal_trip.c

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

155-
trip->temperature = temp;
155+
WRITE_ONCE(trip->temperature, temp);
156156
thermal_notify_tz_trip_change(tz, trip);
157157

158158
if (temp == THERMAL_TEMP_INVALID) {

0 commit comments

Comments
 (0)