@@ -452,26 +452,32 @@ static void acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
452452
453453static int acpi_thermal_get_trip_points (struct acpi_thermal * tz )
454454{
455- bool valid ;
455+ unsigned int count = 0 ;
456456 int i ;
457457
458458 acpi_thermal_get_critical_trip (tz );
459459 acpi_thermal_get_hot_trip (tz );
460460 /* Passive and active trip points (optional). */
461461 __acpi_thermal_trips_update (tz , ACPI_TRIPS_INIT );
462462
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 ++ ;
466468
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 ;
469477
470- if (!valid ) {
471- pr_warn (FW_BUG "No valid trip found\n" );
472- return - ENODEV ;
473478 }
474- return 0 ;
479+
480+ return count ;
475481}
476482
477483/* sys I/F for generic thermal sysfs support */
@@ -681,29 +687,15 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
681687 sysfs_remove_link (& tzdev -> kobj , "device" );
682688}
683689
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 )
685692{
686693 struct acpi_thermal_trip * acpi_trip ;
687694 struct thermal_trip * trip ;
688695 int passive_delay = 0 ;
689- int trip_count = 0 ;
690696 int result ;
691697 int i ;
692698
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-
707699 trip = kcalloc (trip_count , sizeof (* trip ), GFP_KERNEL );
708700 if (!trip )
709701 return - ENOMEM ;
@@ -724,6 +716,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
724716
725717 acpi_trip = & tz -> trips .passive .trip ;
726718 if (acpi_trip -> valid ) {
719+ passive_delay = tz -> trips .passive .tsp * 100 ;
720+
727721 trip -> type = THERMAL_TRIP_PASSIVE ;
728722 trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temperature );
729723 trip -> priv = acpi_trip ;
@@ -893,6 +887,7 @@ static void acpi_thermal_check_fn(struct work_struct *work)
893887static int acpi_thermal_add (struct acpi_device * device )
894888{
895889 struct acpi_thermal * tz ;
890+ unsigned int trip_count ;
896891 int result ;
897892
898893 if (!device )
@@ -911,9 +906,12 @@ static int acpi_thermal_add(struct acpi_device *device)
911906 acpi_thermal_aml_dependency_fix (tz );
912907
913908 /* 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 ;
916913 goto free_memory ;
914+ }
917915
918916 /* Get temperature [_TMP] (required). */
919917 result = acpi_thermal_get_temperature (tz );
@@ -932,7 +930,7 @@ static int acpi_thermal_add(struct acpi_device *device)
932930
933931 acpi_thermal_guess_offset (tz );
934932
935- result = acpi_thermal_register_thermal_zone (tz );
933+ result = acpi_thermal_register_thermal_zone (tz , trip_count );
936934 if (result )
937935 goto free_memory ;
938936
0 commit comments