47
47
48
48
#define ACPI_THERMAL_TRIP_PASSIVE (-1)
49
49
50
+ #define ACPI_THERMAL_MAX_NR_TRIPS (ACPI_THERMAL_MAX_ACTIVE + 3)
51
+
50
52
/*
51
53
* This exception is thrown out in two cases:
52
54
* 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
@@ -112,7 +114,6 @@ struct acpi_thermal {
112
114
unsigned long polling_frequency ;
113
115
volatile u8 zombie ;
114
116
struct acpi_thermal_trips trips ;
115
- struct thermal_trip * trip_table ;
116
117
struct thermal_zone_device * thermal_zone ;
117
118
int kelvin_offset ; /* in millidegrees */
118
119
struct work_struct thermal_check_work ;
@@ -451,26 +452,19 @@ static bool acpi_thermal_init_trip(struct acpi_thermal *tz, int index)
451
452
return false;
452
453
}
453
454
454
- static int acpi_thermal_get_trip_points (struct acpi_thermal * tz )
455
+ static void acpi_thermal_get_trip_points (struct acpi_thermal * tz )
455
456
{
456
- unsigned int count = 0 ;
457
457
int i ;
458
458
459
- if (acpi_thermal_init_trip (tz , ACPI_THERMAL_TRIP_PASSIVE ))
460
- count ++ ;
459
+ acpi_thermal_init_trip (tz , ACPI_THERMAL_TRIP_PASSIVE );
461
460
462
461
for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ ) {
463
- if (acpi_thermal_init_trip (tz , i ))
464
- count ++ ;
465
- else
462
+ if (!acpi_thermal_init_trip (tz , i ))
466
463
break ;
467
-
468
464
}
469
465
470
466
while (++ i < ACPI_THERMAL_MAX_ACTIVE )
471
467
tz -> trips .active [i ].trip .temp_dk = THERMAL_TEMP_INVALID ;
472
-
473
- return count ;
474
468
}
475
469
476
470
/* sys I/F for generic thermal sysfs support */
@@ -662,13 +656,14 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
662
656
}
663
657
664
658
static int acpi_thermal_register_thermal_zone (struct acpi_thermal * tz ,
659
+ const struct thermal_trip * trip_table ,
665
660
unsigned int trip_count ,
666
661
int passive_delay )
667
662
{
668
663
int result ;
669
664
670
665
tz -> thermal_zone = thermal_zone_device_register_with_trips ("acpitz" ,
671
- tz -> trip_table ,
666
+ trip_table ,
672
667
trip_count ,
673
668
0 , tz ,
674
669
& acpi_thermal_zone_ops ,
@@ -823,10 +818,10 @@ static void acpi_thermal_free_thermal_zone(struct acpi_thermal *tz)
823
818
824
819
static int acpi_thermal_add (struct acpi_device * device )
825
820
{
821
+ struct thermal_trip trip_table [ACPI_THERMAL_MAX_NR_TRIPS ] = { 0 };
826
822
struct acpi_thermal_trip * acpi_trip ;
827
823
struct thermal_trip * trip ;
828
824
struct acpi_thermal * tz ;
829
- unsigned int trip_count ;
830
825
int crit_temp , hot_temp ;
831
826
int passive_delay = 0 ;
832
827
int result ;
@@ -848,21 +843,10 @@ static int acpi_thermal_add(struct acpi_device *device)
848
843
acpi_thermal_aml_dependency_fix (tz );
849
844
850
845
/* Get trip points [_CRT, _PSV, etc.] (required). */
851
- trip_count = acpi_thermal_get_trip_points (tz );
846
+ acpi_thermal_get_trip_points (tz );
852
847
853
848
crit_temp = acpi_thermal_get_critical_trip (tz );
854
- if (crit_temp != THERMAL_TEMP_INVALID )
855
- trip_count ++ ;
856
-
857
849
hot_temp = acpi_thermal_get_hot_trip (tz );
858
- if (hot_temp != THERMAL_TEMP_INVALID )
859
- trip_count ++ ;
860
-
861
- if (!trip_count ) {
862
- pr_warn (FW_BUG "No valid trip points!\n" );
863
- result = - ENODEV ;
864
- goto free_memory ;
865
- }
866
850
867
851
/* Get temperature [_TMP] (required). */
868
852
result = acpi_thermal_get_temperature (tz );
@@ -881,13 +865,7 @@ static int acpi_thermal_add(struct acpi_device *device)
881
865
882
866
acpi_thermal_guess_offset (tz , crit_temp );
883
867
884
- trip = kcalloc (trip_count , sizeof (* trip ), GFP_KERNEL );
885
- if (!trip ) {
886
- result = - ENOMEM ;
887
- goto free_memory ;
888
- }
889
-
890
- tz -> trip_table = trip ;
868
+ trip = trip_table ;
891
869
892
870
if (crit_temp != THERMAL_TEMP_INVALID ) {
893
871
trip -> type = THERMAL_TRIP_CRITICAL ;
@@ -923,9 +901,17 @@ static int acpi_thermal_add(struct acpi_device *device)
923
901
trip ++ ;
924
902
}
925
903
926
- result = acpi_thermal_register_thermal_zone (tz , trip_count , passive_delay );
904
+ if (trip == trip_table ) {
905
+ pr_warn (FW_BUG "No valid trip points!\n" );
906
+ result = - ENODEV ;
907
+ goto free_memory ;
908
+ }
909
+
910
+ result = acpi_thermal_register_thermal_zone (tz , trip_table ,
911
+ trip - trip_table ,
912
+ passive_delay );
927
913
if (result )
928
- goto free_trips ;
914
+ goto free_memory ;
929
915
930
916
refcount_set (& tz -> thermal_check_count , 3 );
931
917
mutex_init (& tz -> thermal_check_lock );
@@ -944,8 +930,6 @@ static int acpi_thermal_add(struct acpi_device *device)
944
930
flush_wq :
945
931
flush_workqueue (acpi_thermal_pm_queue );
946
932
acpi_thermal_unregister_thermal_zone (tz );
947
- free_trips :
948
- kfree (tz -> trip_table );
949
933
free_memory :
950
934
acpi_thermal_free_thermal_zone (tz );
951
935
@@ -966,7 +950,6 @@ static void acpi_thermal_remove(struct acpi_device *device)
966
950
967
951
flush_workqueue (acpi_thermal_pm_queue );
968
952
acpi_thermal_unregister_thermal_zone (tz );
969
- kfree (tz -> trip_table );
970
953
acpi_thermal_free_thermal_zone (tz );
971
954
}
972
955
0 commit comments