Skip to content

Commit 6757a7a

Browse files
spandruvadarafaeljw
authored andcommitted
thermal: intel: int340x: Protect trip temperature from concurrent updates
Trip temperatures are read using ACPI methods and stored in the memory during zone initializtion and when the firmware sends a notification for change. This trip temperature is returned when the thermal core calls via callback get_trip_temp(). But it is possible that while updating the memory copy of the trips when the firmware sends a notification for change, thermal core is reading the trip temperature via the callback get_trip_temp(). This may return invalid trip temperature. To address this add a mutex to protect the invalid temperature reads in the callback get_trip_temp() and int340x_thermal_read_trips(). Fixes: 5fbf7f2 ("Thermal/int340x: Add common thermal zone handler") Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Cc: 5.0+ <stable@vger.kernel.org> # 5.0+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 2241ab5 commit 6757a7a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,
4444
int trip, int *temp)
4545
{
4646
struct int34x_thermal_zone *d = zone->devdata;
47-
int i;
47+
int i, ret = 0;
4848

4949
if (d->override_ops && d->override_ops->get_trip_temp)
5050
return d->override_ops->get_trip_temp(zone, trip, temp);
5151

52+
mutex_lock(&d->trip_mutex);
53+
5254
if (trip < d->aux_trip_nr)
5355
*temp = d->aux_trips[trip];
5456
else if (trip == d->crt_trip_id)
@@ -66,10 +68,12 @@ static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,
6668
}
6769
}
6870
if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT)
69-
return -EINVAL;
71+
ret = -EINVAL;
7072
}
7173

72-
return 0;
74+
mutex_unlock(&d->trip_mutex);
75+
76+
return ret;
7377
}
7478

7579
static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone,
@@ -180,6 +184,8 @@ int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone)
180184
int trip_cnt = int34x_zone->aux_trip_nr;
181185
int i;
182186

187+
mutex_lock(&int34x_zone->trip_mutex);
188+
183189
int34x_zone->crt_trip_id = -1;
184190
if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_CRT",
185191
&int34x_zone->crt_temp))
@@ -207,6 +213,8 @@ int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone)
207213
int34x_zone->act_trips[i].valid = true;
208214
}
209215

216+
mutex_unlock(&int34x_zone->trip_mutex);
217+
210218
return trip_cnt;
211219
}
212220
EXPORT_SYMBOL_GPL(int340x_thermal_read_trips);
@@ -230,6 +238,8 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
230238
if (!int34x_thermal_zone)
231239
return ERR_PTR(-ENOMEM);
232240

241+
mutex_init(&int34x_thermal_zone->trip_mutex);
242+
233243
int34x_thermal_zone->adev = adev;
234244
int34x_thermal_zone->override_ops = override_ops;
235245

@@ -281,6 +291,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
281291
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
282292
kfree(int34x_thermal_zone->aux_trips);
283293
err_trip_alloc:
294+
mutex_destroy(&int34x_thermal_zone->trip_mutex);
284295
kfree(int34x_thermal_zone);
285296
return ERR_PTR(ret);
286297
}
@@ -292,6 +303,7 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone
292303
thermal_zone_device_unregister(int34x_thermal_zone->zone);
293304
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
294305
kfree(int34x_thermal_zone->aux_trips);
306+
mutex_destroy(&int34x_thermal_zone->trip_mutex);
295307
kfree(int34x_thermal_zone);
296308
}
297309
EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct int34x_thermal_zone {
3232
struct thermal_zone_device_ops *override_ops;
3333
void *priv_data;
3434
struct acpi_lpat_conversion_table *lpat_table;
35+
struct mutex trip_mutex;
3536
};
3637

3738
struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *,

0 commit comments

Comments
 (0)