@@ -452,26 +452,32 @@ static void acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
452
452
453
453
static int acpi_thermal_get_trip_points (struct acpi_thermal * tz )
454
454
{
455
- bool valid ;
455
+ unsigned int count = 0 ;
456
456
int i ;
457
457
458
458
acpi_thermal_get_critical_trip (tz );
459
459
acpi_thermal_get_hot_trip (tz );
460
460
/* Passive and active trip points (optional). */
461
461
__acpi_thermal_trips_update (tz , ACPI_TRIPS_INIT );
462
462
463
- valid = tz -> trips .critical .valid |
464
- tz -> trips .hot .valid |
465
- tz -> trips .passive .trip .valid ;
463
+ if (tz -> trips .critical .valid )
464
+ count ++ ;
465
+
466
+ if (tz -> trips .hot .valid )
467
+ count ++ ;
466
468
467
- for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ )
468
- valid = valid || tz -> trips .active [i ].trip .valid ;
469
+ if (tz -> trips .passive .trip .valid )
470
+ count ++ ;
471
+
472
+ for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ ) {
473
+ if (tz -> trips .active [i ].trip .valid )
474
+ count ++ ;
475
+ else
476
+ break ;
469
477
470
- if (!valid ) {
471
- pr_warn (FW_BUG "No valid trip found\n" );
472
- return - ENODEV ;
473
478
}
474
- return 0 ;
479
+
480
+ return count ;
475
481
}
476
482
477
483
/* sys I/F for generic thermal sysfs support */
@@ -681,29 +687,15 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
681
687
sysfs_remove_link (& tzdev -> kobj , "device" );
682
688
}
683
689
684
- static int acpi_thermal_register_thermal_zone (struct acpi_thermal * tz )
690
+ static int acpi_thermal_register_thermal_zone (struct acpi_thermal * tz ,
691
+ unsigned int trip_count )
685
692
{
686
693
struct acpi_thermal_trip * acpi_trip ;
687
694
struct thermal_trip * trip ;
688
695
int passive_delay = 0 ;
689
- int trip_count = 0 ;
690
696
int result ;
691
697
int i ;
692
698
693
- if (tz -> trips .critical .valid )
694
- trip_count ++ ;
695
-
696
- if (tz -> trips .hot .valid )
697
- trip_count ++ ;
698
-
699
- if (tz -> trips .passive .trip .valid ) {
700
- trip_count ++ ;
701
- passive_delay = tz -> trips .passive .tsp * 100 ;
702
- }
703
-
704
- for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE && tz -> trips .active [i ].trip .valid ; i ++ )
705
- trip_count ++ ;
706
-
707
699
trip = kcalloc (trip_count , sizeof (* trip ), GFP_KERNEL );
708
700
if (!trip )
709
701
return - ENOMEM ;
@@ -724,6 +716,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
724
716
725
717
acpi_trip = & tz -> trips .passive .trip ;
726
718
if (acpi_trip -> valid ) {
719
+ passive_delay = tz -> trips .passive .tsp * 100 ;
720
+
727
721
trip -> type = THERMAL_TRIP_PASSIVE ;
728
722
trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temperature );
729
723
trip -> priv = acpi_trip ;
@@ -893,6 +887,7 @@ static void acpi_thermal_check_fn(struct work_struct *work)
893
887
static int acpi_thermal_add (struct acpi_device * device )
894
888
{
895
889
struct acpi_thermal * tz ;
890
+ unsigned int trip_count ;
896
891
int result ;
897
892
898
893
if (!device )
@@ -911,9 +906,12 @@ static int acpi_thermal_add(struct acpi_device *device)
911
906
acpi_thermal_aml_dependency_fix (tz );
912
907
913
908
/* Get trip points [_CRT, _PSV, etc.] (required). */
914
- result = acpi_thermal_get_trip_points (tz );
915
- if (result )
909
+ trip_count = acpi_thermal_get_trip_points (tz );
910
+ if (!trip_count ) {
911
+ pr_warn (FW_BUG "No valid trip points!\n" );
912
+ result = - ENODEV ;
916
913
goto free_memory ;
914
+ }
917
915
918
916
/* Get temperature [_TMP] (required). */
919
917
result = acpi_thermal_get_temperature (tz );
@@ -932,7 +930,7 @@ static int acpi_thermal_add(struct acpi_device *device)
932
930
933
931
acpi_thermal_guess_offset (tz );
934
932
935
- result = acpi_thermal_register_thermal_zone (tz );
933
+ result = acpi_thermal_register_thermal_zone (tz , trip_count );
936
934
if (result )
937
935
goto free_memory ;
938
936
0 commit comments