@@ -332,17 +332,20 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip,
int temp)
{
struct __thermal_zone *data = tz->devdata;
+ int ret = 0;
if (trip >= data->ntrips || trip < 0)
return -EDOM;
- if (data->ops->set_trip_temp) {
- int ret;
+ mutex_lock(&tz->lock);
+ if (data->ops && data->ops->set_trip_temp)
ret = data->ops->set_trip_temp(data->sensor_data, trip, temp);
- if (ret)
- return ret;
- }
+
+ mutex_unlock(&tz->lock);
+
+ if (ret)
+ return ret;
/* thermal framework should take care of data->mask & (1 << trip) */
data->trips[trip].temperature = temp;
While no sensor is registered to a DT thermal zone, __thermal_zone->ops (struct thermal_zone_of_device_ops) is set to NULL. This causes a NULL pointer dereference when writing trip point temperature (i.e. trip_point_[0-*]_temp). Fix it by checking if ops is NULL under thermal_zone_device's lock that protects against concurrent access by thermal_zone_of_sensor_register() and thermal_zone_of_sensor_unregister(). Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <edubezval@gmail.com> Cc: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> --- drivers/thermal/of-thermal.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)