[PATCH 7/8] thermal/drivers/int340x: Use thermal zone device trip update

From: Daniel Lezcano
Date: Thu May 25 2023 - 10:02:59 EST


The current code takes the thermal zone device lock to update the
thermal trips.

Now we have an API allowing to update the thermal trip directly, so
use it and get ride of the thermal zone lock access.

Take also the opportunity to use the zone>-type accessor.

Signed-off-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
---
.../int340x_thermal/int340x_thermal_zone.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
index 89cf007146ea..94697063f41e 100644
--- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
+++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
@@ -58,7 +58,8 @@ static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,

static void int340x_thermal_critical(struct thermal_zone_device *zone)
{
- dev_dbg(&zone->device, "%s: critical temperature reached\n", zone->type);
+ dev_dbg(thermal_zone_device(zone), "%s: critical temperature reached\n",
+ thermal_zone_device_type(zone));
}

static struct thermal_zone_device_ops int340x_thermal_zone_ops = {
@@ -215,13 +216,15 @@ EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);
void int340x_thermal_update_trips(struct int34x_thermal_zone *int34x_zone)
{
struct acpi_device *zone_adev = int34x_zone->adev;
- struct thermal_trip *zone_trips = int34x_zone->trips;
- int trip_cnt = int34x_zone->zone->num_trips;
+ struct thermal_trip *zone_trips;
+ int trip_cnt = thermal_zone_get_num_trips(int34x_zone->zone);
int act_trip_nr = 0;
int i;

- mutex_lock(&int34x_zone->zone->lock);
-
+ zone_trips = kmemdup(int34x_zone->trips, sizeof(*zone_trips) * trip_cnt, GFP_KERNEL);
+ if (!zone_trips)
+ return;
+
for (i = int34x_zone->aux_trip_nr; i < trip_cnt; i++) {
int temp, err;

@@ -250,7 +253,9 @@ void int340x_thermal_update_trips(struct int34x_thermal_zone *int34x_zone)
zone_trips[i].temperature = temp;
}

- mutex_unlock(&int34x_zone->zone->lock);
+ if (!thermal_zone_trips_update(int34x_zone->zone, zone_trips, trip_cnt,
+ GENMASK_ULL((trip_cnt) - 1, 0)))
+ int34x_zone->trips = zone_trips;
}
EXPORT_SYMBOL_GPL(int340x_thermal_update_trips);

--
2.34.1