@@ -688,53 +688,10 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
688688}
689689
690690static int acpi_thermal_register_thermal_zone (struct acpi_thermal * tz ,
691- unsigned int trip_count )
691+ unsigned int trip_count ,
692+ int passive_delay )
692693{
693- struct acpi_thermal_trip * acpi_trip ;
694- struct thermal_trip * trip ;
695- int passive_delay = 0 ;
696694 int result ;
697- int i ;
698-
699- trip = kcalloc (trip_count , sizeof (* trip ), GFP_KERNEL );
700- if (!trip )
701- return - ENOMEM ;
702-
703- tz -> trip_table = trip ;
704-
705- if (tz -> trips .critical .valid ) {
706- trip -> type = THERMAL_TRIP_CRITICAL ;
707- trip -> temperature = acpi_thermal_temp (tz , tz -> trips .critical .temperature );
708- trip ++ ;
709- }
710-
711- if (tz -> trips .hot .valid ) {
712- trip -> type = THERMAL_TRIP_HOT ;
713- trip -> temperature = acpi_thermal_temp (tz , tz -> trips .hot .temperature );
714- trip ++ ;
715- }
716-
717- acpi_trip = & tz -> trips .passive .trip ;
718- if (acpi_trip -> valid ) {
719- passive_delay = tz -> trips .passive .tsp * 100 ;
720-
721- trip -> type = THERMAL_TRIP_PASSIVE ;
722- trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temperature );
723- trip -> priv = acpi_trip ;
724- trip ++ ;
725- }
726-
727- for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ ) {
728- acpi_trip = & tz -> trips .active [i ].trip ;
729-
730- if (!acpi_trip -> valid )
731- break ;
732-
733- trip -> type = THERMAL_TRIP_ACTIVE ;
734- trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temperature );
735- trip -> priv = acpi_trip ;
736- trip ++ ;
737- }
738695
739696 tz -> thermal_zone = thermal_zone_device_register_with_trips ("acpitz" ,
740697 tz -> trip_table ,
@@ -744,10 +701,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz,
744701 NULL ,
745702 passive_delay ,
746703 tz -> polling_frequency * 100 );
747- if (IS_ERR (tz -> thermal_zone )) {
748- result = PTR_ERR (tz -> thermal_zone );
749- goto free_trip_table ;
750- }
704+ if (IS_ERR (tz -> thermal_zone ))
705+ return PTR_ERR (tz -> thermal_zone );
751706
752707 result = acpi_thermal_zone_sysfs_add (tz );
753708 if (result )
@@ -766,8 +721,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz,
766721 acpi_thermal_zone_sysfs_remove (tz );
767722unregister_tzd :
768723 thermal_zone_device_unregister (tz -> thermal_zone );
769- free_trip_table :
770- kfree (tz -> trip_table );
771724
772725 return result ;
773726}
@@ -886,9 +839,13 @@ static void acpi_thermal_check_fn(struct work_struct *work)
886839
887840static int acpi_thermal_add (struct acpi_device * device )
888841{
842+ struct acpi_thermal_trip * acpi_trip ;
843+ struct thermal_trip * trip ;
889844 struct acpi_thermal * tz ;
890845 unsigned int trip_count ;
846+ int passive_delay = 0 ;
891847 int result ;
848+ int i ;
892849
893850 if (!device )
894851 return - EINVAL ;
@@ -930,9 +887,49 @@ static int acpi_thermal_add(struct acpi_device *device)
930887
931888 acpi_thermal_guess_offset (tz );
932889
933- result = acpi_thermal_register_thermal_zone (tz , trip_count );
890+ trip = kcalloc (trip_count , sizeof (* trip ), GFP_KERNEL );
891+ if (!trip )
892+ return - ENOMEM ;
893+
894+ tz -> trip_table = trip ;
895+
896+ if (tz -> trips .critical .valid ) {
897+ trip -> type = THERMAL_TRIP_CRITICAL ;
898+ trip -> temperature = acpi_thermal_temp (tz , tz -> trips .critical .temperature );
899+ trip ++ ;
900+ }
901+
902+ if (tz -> trips .hot .valid ) {
903+ trip -> type = THERMAL_TRIP_HOT ;
904+ trip -> temperature = acpi_thermal_temp (tz , tz -> trips .hot .temperature );
905+ trip ++ ;
906+ }
907+
908+ acpi_trip = & tz -> trips .passive .trip ;
909+ if (acpi_trip -> valid ) {
910+ passive_delay = tz -> trips .passive .tsp * 100 ;
911+
912+ trip -> type = THERMAL_TRIP_PASSIVE ;
913+ trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temperature );
914+ trip -> priv = acpi_trip ;
915+ trip ++ ;
916+ }
917+
918+ for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ ) {
919+ acpi_trip = & tz -> trips .active [i ].trip ;
920+
921+ if (!acpi_trip -> valid )
922+ break ;
923+
924+ trip -> type = THERMAL_TRIP_ACTIVE ;
925+ trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temperature );
926+ trip -> priv = acpi_trip ;
927+ trip ++ ;
928+ }
929+
930+ result = acpi_thermal_register_thermal_zone (tz , trip_count , passive_delay );
934931 if (result )
935- goto free_memory ;
932+ goto free_trips ;
936933
937934 refcount_set (& tz -> thermal_check_count , 3 );
938935 mutex_init (& tz -> thermal_check_lock );
@@ -951,6 +948,8 @@ static int acpi_thermal_add(struct acpi_device *device)
951948flush_wq :
952949 flush_workqueue (acpi_thermal_pm_queue );
953950 acpi_thermal_unregister_thermal_zone (tz );
951+ free_trips :
952+ kfree (tz -> trip_table );
954953free_memory :
955954 kfree (tz );
956955
0 commit comments