@@ -44,11 +44,13 @@ static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,
44
44
int trip , int * temp )
45
45
{
46
46
struct int34x_thermal_zone * d = zone -> devdata ;
47
- int i ;
47
+ int i , ret = 0 ;
48
48
49
49
if (d -> override_ops && d -> override_ops -> get_trip_temp )
50
50
return d -> override_ops -> get_trip_temp (zone , trip , temp );
51
51
52
+ mutex_lock (& d -> trip_mutex );
53
+
52
54
if (trip < d -> aux_trip_nr )
53
55
* temp = d -> aux_trips [trip ];
54
56
else if (trip == d -> crt_trip_id )
@@ -66,22 +68,26 @@ static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,
66
68
}
67
69
}
68
70
if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT )
69
- return - EINVAL ;
71
+ ret = - EINVAL ;
70
72
}
71
73
72
- return 0 ;
74
+ mutex_unlock (& d -> trip_mutex );
75
+
76
+ return ret ;
73
77
}
74
78
75
79
static int int340x_thermal_get_trip_type (struct thermal_zone_device * zone ,
76
80
int trip ,
77
81
enum thermal_trip_type * type )
78
82
{
79
83
struct int34x_thermal_zone * d = zone -> devdata ;
80
- int i ;
84
+ int i , ret = 0 ;
81
85
82
86
if (d -> override_ops && d -> override_ops -> get_trip_type )
83
87
return d -> override_ops -> get_trip_type (zone , trip , type );
84
88
89
+ mutex_lock (& d -> trip_mutex );
90
+
85
91
if (trip < d -> aux_trip_nr )
86
92
* type = THERMAL_TRIP_PASSIVE ;
87
93
else if (trip == d -> crt_trip_id )
@@ -99,10 +105,12 @@ static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone,
99
105
}
100
106
}
101
107
if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT )
102
- return - EINVAL ;
108
+ ret = - EINVAL ;
103
109
}
104
110
105
- return 0 ;
111
+ mutex_unlock (& d -> trip_mutex );
112
+
113
+ return ret ;
106
114
}
107
115
108
116
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)
180
188
int trip_cnt = int34x_zone -> aux_trip_nr ;
181
189
int i ;
182
190
191
+ mutex_lock (& int34x_zone -> trip_mutex );
192
+
183
193
int34x_zone -> crt_trip_id = -1 ;
184
194
if (!int340x_thermal_get_trip_config (int34x_zone -> adev -> handle , "_CRT" ,
185
195
& int34x_zone -> crt_temp ))
@@ -207,6 +217,8 @@ int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone)
207
217
int34x_zone -> act_trips [i ].valid = true;
208
218
}
209
219
220
+ mutex_unlock (& int34x_zone -> trip_mutex );
221
+
210
222
return trip_cnt ;
211
223
}
212
224
EXPORT_SYMBOL_GPL (int340x_thermal_read_trips );
@@ -230,6 +242,8 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
230
242
if (!int34x_thermal_zone )
231
243
return ERR_PTR (- ENOMEM );
232
244
245
+ mutex_init (& int34x_thermal_zone -> trip_mutex );
246
+
233
247
int34x_thermal_zone -> adev = adev ;
234
248
int34x_thermal_zone -> override_ops = override_ops ;
235
249
@@ -281,6 +295,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
281
295
acpi_lpat_free_conversion_table (int34x_thermal_zone -> lpat_table );
282
296
kfree (int34x_thermal_zone -> aux_trips );
283
297
err_trip_alloc :
298
+ mutex_destroy (& int34x_thermal_zone -> trip_mutex );
284
299
kfree (int34x_thermal_zone );
285
300
return ERR_PTR (ret );
286
301
}
@@ -292,6 +307,7 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone
292
307
thermal_zone_device_unregister (int34x_thermal_zone -> zone );
293
308
acpi_lpat_free_conversion_table (int34x_thermal_zone -> lpat_table );
294
309
kfree (int34x_thermal_zone -> aux_trips );
310
+ mutex_destroy (& int34x_thermal_zone -> trip_mutex );
295
311
kfree (int34x_thermal_zone );
296
312
}
297
313
EXPORT_SYMBOL_GPL (int340x_thermal_zone_remove );
0 commit comments