@@ -661,7 +661,6 @@ struct cooling_dev_stats {
661
661
spinlock_t lock ;
662
662
unsigned int total_trans ;
663
663
unsigned long state ;
664
- unsigned long max_states ;
665
664
ktime_t last_time ;
666
665
ktime_t * time_in_state ;
667
666
unsigned int * trans_table ;
@@ -691,7 +690,7 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
691
690
goto unlock ;
692
691
693
692
update_time_in_state (stats );
694
- stats -> trans_table [stats -> state * stats -> max_states + new_state ]++ ;
693
+ stats -> trans_table [stats -> state * ( cdev -> max_state + 1 ) + new_state ]++ ;
695
694
stats -> state = new_state ;
696
695
stats -> total_trans ++ ;
697
696
@@ -725,7 +724,7 @@ time_in_state_ms_show(struct device *dev, struct device_attribute *attr,
725
724
spin_lock (& stats -> lock );
726
725
update_time_in_state (stats );
727
726
728
- for (i = 0 ; i < stats -> max_states ; i ++ ) {
727
+ for (i = 0 ; i <= cdev -> max_state ; i ++ ) {
729
728
len += sprintf (buf + len , "state%u\t%llu\n" , i ,
730
729
ktime_to_ms (stats -> time_in_state [i ]));
731
730
}
@@ -740,7 +739,7 @@ reset_store(struct device *dev, struct device_attribute *attr, const char *buf,
740
739
{
741
740
struct thermal_cooling_device * cdev = to_cooling_device (dev );
742
741
struct cooling_dev_stats * stats = cdev -> stats ;
743
- int i , states = stats -> max_states ;
742
+ int i , states = cdev -> max_state + 1 ;
744
743
745
744
spin_lock (& stats -> lock );
746
745
@@ -749,7 +748,7 @@ reset_store(struct device *dev, struct device_attribute *attr, const char *buf,
749
748
memset (stats -> trans_table , 0 ,
750
749
states * states * sizeof (* stats -> trans_table ));
751
750
752
- for (i = 0 ; i < stats -> max_states ; i ++ )
751
+ for (i = 0 ; i < states ; i ++ )
753
752
stats -> time_in_state [i ] = ktime_set (0 , 0 );
754
753
755
754
spin_unlock (& stats -> lock );
@@ -767,7 +766,7 @@ static ssize_t trans_table_show(struct device *dev,
767
766
768
767
len += snprintf (buf + len , PAGE_SIZE - len , " From : To\n" );
769
768
len += snprintf (buf + len , PAGE_SIZE - len , " : " );
770
- for (i = 0 ; i < stats -> max_states ; i ++ ) {
769
+ for (i = 0 ; i <= cdev -> max_state ; i ++ ) {
771
770
if (len >= PAGE_SIZE )
772
771
break ;
773
772
len += snprintf (buf + len , PAGE_SIZE - len , "state%2u " , i );
@@ -777,17 +776,17 @@ static ssize_t trans_table_show(struct device *dev,
777
776
778
777
len += snprintf (buf + len , PAGE_SIZE - len , "\n" );
779
778
780
- for (i = 0 ; i < stats -> max_states ; i ++ ) {
779
+ for (i = 0 ; i <= cdev -> max_state ; i ++ ) {
781
780
if (len >= PAGE_SIZE )
782
781
break ;
783
782
784
783
len += snprintf (buf + len , PAGE_SIZE - len , "state%2u:" , i );
785
784
786
- for (j = 0 ; j < stats -> max_states ; j ++ ) {
785
+ for (j = 0 ; j <= cdev -> max_state ; j ++ ) {
787
786
if (len >= PAGE_SIZE )
788
787
break ;
789
788
len += snprintf (buf + len , PAGE_SIZE - len , "%8u " ,
790
- stats -> trans_table [i * stats -> max_states + j ]);
789
+ stats -> trans_table [i * ( cdev -> max_state + 1 ) + j ]);
791
790
}
792
791
if (len >= PAGE_SIZE )
793
792
break ;
@@ -823,14 +822,10 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
823
822
{
824
823
const struct attribute_group * stats_attr_group = NULL ;
825
824
struct cooling_dev_stats * stats ;
826
- unsigned long states ;
825
+ /* Total number of states is highest state + 1 */
826
+ unsigned long states = cdev -> max_state + 1 ;
827
827
int var ;
828
828
829
- if (cdev -> ops -> get_max_state (cdev , & states ))
830
- goto out ;
831
-
832
- states ++ ; /* Total number of states is highest state + 1 */
833
-
834
829
var = sizeof (* stats );
835
830
var += sizeof (* stats -> time_in_state ) * states ;
836
831
var += sizeof (* stats -> trans_table ) * states * states ;
@@ -843,7 +838,6 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
843
838
stats -> trans_table = (unsigned int * )(stats -> time_in_state + states );
844
839
cdev -> stats = stats ;
845
840
stats -> last_time = ktime_get ();
846
- stats -> max_states = states ;
847
841
848
842
spin_lock_init (& stats -> lock );
849
843
0 commit comments