* [PATCH] hwmon: (vt8231) Clamp voltage limits before scaling
@ 2026-11-09 9:37 Zhu Jun
2026-11-09 9:47 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-09 9:37 UTC (permalink / raw)
To: vt8231; +Cc: zhujun, linux, linux-hwmon, linux-kernel
From: zhujun <zhujun2@cmss.chinamobile.com>
The voltage limit stores multiply an unrestricted unsigned long before
clamping the register value. Large inputs can wrap and select a low
threshold. On 32-bit systems, writing 4483265 mV to a regular voltage
limit selects register 3 instead of 255.
Bound the input before multiplication, using the separate scaling for
input 5. This preserves the conversion throughout the representable
range.
Fixes: 1de9e371b89e ("[PATCH] hwmon: New vt8231 driver")
---
Validation: x86-64 and i386 driver objects built with W=1.
Source-extracted boundary tests passed on 32-bit and 64-bit;
the corresponding test fails on the base revision. I/O is mocked.
No physical sensor hardware or booted-kernel test was available.
OpenAI Codex assisted analysis, code, tests and changelog drafting.
The human submitter must review and add their Signed-off-by.
drivers/hwmon/vt8231.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 1fe361bc30e2..a022119ee305 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -293,6 +293,7 @@ static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
return err;
mutex_lock(&data->update_lock);
+ val = min(val, 255UL * 10000 / 958);
data->in_min[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255);
vt8231_write_value(data, regvoltmin[nr], data->in_min[nr]);
mutex_unlock(&data->update_lock);
@@ -313,6 +314,7 @@ static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
return err;
mutex_lock(&data->update_lock);
+ val = min(val, 255UL * 10000 / 958);
data->in_max[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255);
vt8231_write_value(data, regvoltmax[nr], data->in_max[nr]);
mutex_unlock(&data->update_lock);
@@ -360,6 +362,7 @@ static ssize_t in5_min_store(struct device *dev,
return err;
mutex_lock(&data->update_lock);
+ val = min(val, 255UL * 10000 * 54 / (958 * 34));
data->in_min[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3,
0, 255);
vt8231_write_value(data, regvoltmin[5], data->in_min[5]);
@@ -380,6 +383,7 @@ static ssize_t in5_max_store(struct device *dev,
return err;
mutex_lock(&data->update_lock);
+ val = min(val, 255UL * 10000 * 54 / (958 * 34));
data->in_max[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3,
0, 255);
vt8231_write_value(data, regvoltmax[5], data->in_max[5]);
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] hwmon: (vt8231) Clamp voltage limits before scaling
@ 2026-11-11 6:51 Zhu Jun
2026-11-11 7:00 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-11 6:51 UTC (permalink / raw)
To: vt8231; +Cc: linux, linux-hwmon, linux-kernel, Zhu Jun
The voltage limit stores multiply an unrestricted unsigned long before
clamping the register value. Large inputs can wrap and select a low
threshold. On 32-bit systems, writing 4483265 mV to a regular voltage
limit selects register 3 instead of 255.
Bound the input before multiplication, using the separate scaling for
input 5. This preserves the conversion throughout the representable
range.
Fixes: 1de9e371b89e ("[PATCH] hwmon: New vt8231 driver")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/vt8231.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 1fe361bc30e2..a022119ee305 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -293,6 +293,7 @@ static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
return err;
mutex_lock(&data->update_lock);
+ val = min(val, 255UL * 10000 / 958);
data->in_min[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255);
vt8231_write_value(data, regvoltmin[nr], data->in_min[nr]);
mutex_unlock(&data->update_lock);
@@ -313,6 +314,7 @@ static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
return err;
mutex_lock(&data->update_lock);
+ val = min(val, 255UL * 10000 / 958);
data->in_max[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255);
vt8231_write_value(data, regvoltmax[nr], data->in_max[nr]);
mutex_unlock(&data->update_lock);
@@ -360,6 +362,7 @@ static ssize_t in5_min_store(struct device *dev,
return err;
mutex_lock(&data->update_lock);
+ val = min(val, 255UL * 10000 * 54 / (958 * 34));
data->in_min[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3,
0, 255);
vt8231_write_value(data, regvoltmin[5], data->in_min[5]);
@@ -380,6 +383,7 @@ static ssize_t in5_max_store(struct device *dev,
return err;
mutex_lock(&data->update_lock);
+ val = min(val, 255UL * 10000 * 54 / (958 * 34));
data->in_max[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3,
0, 255);
vt8231_write_value(data, regvoltmax[5], data->in_max[5]);
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-11 7:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09 9:37 [PATCH] hwmon: (vt8231) Clamp voltage limits before scaling Zhu Jun
2026-11-09 9:47 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-11 6:51 Zhu Jun
2026-11-11 7:00 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox