@@ -382,87 +382,55 @@ static const struct attribute_group *thermal_zone_attribute_groups[] = {
382
382
*/
383
383
static int create_trip_attrs (struct thermal_zone_device * tz )
384
384
{
385
- const struct thermal_trip_desc * td ;
385
+ struct thermal_trip_desc * td ;
386
386
struct attribute * * attrs ;
387
-
388
- /* This function works only for zones with at least one trip */
389
- if (tz -> num_trips <= 0 )
390
- return - EINVAL ;
391
-
392
- tz -> trip_type_attrs = kcalloc (tz -> num_trips , sizeof (* tz -> trip_type_attrs ),
393
- GFP_KERNEL );
394
- if (!tz -> trip_type_attrs )
395
- return - ENOMEM ;
396
-
397
- tz -> trip_temp_attrs = kcalloc (tz -> num_trips , sizeof (* tz -> trip_temp_attrs ),
398
- GFP_KERNEL );
399
- if (!tz -> trip_temp_attrs ) {
400
- kfree (tz -> trip_type_attrs );
401
- return - ENOMEM ;
402
- }
403
-
404
- tz -> trip_hyst_attrs = kcalloc (tz -> num_trips ,
405
- sizeof (* tz -> trip_hyst_attrs ),
406
- GFP_KERNEL );
407
- if (!tz -> trip_hyst_attrs ) {
408
- kfree (tz -> trip_type_attrs );
409
- kfree (tz -> trip_temp_attrs );
410
- return - ENOMEM ;
411
- }
387
+ int i ;
412
388
413
389
attrs = kcalloc (tz -> num_trips * 3 + 1 , sizeof (* attrs ), GFP_KERNEL );
414
- if (!attrs ) {
415
- kfree (tz -> trip_type_attrs );
416
- kfree (tz -> trip_temp_attrs );
417
- kfree (tz -> trip_hyst_attrs );
390
+ if (!attrs )
418
391
return - ENOMEM ;
419
- }
420
392
393
+ i = 0 ;
421
394
for_each_trip_desc (tz , td ) {
422
- int indx = thermal_zone_trip_id ( tz , & td -> trip ) ;
395
+ struct thermal_trip_attrs * trip_attrs = & td -> trip_attrs ;
423
396
424
397
/* create trip type attribute */
425
- snprintf (tz -> trip_type_attrs [ indx ] .name , THERMAL_NAME_LENGTH ,
426
- "trip_point_%d_type" , indx );
398
+ snprintf (trip_attrs -> type .name , THERMAL_NAME_LENGTH ,
399
+ "trip_point_%d_type" , i );
427
400
428
- sysfs_attr_init (& tz -> trip_type_attrs [indx ].attr .attr );
429
- tz -> trip_type_attrs [indx ].attr .attr .name =
430
- tz -> trip_type_attrs [indx ].name ;
431
- tz -> trip_type_attrs [indx ].attr .attr .mode = S_IRUGO ;
432
- tz -> trip_type_attrs [indx ].attr .show = trip_point_type_show ;
433
- attrs [indx ] = & tz -> trip_type_attrs [indx ].attr .attr ;
401
+ sysfs_attr_init (& trip_attrs -> type .attr .attr );
402
+ trip_attrs -> type .attr .attr .name = trip_attrs -> type .name ;
403
+ trip_attrs -> type .attr .attr .mode = S_IRUGO ;
404
+ trip_attrs -> type .attr .show = trip_point_type_show ;
405
+ attrs [i ] = & trip_attrs -> type .attr .attr ;
434
406
435
407
/* create trip temp attribute */
436
- snprintf (tz -> trip_temp_attrs [indx ].name , THERMAL_NAME_LENGTH ,
437
- "trip_point_%d_temp" , indx );
438
-
439
- sysfs_attr_init (& tz -> trip_temp_attrs [indx ].attr .attr );
440
- tz -> trip_temp_attrs [indx ].attr .attr .name =
441
- tz -> trip_temp_attrs [indx ].name ;
442
- tz -> trip_temp_attrs [indx ].attr .attr .mode = S_IRUGO ;
443
- tz -> trip_temp_attrs [indx ].attr .show = trip_point_temp_show ;
408
+ snprintf (trip_attrs -> temp .name , THERMAL_NAME_LENGTH ,
409
+ "trip_point_%d_temp" , i );
410
+
411
+ sysfs_attr_init (& trip_attrs -> temp .attr .attr );
412
+ trip_attrs -> temp .attr .attr .name = trip_attrs -> temp .name ;
413
+ trip_attrs -> temp .attr .attr .mode = S_IRUGO ;
414
+ trip_attrs -> temp .attr .show = trip_point_temp_show ;
444
415
if (td -> trip .flags & THERMAL_TRIP_FLAG_RW_TEMP ) {
445
- tz -> trip_temp_attrs [indx ].attr .attr .mode |= S_IWUSR ;
446
- tz -> trip_temp_attrs [indx ].attr .store =
447
- trip_point_temp_store ;
416
+ trip_attrs -> temp .attr .attr .mode |= S_IWUSR ;
417
+ trip_attrs -> temp .attr .store = trip_point_temp_store ;
448
418
}
449
- attrs [indx + tz -> num_trips ] = & tz -> trip_temp_attrs [ indx ] .attr .attr ;
419
+ attrs [i + tz -> num_trips ] = & trip_attrs -> temp .attr .attr ;
450
420
451
- snprintf (tz -> trip_hyst_attrs [ indx ] .name , THERMAL_NAME_LENGTH ,
452
- "trip_point_%d_hyst" , indx );
421
+ snprintf (trip_attrs -> hyst .name , THERMAL_NAME_LENGTH ,
422
+ "trip_point_%d_hyst" , i );
453
423
454
- sysfs_attr_init (& tz -> trip_hyst_attrs [indx ].attr .attr );
455
- tz -> trip_hyst_attrs [indx ].attr .attr .name =
456
- tz -> trip_hyst_attrs [indx ].name ;
457
- tz -> trip_hyst_attrs [indx ].attr .attr .mode = S_IRUGO ;
458
- tz -> trip_hyst_attrs [indx ].attr .show = trip_point_hyst_show ;
424
+ sysfs_attr_init (& trip_attrs -> hyst .attr .attr );
425
+ trip_attrs -> hyst .attr .attr .name = trip_attrs -> hyst .name ;
426
+ trip_attrs -> hyst .attr .attr .mode = S_IRUGO ;
427
+ trip_attrs -> hyst .attr .show = trip_point_hyst_show ;
459
428
if (td -> trip .flags & THERMAL_TRIP_FLAG_RW_HYST ) {
460
- tz -> trip_hyst_attrs [indx ].attr .attr .mode |= S_IWUSR ;
461
- tz -> trip_hyst_attrs [indx ].attr .store =
462
- trip_point_hyst_store ;
429
+ trip_attrs -> hyst .attr .attr .mode |= S_IWUSR ;
430
+ trip_attrs -> hyst .attr .store = trip_point_hyst_store ;
463
431
}
464
- attrs [indx + tz -> num_trips * 2 ] =
465
- & tz -> trip_hyst_attrs [ indx ]. attr . attr ;
432
+ attrs [i + 2 * tz -> num_trips ] = & trip_attrs -> hyst . attr . attr ;
433
+ i ++ ;
466
434
}
467
435
attrs [tz -> num_trips * 3 ] = NULL ;
468
436
@@ -479,13 +447,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
479
447
*/
480
448
static void destroy_trip_attrs (struct thermal_zone_device * tz )
481
449
{
482
- if (!tz )
483
- return ;
484
-
485
- kfree (tz -> trip_type_attrs );
486
- kfree (tz -> trip_temp_attrs );
487
- kfree (tz -> trip_hyst_attrs );
488
- kfree (tz -> trips_attribute_group .attrs );
450
+ if (tz )
451
+ kfree (tz -> trips_attribute_group .attrs );
489
452
}
490
453
491
454
int thermal_zone_create_device_groups (struct thermal_zone_device * tz )
0 commit comments