@@ -92,7 +92,14 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
92
92
if (sscanf (attr -> attr .name , "trip_point_%d_type" , & trip ) != 1 )
93
93
return - EINVAL ;
94
94
95
- result = tz -> ops -> get_trip_type (tz , trip , & type );
95
+ mutex_lock (& tz -> lock );
96
+
97
+ if (device_is_registered (dev ))
98
+ result = tz -> ops -> get_trip_type (tz , trip , & type );
99
+ else
100
+ result = - ENODEV ;
101
+
102
+ mutex_unlock (& tz -> lock );
96
103
if (result )
97
104
return result ;
98
105
@@ -128,10 +135,17 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
128
135
if (kstrtoint (buf , 10 , & temperature ))
129
136
return - EINVAL ;
130
137
138
+ mutex_lock (& tz -> lock );
139
+
140
+ if (!device_is_registered (dev )) {
141
+ ret = - ENODEV ;
142
+ goto unlock ;
143
+ }
144
+
131
145
if (tz -> ops -> set_trip_temp ) {
132
146
ret = tz -> ops -> set_trip_temp (tz , trip , temperature );
133
147
if (ret )
134
- return ret ;
148
+ goto unlock ;
135
149
}
136
150
137
151
if (tz -> trips )
@@ -140,16 +154,22 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
140
154
if (tz -> ops -> get_trip_hyst ) {
141
155
ret = tz -> ops -> get_trip_hyst (tz , trip , & hyst );
142
156
if (ret )
143
- return ret ;
157
+ goto unlock ;
144
158
}
145
159
146
160
ret = tz -> ops -> get_trip_type (tz , trip , & type );
147
161
if (ret )
148
- return ret ;
162
+ goto unlock ;
149
163
150
164
thermal_notify_tz_trip_change (tz -> id , trip , type , temperature , hyst );
151
165
152
- thermal_zone_device_update (tz , THERMAL_EVENT_UNSPECIFIED );
166
+ __thermal_zone_device_update (tz , THERMAL_EVENT_UNSPECIFIED );
167
+
168
+ unlock :
169
+ mutex_unlock (& tz -> lock );
170
+
171
+ if (ret )
172
+ return ret ;
153
173
154
174
return count ;
155
175
}
@@ -168,7 +188,14 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
168
188
if (sscanf (attr -> attr .name , "trip_point_%d_temp" , & trip ) != 1 )
169
189
return - EINVAL ;
170
190
171
- ret = tz -> ops -> get_trip_temp (tz , trip , & temperature );
191
+ mutex_lock (& tz -> lock );
192
+
193
+ if (device_is_registered (dev ))
194
+ ret = tz -> ops -> get_trip_temp (tz , trip , & temperature );
195
+ else
196
+ ret = - ENODEV ;
197
+
198
+ mutex_unlock (& tz -> lock );
172
199
173
200
if (ret )
174
201
return ret ;
@@ -193,6 +220,13 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
193
220
if (kstrtoint (buf , 10 , & temperature ))
194
221
return - EINVAL ;
195
222
223
+ mutex_lock (& tz -> lock );
224
+
225
+ if (!device_is_registered (dev )) {
226
+ ret = - ENODEV ;
227
+ goto unlock ;
228
+ }
229
+
196
230
/*
197
231
* We are not doing any check on the 'temperature' value
198
232
* here. The driver implementing 'set_trip_hyst' has to
@@ -201,7 +235,10 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
201
235
ret = tz -> ops -> set_trip_hyst (tz , trip , temperature );
202
236
203
237
if (!ret )
204
- thermal_zone_set_trips (tz );
238
+ __thermal_zone_set_trips (tz );
239
+
240
+ unlock :
241
+ mutex_unlock (& tz -> lock );
205
242
206
243
return ret ? ret : count ;
207
244
}
@@ -220,7 +257,14 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
220
257
if (sscanf (attr -> attr .name , "trip_point_%d_hyst" , & trip ) != 1 )
221
258
return - EINVAL ;
222
259
223
- ret = tz -> ops -> get_trip_hyst (tz , trip , & temperature );
260
+ mutex_lock (& tz -> lock );
261
+
262
+ if (device_is_registered (dev ))
263
+ ret = tz -> ops -> get_trip_hyst (tz , trip , & temperature );
264
+ else
265
+ ret = - ENODEV ;
266
+
267
+ mutex_unlock (& tz -> lock );
224
268
225
269
return ret ? ret : sprintf (buf , "%d\n" , temperature );
226
270
}
@@ -269,16 +313,23 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,
269
313
if (kstrtoint (buf , 10 , & temperature ))
270
314
return - EINVAL ;
271
315
272
- if (!tz -> ops -> set_emul_temp ) {
273
- mutex_lock (& tz -> lock );
316
+ mutex_lock (& tz -> lock );
317
+
318
+ if (!device_is_registered (dev )) {
319
+ ret = - ENODEV ;
320
+ goto unlock ;
321
+ }
322
+
323
+ if (!tz -> ops -> set_emul_temp )
274
324
tz -> emul_temperature = temperature ;
275
- mutex_unlock (& tz -> lock );
276
- } else {
325
+ else
277
326
ret = tz -> ops -> set_emul_temp (tz , temperature );
278
- }
279
327
280
328
if (!ret )
281
- thermal_zone_device_update (tz , THERMAL_EVENT_UNSPECIFIED );
329
+ __thermal_zone_device_update (tz , THERMAL_EVENT_UNSPECIFIED );
330
+
331
+ unlock :
332
+ mutex_unlock (& tz -> lock );
282
333
283
334
return ret ? ret : count ;
284
335
}
0 commit comments