* [PATCH] nvme-hwmon: clamp threshold input before Kelvin conversion
@ 2026-12-02 16:49 Andrew Stellman
2026-12-03 8:10 ` Christoph Hellwig
2026-12-03 21:22 ` Keith Busch
0 siblings, 2 replies; 3+ messages 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] 3+ messages in thread* Re: [PATCH] nvme-hwmon: clamp threshold input before Kelvin conversion
2026-12-02 16:49 [PATCH] nvme-hwmon: clamp threshold input before Kelvin conversion Andrew Stellman
@ 2026-12-03 8:10 ` Christoph Hellwig
2026-12-03 21:22 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-12-03 8:10 UTC (permalink / raw)
To: Andrew Stellman
Cc: Guenter Roeck, Keith Busch, Jens Axboe, Sagi Grimberg,
Akinobu Mita, linux-nvme, linux-kernel
On Wed, Dec 02, 2026 at 11:49:56AM -0500, Andrew Stellman wrote:
> 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.
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nvme-hwmon: clamp threshold input before Kelvin conversion
2026-12-02 16:49 [PATCH] nvme-hwmon: clamp threshold input before Kelvin conversion Andrew Stellman
2026-12-03 8:10 ` Christoph Hellwig
@ 2026-12-03 21:22 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2026-12-03 21:22 UTC (permalink / raw)
To: Guenter Roeck, Christoph Hellwig, Andrew Stellman
Cc: Jens Axboe, Sagi Grimberg, Akinobu Mita, linux-nvme, linux-kernel
On Wed, 2 Dec 2026 11:49:56 -0500, Andrew Stellman wrote:
> 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.
>
> [...]
Thanks, applied to nvme-7.4.
[1/1] nvme-hwmon: clamp threshold input before Kelvin conversion
commit: d647c9807cc0b0d3ae6fc4258ee473bb326603a7
--
Keith Busch <kbusch@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 21:22 UTC | newest]
Thread overview: 3+ messages (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
2026-12-03 8:10 ` Christoph Hellwig
2026-12-03 21:22 ` Keith Busch
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®