@@ -661,7 +661,6 @@ struct cooling_dev_stats {
661661 spinlock_t lock ;
662662 unsigned int total_trans ;
663663 unsigned long state ;
664- unsigned long max_states ;
665664 ktime_t last_time ;
666665 ktime_t * time_in_state ;
667666 unsigned int * trans_table ;
@@ -691,7 +690,7 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
691690 goto unlock ;
692691
693692 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 ]++ ;
695694 stats -> state = new_state ;
696695 stats -> total_trans ++ ;
697696
@@ -725,7 +724,7 @@ time_in_state_ms_show(struct device *dev, struct device_attribute *attr,
725724 spin_lock (& stats -> lock );
726725 update_time_in_state (stats );
727726
728- for (i = 0 ; i < stats -> max_states ; i ++ ) {
727+ for (i = 0 ; i <= cdev -> max_state ; i ++ ) {
729728 len += sprintf (buf + len , "state%u\t%llu\n" , i ,
730729 ktime_to_ms (stats -> time_in_state [i ]));
731730 }
@@ -740,7 +739,7 @@ reset_store(struct device *dev, struct device_attribute *attr, const char *buf,
740739{
741740 struct thermal_cooling_device * cdev = to_cooling_device (dev );
742741 struct cooling_dev_stats * stats = cdev -> stats ;
743- int i , states = stats -> max_states ;
742+ int i , states = cdev -> max_state + 1 ;
744743
745744 spin_lock (& stats -> lock );
746745
@@ -749,7 +748,7 @@ reset_store(struct device *dev, struct device_attribute *attr, const char *buf,
749748 memset (stats -> trans_table , 0 ,
750749 states * states * sizeof (* stats -> trans_table ));
751750
752- for (i = 0 ; i < stats -> max_states ; i ++ )
751+ for (i = 0 ; i < states ; i ++ )
753752 stats -> time_in_state [i ] = ktime_set (0 , 0 );
754753
755754 spin_unlock (& stats -> lock );
@@ -767,7 +766,7 @@ static ssize_t trans_table_show(struct device *dev,
767766
768767 len += snprintf (buf + len , PAGE_SIZE - len , " From : To\n" );
769768 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 ++ ) {
771770 if (len >= PAGE_SIZE )
772771 break ;
773772 len += snprintf (buf + len , PAGE_SIZE - len , "state%2u " , i );
@@ -777,17 +776,17 @@ static ssize_t trans_table_show(struct device *dev,
777776
778777 len += snprintf (buf + len , PAGE_SIZE - len , "\n" );
779778
780- for (i = 0 ; i < stats -> max_states ; i ++ ) {
779+ for (i = 0 ; i <= cdev -> max_state ; i ++ ) {
781780 if (len >= PAGE_SIZE )
782781 break ;
783782
784783 len += snprintf (buf + len , PAGE_SIZE - len , "state%2u:" , i );
785784
786- for (j = 0 ; j < stats -> max_states ; j ++ ) {
785+ for (j = 0 ; j <= cdev -> max_state ; j ++ ) {
787786 if (len >= PAGE_SIZE )
788787 break ;
789788 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 ]);
791790 }
792791 if (len >= PAGE_SIZE )
793792 break ;
@@ -823,14 +822,10 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
823822{
824823 const struct attribute_group * stats_attr_group = NULL ;
825824 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 ;
827827 int var ;
828828
829- if (cdev -> ops -> get_max_state (cdev , & states ))
830- goto out ;
831-
832- states ++ ; /* Total number of states is highest state + 1 */
833-
834829 var = sizeof (* stats );
835830 var += sizeof (* stats -> time_in_state ) * states ;
836831 var += sizeof (* stats -> trans_table ) * states * states ;
@@ -843,7 +838,6 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
843838 stats -> trans_table = (unsigned int * )(stats -> time_in_state + states );
844839 cdev -> stats = stats ;
845840 stats -> last_time = ktime_get ();
846- stats -> max_states = states ;
847841
848842 spin_lock_init (& stats -> lock );
849843
0 commit comments