2023-10-02 18:17:54

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH v1 2/4] ACPI: thermal: Use thermal_zone_for_each_trip()

From: Rafael J. Wysocki <[email protected]>

Rearrange the code handling notifications from the platform firmware
to carry out one loop over trip points instead of two and use
thermal_zone_for_each_trip() for that, which is more straightforward
that using a combination of thermal_zone_device_exec() and
for_each_thermal_trip(), each with its own callback function.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/acpi/thermal.c | 58 +++++++++++++++++++++++++++----------------------
1 file changed, 32 insertions(+), 26 deletions(-)

Index: linux-pm/drivers/acpi/thermal.c
===================================================================
--- linux-pm.orig/drivers/acpi/thermal.c
+++ linux-pm/drivers/acpi/thermal.c
@@ -95,6 +95,7 @@ struct acpi_thermal_passive {

struct acpi_thermal_active {
struct acpi_thermal_trip trip;
+ int index;
};

struct acpi_thermal_trips {
@@ -285,14 +286,36 @@ static void acpi_thermal_update_active_t
ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
}

+struct adjust_trip_data {
+ struct acpi_thermal *tz;
+ u32 event;
+};
+
static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data)
{
struct acpi_thermal_trip *acpi_trip = trip->priv;
- struct acpi_thermal *tz = data;
+ struct adjust_trip_data *atd = data;
+ struct acpi_thermal *tz = atd->tz;

if (!acpi_trip)
return 0;

+ if (trip->type == THERMAL_TRIP_PASSIVE) {
+ if (atd->event == ACPI_THERMAL_NOTIFY_THRESHOLDS)
+ acpi_thermal_update_passive_trip(tz);
+ else
+ acpi_thermal_update_trip_devices(tz, ACPI_THERMAL_TRIP_PASSIVE);
+ } else {
+ /* Since acpi_trip is present, this must be an active trip. */
+ struct acpi_thermal_active *active;
+
+ active = container_of(acpi_trip, struct acpi_thermal_active, trip);
+ if (atd->event == ACPI_THERMAL_NOTIFY_THRESHOLDS)
+ acpi_thermal_update_active_trip(tz, active->index);
+ else
+ acpi_thermal_update_trip_devices(tz, active->index);
+ }
+
if (acpi_thermal_trip_valid(acpi_trip))
trip->temperature = acpi_thermal_temp(tz, acpi_trip->temp_dk);
else
@@ -301,25 +324,6 @@ static int acpi_thermal_adjust_trip(stru
return 0;
}

-static void acpi_thermal_adjust_thermal_zone(struct thermal_zone_device *thermal,
- unsigned long data)
-{
- struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
- int i;
-
- if (data == ACPI_THERMAL_NOTIFY_THRESHOLDS) {
- acpi_thermal_update_passive_trip(tz);
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
- acpi_thermal_update_active_trip(tz, i);
- } else {
- acpi_thermal_update_trip_devices(tz, ACPI_THERMAL_TRIP_PASSIVE);
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
- acpi_thermal_update_trip_devices(tz, i);
- }
-
- for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz);
-}
-
static void acpi_queue_thermal_check(struct acpi_thermal *tz)
{
if (!work_pending(&tz->thermal_check_work))
@@ -328,17 +332,18 @@ static void acpi_queue_thermal_check(str

static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
{
+ struct adjust_trip_data atd = { .tz = tz, .event = event };
struct acpi_device *adev = tz->device;

/*
- * Use thermal_zone_device_exec() to carry out the trip points
+ * Use thermal_zone_for_each_trip() to carry out the trip points
* update, so as to protect thermal_get_trend() from getting stale
* trip point temperatures and to prevent thermal_zone_device_update()
* invoked from acpi_thermal_check_fn() from producing inconsistent
* results.
*/
- thermal_zone_device_exec(tz->thermal_zone,
- acpi_thermal_adjust_thermal_zone, event);
+ thermal_zone_for_each_trip(tz->thermal_zone,
+ acpi_thermal_adjust_trip, &atd);
acpi_queue_thermal_check(tz);
acpi_bus_generate_netlink_event(adev->pnp.device_class,
dev_name(&adev->dev), event, 0);
@@ -466,11 +471,12 @@ static int acpi_thermal_get_trip_points(
count++;

for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
- if (acpi_thermal_init_trip(tz, i))
+ if (acpi_thermal_init_trip(tz, i)) {
+ tz->trips.active[i].index = i;
count++;
- else
+ } else {
break;
-
+ }
}

while (++i < ACPI_THERMAL_MAX_ACTIVE)