@@ -229,10 +229,9 @@ int thermal_build_list_of_policies(char *buf)
229
229
mutex_lock (& thermal_governor_lock );
230
230
231
231
list_for_each_entry (pos , & thermal_governor_list , governor_list ) {
232
- count += scnprintf (buf + count , PAGE_SIZE - count , "%s " ,
233
- pos -> name );
232
+ count += sysfs_emit_at (buf , count , "%s " , pos -> name );
234
233
}
235
- count += scnprintf (buf + count , PAGE_SIZE - count , "\n" );
234
+ count += sysfs_emit_at (buf , count , "\n" );
236
235
237
236
mutex_unlock (& thermal_governor_lock );
238
237
@@ -770,14 +769,14 @@ static void thermal_release(struct device *dev)
770
769
} else if (!strncmp (dev_name (dev ), "cooling_device" ,
771
770
sizeof ("cooling_device" ) - 1 )) {
772
771
cdev = to_cooling_device (dev );
772
+ thermal_cooling_device_destroy_sysfs (cdev );
773
+ kfree (cdev -> type );
774
+ ida_free (& thermal_cdev_ida , cdev -> id );
773
775
kfree (cdev );
774
776
}
775
777
}
776
778
777
- static struct class thermal_class = {
778
- .name = "thermal" ,
779
- .dev_release = thermal_release ,
780
- };
779
+ static struct class * thermal_class ;
781
780
782
781
static inline
783
782
void print_bind_err_msg (struct thermal_zone_device * tz ,
@@ -880,6 +879,9 @@ __thermal_cooling_device_register(struct device_node *np,
880
879
!ops -> set_cur_state )
881
880
return ERR_PTR (- EINVAL );
882
881
882
+ if (!thermal_class )
883
+ return ERR_PTR (- ENODEV );
884
+
883
885
cdev = kzalloc (sizeof (* cdev ), GFP_KERNEL );
884
886
if (!cdev )
885
887
return ERR_PTR (- ENOMEM );
@@ -901,27 +903,25 @@ __thermal_cooling_device_register(struct device_node *np,
901
903
cdev -> np = np ;
902
904
cdev -> ops = ops ;
903
905
cdev -> updated = false;
904
- cdev -> device .class = & thermal_class ;
906
+ cdev -> device .class = thermal_class ;
905
907
cdev -> devdata = devdata ;
906
908
907
909
ret = cdev -> ops -> get_max_state (cdev , & cdev -> max_state );
908
- if (ret ) {
909
- kfree (cdev -> type );
910
- goto out_ida_remove ;
911
- }
910
+ if (ret )
911
+ goto out_cdev_type ;
912
912
913
913
thermal_cooling_device_setup_sysfs (cdev );
914
914
915
915
ret = dev_set_name (& cdev -> device , "cooling_device%d" , cdev -> id );
916
- if (ret ) {
917
- kfree (cdev -> type );
918
- thermal_cooling_device_destroy_sysfs (cdev );
919
- goto out_ida_remove ;
920
- }
916
+ if (ret )
917
+ goto out_cooling_dev ;
921
918
922
919
ret = device_register (& cdev -> device );
923
- if (ret )
924
- goto out_kfree_type ;
920
+ if (ret ) {
921
+ /* thermal_release() handles rest of the cleanup */
922
+ put_device (& cdev -> device );
923
+ return ERR_PTR (ret );
924
+ }
925
925
926
926
/* Add 'this' new cdev to the global cdev list */
927
927
mutex_lock (& thermal_list_lock );
@@ -940,13 +940,10 @@ __thermal_cooling_device_register(struct device_node *np,
940
940
941
941
return cdev ;
942
942
943
- out_kfree_type :
943
+ out_cooling_dev :
944
944
thermal_cooling_device_destroy_sysfs (cdev );
945
+ out_cdev_type :
945
946
kfree (cdev -> type );
946
- put_device (& cdev -> device );
947
-
948
- /* thermal_release() takes care of the rest */
949
- cdev = NULL ;
950
947
out_ida_remove :
951
948
ida_free (& thermal_cdev_ida , id );
952
949
out_kfree_cdev :
@@ -1107,11 +1104,7 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
1107
1104
1108
1105
mutex_unlock (& thermal_list_lock );
1109
1106
1110
- ida_free (& thermal_cdev_ida , cdev -> id );
1111
- device_del (& cdev -> device );
1112
- thermal_cooling_device_destroy_sysfs (cdev );
1113
- kfree (cdev -> type );
1114
- put_device (& cdev -> device );
1107
+ device_unregister (& cdev -> device );
1115
1108
}
1116
1109
EXPORT_SYMBOL_GPL (thermal_cooling_device_unregister );
1117
1110
@@ -1162,12 +1155,6 @@ static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms
1162
1155
* delay_jiffies = round_jiffies (* delay_jiffies );
1163
1156
}
1164
1157
1165
- int thermal_zone_get_num_trips (struct thermal_zone_device * tz )
1166
- {
1167
- return tz -> num_trips ;
1168
- }
1169
- EXPORT_SYMBOL_GPL (thermal_zone_get_num_trips );
1170
-
1171
1158
int thermal_zone_get_crit_temp (struct thermal_zone_device * tz , int * temp )
1172
1159
{
1173
1160
int i , ret = - EINVAL ;
@@ -1194,87 +1181,6 @@ int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp)
1194
1181
}
1195
1182
EXPORT_SYMBOL_GPL (thermal_zone_get_crit_temp );
1196
1183
1197
- int __thermal_zone_get_trip (struct thermal_zone_device * tz , int trip_id ,
1198
- struct thermal_trip * trip )
1199
- {
1200
- int ret ;
1201
-
1202
- if (!tz || trip_id < 0 || trip_id >= tz -> num_trips || !trip )
1203
- return - EINVAL ;
1204
-
1205
- if (tz -> trips ) {
1206
- * trip = tz -> trips [trip_id ];
1207
- return 0 ;
1208
- }
1209
-
1210
- if (tz -> ops -> get_trip_hyst ) {
1211
- ret = tz -> ops -> get_trip_hyst (tz , trip_id , & trip -> hysteresis );
1212
- if (ret )
1213
- return ret ;
1214
- } else {
1215
- trip -> hysteresis = 0 ;
1216
- }
1217
-
1218
- ret = tz -> ops -> get_trip_temp (tz , trip_id , & trip -> temperature );
1219
- if (ret )
1220
- return ret ;
1221
-
1222
- return tz -> ops -> get_trip_type (tz , trip_id , & trip -> type );
1223
- }
1224
- EXPORT_SYMBOL_GPL (__thermal_zone_get_trip );
1225
-
1226
- int thermal_zone_get_trip (struct thermal_zone_device * tz , int trip_id ,
1227
- struct thermal_trip * trip )
1228
- {
1229
- int ret ;
1230
-
1231
- mutex_lock (& tz -> lock );
1232
- ret = __thermal_zone_get_trip (tz , trip_id , trip );
1233
- mutex_unlock (& tz -> lock );
1234
-
1235
- return ret ;
1236
- }
1237
- EXPORT_SYMBOL_GPL (thermal_zone_get_trip );
1238
-
1239
- int thermal_zone_set_trip (struct thermal_zone_device * tz , int trip_id ,
1240
- const struct thermal_trip * trip )
1241
- {
1242
- struct thermal_trip t ;
1243
- int ret ;
1244
-
1245
- if (!tz -> ops -> set_trip_temp && !tz -> ops -> set_trip_hyst && !tz -> trips )
1246
- return - EINVAL ;
1247
-
1248
- ret = __thermal_zone_get_trip (tz , trip_id , & t );
1249
- if (ret )
1250
- return ret ;
1251
-
1252
- if (t .type != trip -> type )
1253
- return - EINVAL ;
1254
-
1255
- if (t .temperature != trip -> temperature && tz -> ops -> set_trip_temp ) {
1256
- ret = tz -> ops -> set_trip_temp (tz , trip_id , trip -> temperature );
1257
- if (ret )
1258
- return ret ;
1259
- }
1260
-
1261
- if (t .hysteresis != trip -> hysteresis && tz -> ops -> set_trip_hyst ) {
1262
- ret = tz -> ops -> set_trip_hyst (tz , trip_id , trip -> hysteresis );
1263
- if (ret )
1264
- return ret ;
1265
- }
1266
-
1267
- if (tz -> trips && (t .temperature != trip -> temperature || t .hysteresis != trip -> hysteresis ))
1268
- tz -> trips [trip_id ] = * trip ;
1269
-
1270
- thermal_notify_tz_trip_change (tz -> id , trip_id , trip -> type ,
1271
- trip -> temperature , trip -> hysteresis );
1272
-
1273
- __thermal_zone_device_update (tz , THERMAL_TRIP_CHANGED );
1274
-
1275
- return 0 ;
1276
- }
1277
-
1278
1184
/**
1279
1185
* thermal_zone_device_register_with_trips() - register a new thermal zone device
1280
1186
* @type: the thermal zone device type
@@ -1349,6 +1255,9 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
1349
1255
if (num_trips > 0 && (!ops -> get_trip_type || !ops -> get_trip_temp ) && !trips )
1350
1256
return ERR_PTR (- EINVAL );
1351
1257
1258
+ if (!thermal_class )
1259
+ return ERR_PTR (- ENODEV );
1260
+
1352
1261
tz = kzalloc (sizeof (* tz ), GFP_KERNEL );
1353
1262
if (!tz )
1354
1263
return ERR_PTR (- ENOMEM );
@@ -1370,7 +1279,7 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
1370
1279
1371
1280
tz -> ops = ops ;
1372
1281
tz -> tzp = tzp ;
1373
- tz -> device .class = & thermal_class ;
1282
+ tz -> device .class = thermal_class ;
1374
1283
tz -> devdata = devdata ;
1375
1284
tz -> trips = trips ;
1376
1285
tz -> num_trips = num_trips ;
@@ -1613,11 +1522,23 @@ static int __init thermal_init(void)
1613
1522
1614
1523
result = thermal_register_governors ();
1615
1524
if (result )
1616
- goto error ;
1525
+ goto unregister_netlink ;
1617
1526
1618
- result = class_register (& thermal_class );
1619
- if (result )
1527
+ thermal_class = kzalloc (sizeof (* thermal_class ), GFP_KERNEL );
1528
+ if (!thermal_class ) {
1529
+ result = - ENOMEM ;
1620
1530
goto unregister_governors ;
1531
+ }
1532
+
1533
+ thermal_class -> name = "thermal" ;
1534
+ thermal_class -> dev_release = thermal_release ;
1535
+
1536
+ result = class_register (thermal_class );
1537
+ if (result ) {
1538
+ kfree (thermal_class );
1539
+ thermal_class = NULL ;
1540
+ goto unregister_governors ;
1541
+ }
1621
1542
1622
1543
result = register_pm_notifier (& thermal_pm_nb );
1623
1544
if (result )
@@ -1628,9 +1549,9 @@ static int __init thermal_init(void)
1628
1549
1629
1550
unregister_governors :
1630
1551
thermal_unregister_governors ();
1552
+ unregister_netlink :
1553
+ thermal_netlink_exit ();
1631
1554
error :
1632
- ida_destroy (& thermal_tz_ida );
1633
- ida_destroy (& thermal_cdev_ida );
1634
1555
mutex_destroy (& thermal_list_lock );
1635
1556
mutex_destroy (& thermal_governor_lock );
1636
1557
return result ;
0 commit comments