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 ;
@@ -167,11 +168,17 @@ static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
167
168
168
169
static int acpi_thermal_temp (struct acpi_thermal * tz , int temp_deci_k )
169
170
{
171
+ int temp ;
172
+
170
173
if (temp_deci_k == THERMAL_TEMP_INVALID )
171
174
return THERMAL_TEMP_INVALID ;
172
175
173
- return deci_kelvin_to_millicelsius_with_offset (temp_deci_k ,
176
+ temp = deci_kelvin_to_millicelsius_with_offset (temp_deci_k ,
174
177
tz -> kelvin_offset );
178
+ if (temp <= 0 )
179
+ return THERMAL_TEMP_INVALID ;
180
+
181
+ return temp ;
175
182
}
176
183
177
184
static bool acpi_thermal_trip_valid (struct acpi_thermal_trip * acpi_trip )
@@ -451,26 +458,19 @@ static bool acpi_thermal_init_trip(struct acpi_thermal *tz, int index)
451
458
return false;
452
459
}
453
460
454
- static int acpi_thermal_get_trip_points (struct acpi_thermal * tz )
461
+ static void acpi_thermal_get_trip_points (struct acpi_thermal * tz )
455
462
{
456
- unsigned int count = 0 ;
457
463
int i ;
458
464
459
- if (acpi_thermal_init_trip (tz , ACPI_THERMAL_TRIP_PASSIVE ))
460
- count ++ ;
465
+ acpi_thermal_init_trip (tz , ACPI_THERMAL_TRIP_PASSIVE );
461
466
462
467
for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ ) {
463
- if (acpi_thermal_init_trip (tz , i ))
464
- count ++ ;
465
- else
468
+ if (!acpi_thermal_init_trip (tz , i ))
466
469
break ;
467
-
468
470
}
469
471
470
472
while (++ i < ACPI_THERMAL_MAX_ACTIVE )
471
473
tz -> trips .active [i ].trip .temp_dk = THERMAL_TEMP_INVALID ;
472
-
473
- return count ;
474
474
}
475
475
476
476
/* sys I/F for generic thermal sysfs support */
@@ -558,77 +558,31 @@ static void acpi_thermal_zone_device_critical(struct thermal_zone_device *therma
558
558
thermal_zone_device_critical (thermal );
559
559
}
560
560
561
- struct acpi_thermal_bind_data {
562
- struct thermal_zone_device * thermal ;
563
- struct thermal_cooling_device * cdev ;
564
- bool bind ;
565
- };
566
-
567
- static int bind_unbind_cdev_cb (struct thermal_trip * trip , void * arg )
561
+ static bool acpi_thermal_should_bind_cdev (struct thermal_zone_device * thermal ,
562
+ const struct thermal_trip * trip ,
563
+ struct thermal_cooling_device * cdev ,
564
+ struct cooling_spec * c )
568
565
{
569
566
struct acpi_thermal_trip * acpi_trip = trip -> priv ;
570
- struct acpi_thermal_bind_data * bd = arg ;
571
- struct thermal_zone_device * thermal = bd -> thermal ;
572
- struct thermal_cooling_device * cdev = bd -> cdev ;
573
567
struct acpi_device * cdev_adev = cdev -> devdata ;
574
568
int i ;
575
569
576
570
/* Skip critical and hot trips. */
577
571
if (!acpi_trip )
578
- return 0 ;
572
+ return false ;
579
573
580
574
for (i = 0 ; i < acpi_trip -> devices .count ; i ++ ) {
581
575
acpi_handle handle = acpi_trip -> devices .handles [i ];
582
- struct acpi_device * adev = acpi_fetch_acpi_dev (handle );
583
-
584
- if (adev != cdev_adev )
585
- continue ;
586
-
587
- if (bd -> bind ) {
588
- int ret ;
589
-
590
- ret = thermal_bind_cdev_to_trip (thermal , trip , cdev ,
591
- THERMAL_NO_LIMIT ,
592
- THERMAL_NO_LIMIT ,
593
- THERMAL_WEIGHT_DEFAULT );
594
- if (ret )
595
- return ret ;
596
- } else {
597
- thermal_unbind_cdev_from_trip (thermal , trip , cdev );
598
- }
599
- }
600
-
601
- return 0 ;
602
- }
603
-
604
- static int acpi_thermal_bind_unbind_cdev (struct thermal_zone_device * thermal ,
605
- struct thermal_cooling_device * cdev ,
606
- bool bind )
607
- {
608
- struct acpi_thermal_bind_data bd = {
609
- .thermal = thermal , .cdev = cdev , .bind = bind
610
- };
611
-
612
- return for_each_thermal_trip (thermal , bind_unbind_cdev_cb , & bd );
613
- }
614
576
615
- static int
616
- acpi_thermal_bind_cooling_device (struct thermal_zone_device * thermal ,
617
- struct thermal_cooling_device * cdev )
618
- {
619
- return acpi_thermal_bind_unbind_cdev (thermal , cdev , true);
620
- }
577
+ if (acpi_fetch_acpi_dev (handle ) == cdev_adev )
578
+ return true;
579
+ }
621
580
622
- static int
623
- acpi_thermal_unbind_cooling_device (struct thermal_zone_device * thermal ,
624
- struct thermal_cooling_device * cdev )
625
- {
626
- return acpi_thermal_bind_unbind_cdev (thermal , cdev , false);
581
+ return false;
627
582
}
628
583
629
- static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
630
- .bind = acpi_thermal_bind_cooling_device ,
631
- .unbind = acpi_thermal_unbind_cooling_device ,
584
+ static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
585
+ .should_bind = acpi_thermal_should_bind_cdev ,
632
586
.get_temp = thermal_get_temp ,
633
587
.get_trend = thermal_get_trend ,
634
588
.hot = acpi_thermal_zone_device_hot ,
@@ -662,14 +616,15 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
662
616
}
663
617
664
618
static int acpi_thermal_register_thermal_zone (struct acpi_thermal * tz ,
619
+ const struct thermal_trip * trip_table ,
665
620
unsigned int trip_count ,
666
621
int passive_delay )
667
622
{
668
623
int result ;
669
624
670
625
if (trip_count )
671
626
tz -> thermal_zone = thermal_zone_device_register_with_trips (
672
- "acpitz" , tz -> trip_table , trip_count , 0 , tz ,
627
+ "acpitz" , trip_table , trip_count , tz ,
673
628
& acpi_thermal_zone_ops , NULL , passive_delay ,
674
629
tz -> polling_frequency * 100 );
675
630
else
@@ -824,10 +779,10 @@ static void acpi_thermal_free_thermal_zone(struct acpi_thermal *tz)
824
779
825
780
static int acpi_thermal_add (struct acpi_device * device )
826
781
{
782
+ struct thermal_trip trip_table [ACPI_THERMAL_MAX_NR_TRIPS ] = { 0 };
827
783
struct acpi_thermal_trip * acpi_trip ;
828
784
struct thermal_trip * trip ;
829
785
struct acpi_thermal * tz ;
830
- unsigned int trip_count ;
831
786
int crit_temp , hot_temp ;
832
787
int passive_delay = 0 ;
833
788
int result ;
@@ -849,21 +804,10 @@ static int acpi_thermal_add(struct acpi_device *device)
849
804
acpi_thermal_aml_dependency_fix (tz );
850
805
851
806
/* Get trip points [_CRT, _PSV, etc.] (required). */
852
- trip_count = acpi_thermal_get_trip_points (tz );
807
+ acpi_thermal_get_trip_points (tz );
853
808
854
809
crit_temp = acpi_thermal_get_critical_trip (tz );
855
- if (crit_temp != THERMAL_TEMP_INVALID )
856
- trip_count ++ ;
857
-
858
810
hot_temp = acpi_thermal_get_hot_trip (tz );
859
- if (hot_temp != THERMAL_TEMP_INVALID )
860
- trip_count ++ ;
861
-
862
- if (!trip_count ) {
863
- pr_warn (FW_BUG "No valid trip points!\n" );
864
- result = - ENODEV ;
865
- goto free_memory ;
866
- }
867
811
868
812
/* Get temperature [_TMP] (required). */
869
813
result = acpi_thermal_get_temperature (tz );
@@ -882,13 +826,7 @@ static int acpi_thermal_add(struct acpi_device *device)
882
826
883
827
acpi_thermal_guess_offset (tz , crit_temp );
884
828
885
- trip = kcalloc (trip_count , sizeof (* trip ), GFP_KERNEL );
886
- if (!trip ) {
887
- result = - ENOMEM ;
888
- goto free_memory ;
889
- }
890
-
891
- tz -> trip_table = trip ;
829
+ trip = trip_table ;
892
830
893
831
if (crit_temp != THERMAL_TEMP_INVALID ) {
894
832
trip -> type = THERMAL_TRIP_CRITICAL ;
@@ -924,12 +862,17 @@ static int acpi_thermal_add(struct acpi_device *device)
924
862
trip ++ ;
925
863
}
926
864
927
- if (trip == tz -> trip_table )
865
+ if (trip == trip_table ) {
928
866
pr_warn (FW_BUG "No valid trip points!\n" );
867
+ result = - ENODEV ;
868
+ goto free_memory ;
869
+ }
929
870
930
- result = acpi_thermal_register_thermal_zone (tz , trip_count , passive_delay );
871
+ result = acpi_thermal_register_thermal_zone (tz , trip_table ,
872
+ trip - trip_table ,
873
+ passive_delay );
931
874
if (result )
932
- goto free_trips ;
875
+ goto free_memory ;
933
876
934
877
refcount_set (& tz -> thermal_check_count , 3 );
935
878
mutex_init (& tz -> thermal_check_lock );
@@ -948,8 +891,6 @@ static int acpi_thermal_add(struct acpi_device *device)
948
891
flush_wq :
949
892
flush_workqueue (acpi_thermal_pm_queue );
950
893
acpi_thermal_unregister_thermal_zone (tz );
951
- free_trips :
952
- kfree (tz -> trip_table );
953
894
free_memory :
954
895
acpi_thermal_free_thermal_zone (tz );
955
896
@@ -970,8 +911,7 @@ static void acpi_thermal_remove(struct acpi_device *device)
970
911
971
912
flush_workqueue (acpi_thermal_pm_queue );
972
913
acpi_thermal_unregister_thermal_zone (tz );
973
- kfree (tz -> trip_table );
974
- kfree (tz );
914
+ acpi_thermal_free_thermal_zone (tz );
975
915
}
976
916
977
917
#ifdef CONFIG_PM_SLEEP
0 commit comments