mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nvme-hwmon: clamp threshold input before Kelvin conversion
@ 2026-12-02 16:49 Andrew Stellman
  0 siblings, 0 replies; only message in thread
From: Andrew Stellman @ 2026-12-02 16:49 UTC (permalink / raw)
  To: Guenter Roeck, Keith Busch, Christoph Hellwig
  Cc: Jens Axboe, Sagi Grimberg, Akinobu Mita, linux-nvme, linux-kernel

From: Andrew Stellman <astellman@stellman-greene.com>

nvme_set_temp_thresh() calls millicelsius_to_kelvin() before clamping
the value. From reading the code, an input close to LONG_MAX
overflows in that conversion, so the clamp then programs 0 K instead
of the maximum.

Clamp the millidegree input before converting it.

Fixes: 52deba0f02a9 ("nvme: hwmon: provide temperature min and max values for each sensor")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
Tested on mainline 19cc08c1a6a6 (7.4.0-rc5) in arm64 QEMU with KASAN:
writing 9223372036854775807 to temp1_max set 0 K without the patch and
65535 K with it.
Found with Quality Playbook
(https://github.com/andrewstellman/quality-playbook) running Claude Opus
5.5; the fix was drafted with OpenAI GPT-6 (Codex).
A reproducer is available on request.

 drivers/nvme/host/hwmon.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nvme/host/hwmon.c b/drivers/nvme/host/hwmon.c
index 406203d8b9ad..fd5aea5c5d9a 100644
--- a/drivers/nvme/host/hwmon.c
+++ b/drivers/nvme/host/hwmon.c
@@ -43,6 +43,8 @@ static int nvme_set_temp_thresh(struct nvme_ctrl *ctrl, int sensor, bool under,
 	unsigned int threshold = sensor << NVME_TEMP_THRESH_SELECT_SHIFT;
 	int ret;
 
+	temp = clamp_val(temp, ABSOLUTE_ZERO_MILLICELSIUS,
+			 kelvin_to_millicelsius(NVME_TEMP_THRESH_MASK));
 	temp = millicelsius_to_kelvin(temp);
 	threshold |= clamp_val(temp, 0, NVME_TEMP_THRESH_MASK);
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02 16:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 16:49 [PATCH] nvme-hwmon: clamp threshold input before Kelvin conversion Andrew Stellman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®