@@ -93,6 +93,13 @@ struct power_allocator_params {
9393 struct power_actor * power ;
9494};
9595
96+ static bool power_actor_is_valid (struct power_allocator_params * params ,
97+ struct thermal_instance * instance )
98+ {
99+ return (instance -> trip == params -> trip_max &&
100+ cdev_is_power_actor (instance -> cdev ));
101+ }
102+
96103/**
97104 * estimate_sustainable_power() - Estimate the sustainable power of a thermal zone
98105 * @tz: thermal zone we are operating in
@@ -113,14 +120,10 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
113120 u32 min_power ;
114121
115122 list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
116- cdev = instance -> cdev ;
117-
118- if (instance -> trip != params -> trip_max )
119- continue ;
120-
121- if (!cdev_is_power_actor (cdev ))
123+ if (!power_actor_is_valid (params , instance ))
122124 continue ;
123125
126+ cdev = instance -> cdev ;
124127 if (cdev -> ops -> state2power (cdev , instance -> upper , & min_power ))
125128 continue ;
126129
@@ -409,8 +412,7 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp)
409412 return - ENODEV ;
410413
411414 list_for_each_entry (instance , & tz -> thermal_instances , tz_node )
412- if ((instance -> trip == params -> trip_max ) &&
413- cdev_is_power_actor (instance -> cdev ))
415+ if (power_actor_is_valid (params , instance ))
414416 total_weight += instance -> weight ;
415417
416418 /* Clean all buffers for new power estimations */
@@ -419,13 +421,10 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp)
419421 list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
420422 struct power_actor * pa = & power [i ];
421423
422- cdev = instance -> cdev ;
423-
424- if (instance -> trip != params -> trip_max )
424+ if (!power_actor_is_valid (params , instance ))
425425 continue ;
426426
427- if (!cdev_is_power_actor (cdev ))
428- continue ;
427+ cdev = instance -> cdev ;
429428
430429 ret = cdev -> ops -> get_requested_power (cdev , & pa -> req_power );
431430 if (ret )
@@ -459,10 +458,7 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp)
459458 list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
460459 struct power_actor * pa = & power [i ];
461460
462- if (instance -> trip != params -> trip_max )
463- continue ;
464-
465- if (!cdev_is_power_actor (instance -> cdev ))
461+ if (!power_actor_is_valid (params , instance ))
466462 continue ;
467463
468464 power_actor_set_power (instance -> cdev , instance ,
@@ -548,12 +544,11 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update)
548544 u32 req_power ;
549545
550546 list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
551- cdev = instance -> cdev ;
552-
553- if (instance -> trip != params -> trip_max ||
554- !cdev_is_power_actor (instance -> cdev ))
547+ if (!power_actor_is_valid (params , instance ))
555548 continue ;
556549
550+ cdev = instance -> cdev ;
551+
557552 instance -> target = 0 ;
558553 mutex_lock (& cdev -> lock );
559554 /*
@@ -648,8 +643,7 @@ static void power_allocator_update_tz(struct thermal_zone_device *tz,
648643 case THERMAL_TZ_BIND_CDEV :
649644 case THERMAL_TZ_UNBIND_CDEV :
650645 list_for_each_entry (instance , & tz -> thermal_instances , tz_node )
651- if ((instance -> trip == params -> trip_max ) &&
652- cdev_is_power_actor (instance -> cdev ))
646+ if (power_actor_is_valid (params , instance ))
653647 num_actors ++ ;
654648
655649 if (num_actors == params -> num_actors )
0 commit comments