2023-02-03 17:51:55

by Daniel Lezcano

[permalink] [raw]
Subject: [PATCH v2 05/11] thermal/acpi: Optimize get_trip_points()

The function has two purposes. Initialize the trip points by reading
the ACPI table and then doing a check trip points exists.

This check will go through all the trip points and at the end if a
valid trip point is found, the parsing is considered valid.

Instead of checking all the trip points, exit when a valid trip point
is found.

Signed-off-by: Daniel Lezcano <[email protected]>
---
drivers/acpi/thermal.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 903f0e3d95f5..c4fd583fbf5c 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -461,23 +461,20 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)

static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
{
- int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
+ int i, ret;

+ ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
if (ret)
return ret;

- valid = tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid |
- tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid |
- tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid;
+ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
+ if (tz->trips[i].flags.valid)
+ return 0;
+ }

- for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++)
- valid |= tz->trips[i].flags.valid;
+ pr_warn(FW_BUG "No valid trip found\n");

- if (!valid) {
- pr_warn(FW_BUG "No valid trip found\n");
- return -ENODEV;
- }
- return 0;
+ return -ENODEV;
}

/* sys I/F for generic thermal sysfs support */
--
2.34.1