Skip to contentSkip to conversation

thermal: of-thermal: avoid NULL ops dereference when writing trip temperature

PATCH New Akinobu Mita 1 participant 1 message Jul 3, 2019 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: of-thermal: avoid NULL ops dereference when writing trip temperature

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 <[email protected]>
Cc Eduardo Valentin <[email protected]>
Cc Daniel Lezcano <[email protected]>
---
 drivers/thermal/of-thermal.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/thermal/of-thermal.c +8 -5
index dc5093b..c207075 100644
@@ -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;
Signature · 1 line
2.7.4