* [PATCH] thermal: spacemit: validate clamped trip thresholds
@ 2026-07-20 10:36 kr494167
0 siblings, 0 replies; only message in thread
From: kr494167 @ 2026-07-20 10:36 UTC (permalink / raw)
To: rafael, daniel.lezcano, dlan
Cc: rui.zhang, lukasz.luba, shuwei.wu, linux-pm, linux-riscv,
spacemit, linux-kernel, surendra
From: surendra <kr494167@gmail.com>
k1_tsensor_set_trips() checks the requested trip temperatures before
converting them to the sensor register representation. Distinct
out-of-range temperatures can clamp to the same hardware value, leaving the
sensor with an invalid low/high threshold pair.
Validate the ordering after conversion and clamping.
Fixes: 296a977f2bac ("thermal/drivers/spacemit/k1: Add thermal sensor support")
Signed-off-by: surendra <kr494167@gmail.com>
---
drivers/thermal/spacemit/k1_tsensor.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/spacemit/k1_tsensor.c b/drivers/thermal/spacemit/k1_tsensor.c
index 79222d233129..a9eaedefdac3 100644
--- a/drivers/thermal/spacemit/k1_tsensor.c
+++ b/drivers/thermal/spacemit/k1_tsensor.c
@@ -156,13 +156,12 @@ static int k1_tsensor_set_trips(struct thermal_zone_device *tz, int low, int hig
struct k1_tsensor *ts = ch->ts;
u32 val;
- if (low >= high)
- return -EINVAL;
-
low = clamp_val(low / 1000 + TEMPERATURE_OFFSET, TEMPERATURE_OFFSET,
FIELD_MAX(K1_TSENSOR_THRSH_LOW_MASK));
high = clamp_val(high / 1000 + TEMPERATURE_OFFSET, TEMPERATURE_OFFSET,
FIELD_MAX(K1_TSENSOR_THRSH_HIGH_MASK));
+ if (low >= high)
+ return -EINVAL;
val = readl(ts->base + K1_TSENSOR_THRSH_REG(ch->id));
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-20 10:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 10:36 [PATCH] thermal: spacemit: validate clamped trip thresholds kr494167
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox