summaryrefslogtreecommitdiff
path: root/sys/dev/ofw
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2019-12-03 09:17:21 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2019-12-03 09:17:21 +0000
commit2021dc17f8ee24ee50effd2c7a4e3452da2cea17 (patch)
tree2edf81d9555505601148d781c64395e92b9ba2d5 /sys/dev/ofw
parent6a1b27f1ba1d870dd24f1d2c98893b83442e504d (diff)
Since device tree trip points might not be sorted, but our code
expected a sorted list, do the sorting ourselves upon parsing the trip points. ok kurt@
Diffstat (limited to 'sys/dev/ofw')
-rw-r--r--sys/dev/ofw/ofw_thermal.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/sys/dev/ofw/ofw_thermal.c b/sys/dev/ofw/ofw_thermal.c
index 636b05dc8a4..89b5d0e4d4a 100644
--- a/sys/dev/ofw/ofw_thermal.c
+++ b/sys/dev/ofw/ofw_thermal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofw_thermal.c,v 1.4 2019/08/28 19:37:56 kettenis Exp $ */
+/* $OpenBSD: ofw_thermal.c,v 1.5 2019/12/03 09:17:20 patrick Exp $ */
/*
* Copyright (c) 2019 Mark Kettenis
*
@@ -355,14 +355,29 @@ thermal_zone_init(int node)
tz->tz_trips = mallocarray(tz->tz_ntrips, sizeof(struct trippoint),
M_DEVBUF, M_ZERO | M_WAITOK);
- tp = tz->tz_trips;
node = OF_getnodebyname(tz->tz_node, "trips");
for (node = OF_child(node); node != 0; node = OF_peer(node)) {
char type[32] = "none";
+ int32_t temp;
+
+ temp = OF_getpropint(node, "temperature", THERMAL_SENSOR_MAX);
- tp->tp_temperature =
- OF_getpropint(node, "temperature", THERMAL_SENSOR_MAX);
+ /* Sorted insertion, since tree might not be */
+ for (i = 0; i < tz->tz_ntrips; i++) {
+ /* No trip point should be 0 degC, take it */
+ if (tz->tz_trips[i].tp_temperature == 0)
+ break;
+ /* We should be bigger than the one before us */
+ if (tz->tz_trips[i].tp_temperature < temp)
+ continue;
+ /* Free current slot */
+ memmove(&tz->tz_trips[i + 1], &tz->tz_trips[i],
+ (tz->tz_ntrips - (i + 1)) * sizeof(*tp));
+ break;
+ }
+ tp = &tz->tz_trips[i];
+ tp->tp_temperature = temp;
tp->tp_hysteresis = OF_getpropint(node, "hysteresis", 0);
OF_getprop(node, "type", type, sizeof(type));
if (strcmp(type, "active") == 0)