Skip to content

Commit d5ea889

Browse files
committed
ACPI: thermal: Do not use trip indices for cooling device binding
Rearrange the ACPI thermal driver's callback functions used for cooling device binding and unbinding, acpi_thermal_bind_cooling_device() and acpi_thermal_unbind_cooling_device(), respectively, so that they use trip pointers instead of trip indices which is more straightforward and allows the driver to become independent of the ordering of trips in the thermal zone structure. The general functionality is not expected to be changed. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Daniel Lezcano <[email protected]>
1 parent 3770201 commit d5ea889

File tree

1 file changed

+44
-66
lines changed

1 file changed

+44
-66
lines changed

drivers/acpi/thermal.c

Lines changed: 44 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -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

650628
static int
651629
acpi_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

657635
static int
658636
acpi_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

664642
static struct thermal_zone_device_ops acpi_thermal_zone_ops = {

0 commit comments

Comments
 (0)