Skip to content

Commit 317508c

Browse files
committed
ACPI: thermal: Collapse trip devices update functions
In order to reduce code duplication, merge update_passive_devices() and update_active_devices() into one function called update_trip_devices() that will be used for updating both the passive and active trip points. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Daniel Lezcano <[email protected]>
1 parent 0fa1bf3 commit 317508c

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

drivers/acpi/thermal.c

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#define ACPI_THERMAL_MAX_ACTIVE 10
4444
#define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
4545

46+
#define ACPI_THERMAL_TRIP_PASSIVE (-1)
47+
4648
/*
4749
* This exception is thrown out in two cases:
4850
* 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
@@ -202,18 +204,25 @@ static void acpi_thermal_update_passive_trip(struct acpi_thermal *tz)
202204
ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
203205
}
204206

205-
static bool update_passive_devices(struct acpi_thermal *tz, bool compare)
207+
static bool update_trip_devices(struct acpi_thermal *tz,
208+
struct acpi_thermal_trip *acpi_trip,
209+
int index, bool compare)
206210
{
207-
struct acpi_thermal_trip *acpi_trip = &tz->trips.passive.trip;
208211
struct acpi_handle_list devices;
212+
char method[] = "_PSL";
209213
acpi_status status;
210214

215+
if (index != ACPI_THERMAL_TRIP_PASSIVE) {
216+
method[1] = 'A';
217+
method[2] = 'L';
218+
method[3] = '0' + index;
219+
}
220+
211221
memset(&devices, 0, sizeof(devices));
212222

213-
status = acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices);
223+
status = acpi_evaluate_reference(tz->device->handle, method, NULL, &devices);
214224
if (ACPI_FAILURE(status)) {
215-
acpi_handle_info(tz->device->handle,
216-
"Missing device list for passive threshold\n");
225+
acpi_handle_info(tz->device->handle, "%s evaluation failure\n", method);
217226
return false;
218227
}
219228

@@ -231,8 +240,9 @@ static void acpi_thermal_update_passive_devices(struct acpi_thermal *tz)
231240
if (!acpi_thermal_trip_valid(acpi_trip))
232241
return;
233242

234-
if (update_passive_devices(tz, true))
243+
if (update_trip_devices(tz, acpi_trip, ACPI_THERMAL_TRIP_PASSIVE, true)) {
235244
return;
245+
}
236246

237247
acpi_trip->temperature = THERMAL_TEMP_INVALID;
238248
ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
@@ -273,38 +283,14 @@ static void acpi_thermal_update_active_trip(struct acpi_thermal *tz, int index)
273283
ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
274284
}
275285

276-
static bool update_active_devices(struct acpi_thermal *tz, int index, bool compare)
277-
{
278-
char method[] = { '_', 'A', 'L', '0' + index, '\0' };
279-
struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip;
280-
struct acpi_handle_list devices;
281-
acpi_status status;
282-
283-
memset(&devices, 0, sizeof(devices));
284-
285-
status = acpi_evaluate_reference(tz->device->handle, method, NULL, &devices);
286-
if (ACPI_FAILURE(status)) {
287-
acpi_handle_info(tz->device->handle,
288-
"Missing device list for active threshold %d\n",
289-
index);
290-
return false;
291-
}
292-
293-
if (compare && memcmp(&acpi_trip->devices, &devices, sizeof(devices)))
294-
ACPI_THERMAL_TRIPS_EXCEPTION(tz, "device");
295-
296-
memcpy(&acpi_trip->devices, &devices, sizeof(devices));
297-
return true;
298-
}
299-
300286
static void acpi_thermal_update_active_devices(struct acpi_thermal *tz, int index)
301287
{
302288
struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip;
303289

304290
if (!acpi_thermal_trip_valid(acpi_trip))
305291
return;
306292

307-
if (update_active_devices(tz, index, true))
293+
if (update_trip_devices(tz, acpi_trip, index, true))
308294
return;
309295

310296
acpi_trip->temperature = THERMAL_TEMP_INVALID;
@@ -460,7 +446,8 @@ static bool acpi_thermal_init_passive_trip(struct acpi_thermal *tz)
460446

461447
tz->trips.passive.tsp = tmp;
462448

463-
if (!update_passive_devices(tz, false))
449+
if (!update_trip_devices(tz, &tz->trips.passive.trip,
450+
ACPI_THERMAL_TRIP_PASSIVE, false))
464451
goto fail;
465452

466453
tz->trips.passive.trip.temperature = temp;
@@ -482,7 +469,7 @@ static bool acpi_thermal_init_active_trip(struct acpi_thermal *tz, int index)
482469
if (temp == THERMAL_TEMP_INVALID)
483470
goto fail;
484471

485-
if (!update_active_devices(tz, index, false))
472+
if (!update_trip_devices(tz, &tz->trips.active[index].trip, index, false))
486473
goto fail;
487474

488475
tz->trips.active[index].trip.temperature = temp;

0 commit comments

Comments
 (0)