From 2021dc17f8ee24ee50effd2c7a4e3452da2cea17 Mon Sep 17 00:00:00 2001 From: Patrick Wildt Date: Tue, 3 Dec 2019 09:17:21 +0000 Subject: 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@ --- sys/dev/ofw/ofw_thermal.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'sys/dev') 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) -- cgit v1.2.3