Skip to content

Commit 274d2f8

Browse files
committed
Merge tag 'thermal-6.2-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull thermal control fixes from Rafael Wysocki: "Add locking to the Intel int340x thermal control driver to prevent its thermal zone callbacks from racing with firmware-induced thermal trip point updates (Srinivas Pandruvada, Rafael Wysocki)" * tag 'thermal-6.2-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: thermal: intel: int340x: Add locking to int340x_thermal_get_trip_type() thermal: intel: int340x: Protect trip temperature from concurrent updates
2 parents 0d1e013 + acd7e9e commit 274d2f8

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

Lines changed: 22 additions & 6 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,22 +68,26 @@ 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,
7680
int trip,
7781
enum thermal_trip_type *type)
7882
{
7983
struct int34x_thermal_zone *d = zone->devdata;
80-
int i;
84+
int i, ret = 0;
8185

8286
if (d->override_ops && d->override_ops->get_trip_type)
8387
return d->override_ops->get_trip_type(zone, trip, type);
8488

89+
mutex_lock(&d->trip_mutex);
90+
8591
if (trip < d->aux_trip_nr)
8692
*type = THERMAL_TRIP_PASSIVE;
8793
else if (trip == d->crt_trip_id)
@@ -99,10 +105,12 @@ static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone,
99105
}
100106
}
101107
if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT)
102-
return -EINVAL;
108+
ret = -EINVAL;
103109
}
104110

105-
return 0;
111+
mutex_unlock(&d->trip_mutex);
112+
113+
return ret;
106114
}
107115

108116
static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
@@ -180,6 +188,8 @@ int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone)
180188
int trip_cnt = int34x_zone->aux_trip_nr;
181189
int i;
182190

191+
mutex_lock(&int34x_zone->trip_mutex);
192+
183193
int34x_zone->crt_trip_id = -1;
184194
if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_CRT",
185195
&int34x_zone->crt_temp))
@@ -207,6 +217,8 @@ int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone)
207217
int34x_zone->act_trips[i].valid = true;
208218
}
209219

220+
mutex_unlock(&int34x_zone->trip_mutex);
221+
210222
return trip_cnt;
211223
}
212224
EXPORT_SYMBOL_GPL(int340x_thermal_read_trips);
@@ -230,6 +242,8 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
230242
if (!int34x_thermal_zone)
231243
return ERR_PTR(-ENOMEM);
232244

245+
mutex_init(&int34x_thermal_zone->trip_mutex);
246+
233247
int34x_thermal_zone->adev = adev;
234248
int34x_thermal_zone->override_ops = override_ops;
235249

@@ -281,6 +295,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
281295
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
282296
kfree(int34x_thermal_zone->aux_trips);
283297
err_trip_alloc:
298+
mutex_destroy(&int34x_thermal_zone->trip_mutex);
284299
kfree(int34x_thermal_zone);
285300
return ERR_PTR(ret);
286301
}
@@ -292,6 +307,7 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone
292307
thermal_zone_device_unregister(int34x_thermal_zone->zone);
293308
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
294309
kfree(int34x_thermal_zone->aux_trips);
310+
mutex_destroy(&int34x_thermal_zone->trip_mutex);
295311
kfree(int34x_thermal_zone);
296312
}
297313
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)