@@ -571,94 +571,72 @@ static void acpi_thermal_zone_device_critical(struct thermal_zone_device *therma
571571 thermal_zone_device_critical (thermal );
572572}
573573
574- static int acpi_thermal_cooling_device_cb (struct thermal_zone_device * thermal ,
575- struct thermal_cooling_device * cdev ,
576- bool bind )
574+ struct acpi_thermal_bind_data {
575+ struct thermal_zone_device * thermal ;
576+ struct thermal_cooling_device * cdev ;
577+ bool bind ;
578+ };
579+
580+ static int bind_unbind_cdev_cb (struct thermal_trip * trip , void * arg )
577581{
578- struct acpi_device * device = cdev -> devdata ;
579- struct acpi_thermal * tz = thermal_zone_device_priv ( thermal ) ;
580- struct acpi_thermal_trip * acpi_trip ;
581- struct acpi_device * dev ;
582- acpi_handle handle ;
582+ struct acpi_thermal_trip * acpi_trip = trip -> priv ;
583+ struct acpi_thermal_bind_data * bd = arg ;
584+ struct thermal_zone_device * thermal = bd -> thermal ;
585+ struct thermal_cooling_device * cdev = bd -> cdev ;
586+ struct acpi_device * cdev_adev = cdev -> devdata ;
583587 int i ;
584- int j ;
585- int trip = -1 ;
586- int result = 0 ;
587588
588- if (tz -> trips .critical_valid )
589- trip ++ ;
589+ /* Skip critical and hot trips. */
590+ if (!acpi_trip )
591+ return 0 ;
590592
591- if (tz -> trips .hot_valid )
592- trip ++ ;
593+ for (i = 0 ; i < acpi_trip -> devices .count ; i ++ ) {
594+ acpi_handle handle = acpi_trip -> devices .handles [i ];
595+ struct acpi_device * adev = acpi_fetch_acpi_dev (handle );
593596
594- acpi_trip = & tz -> trips .passive .trip ;
595- if (acpi_thermal_trip_valid (acpi_trip )) {
596- trip ++ ;
597- for (i = 0 ; i < acpi_trip -> devices .count ; i ++ ) {
598- handle = acpi_trip -> devices .handles [i ];
599- dev = acpi_fetch_acpi_dev (handle );
600- if (dev != device )
601- continue ;
602-
603- if (bind )
604- result = thermal_zone_bind_cooling_device (
605- thermal , trip , cdev ,
606- THERMAL_NO_LIMIT ,
607- THERMAL_NO_LIMIT ,
608- THERMAL_WEIGHT_DEFAULT );
609- else
610- result =
611- thermal_zone_unbind_cooling_device (
612- thermal , trip , cdev );
613-
614- if (result )
615- goto failed ;
616- }
617- }
597+ if (adev != cdev_adev )
598+ continue ;
618599
619- for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ ) {
620- acpi_trip = & tz -> trips .active [i ].trip ;
621- if (!acpi_thermal_trip_valid (acpi_trip ))
622- break ;
600+ if (bd -> bind ) {
601+ int ret ;
623602
624- trip ++ ;
625- for (j = 0 ; j < acpi_trip -> devices .count ; j ++ ) {
626- handle = acpi_trip -> devices .handles [j ];
627- dev = acpi_fetch_acpi_dev (handle );
628- if (dev != device )
629- continue ;
630-
631- if (bind )
632- result = thermal_zone_bind_cooling_device (
633- thermal , trip , cdev ,
634- THERMAL_NO_LIMIT ,
635- THERMAL_NO_LIMIT ,
636- THERMAL_WEIGHT_DEFAULT );
637- else
638- result = thermal_zone_unbind_cooling_device (
639- thermal , trip , cdev );
640-
641- if (result )
642- goto failed ;
603+ ret = thermal_bind_cdev_to_trip (thermal , trip , cdev ,
604+ THERMAL_NO_LIMIT ,
605+ THERMAL_NO_LIMIT ,
606+ THERMAL_WEIGHT_DEFAULT );
607+ if (ret )
608+ return ret ;
609+ } else {
610+ thermal_unbind_cdev_from_trip (thermal , trip , cdev );
643611 }
644612 }
645613
646- failed :
647- return result ;
614+ return 0 ;
615+ }
616+
617+ static int acpi_thermal_bind_unbind_cdev (struct thermal_zone_device * thermal ,
618+ struct thermal_cooling_device * cdev ,
619+ bool bind )
620+ {
621+ struct acpi_thermal_bind_data bd = {
622+ .thermal = thermal , .cdev = cdev , .bind = bind
623+ };
624+
625+ return for_each_thermal_trip (thermal , bind_unbind_cdev_cb , & bd );
648626}
649627
650628static int
651629acpi_thermal_bind_cooling_device (struct thermal_zone_device * thermal ,
652630 struct thermal_cooling_device * cdev )
653631{
654- return acpi_thermal_cooling_device_cb (thermal , cdev , true);
632+ return acpi_thermal_bind_unbind_cdev (thermal , cdev , true);
655633}
656634
657635static int
658636acpi_thermal_unbind_cooling_device (struct thermal_zone_device * thermal ,
659637 struct thermal_cooling_device * cdev )
660638{
661- return acpi_thermal_cooling_device_cb (thermal , cdev , false);
639+ return acpi_thermal_bind_unbind_cdev (thermal , cdev , false);
662640}
663641
664642static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
0 commit comments