* [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
@ 2026-11-09 9:25 Zhu Jun
2026-11-09 20:00 ` sashiko-bot
0 siblings, 1 reply; 8+ messages in thread
From: Zhu Jun @ 2026-11-09 9:25 UTC (permalink / raw)
To: linux; +Cc: linux-hwmon, linux-kernel, zhujun
From: zhujun <zhujun2@cmss.chinamobile.com>
store_in_reg() parses an unsigned long, but in_to_reg() takes a u32 and
multiplies it by 100 before clamping. Large limits can therefore wrap to
a low register value. For example, 4294967296 mV becomes zero on a
64-bit system.
Keep the input as an unsigned long and bound it to the register range
before scaling.
Fixes: 9de2e2e84e7d ("hwmon: Driver for Nuvoton NCT6775F, NCT6776F, and NCT6779D")
---
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/nct6775-core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/nct6775-core.c b/drivers/hwmon/nct6775-core.c
index 6e97e4f08b90..b7c1e8ceaac9 100644
--- a/drivers/hwmon/nct6775-core.c
+++ b/drivers/hwmon/nct6775-core.c
@@ -1039,8 +1039,9 @@ static inline long in_from_reg(u8 reg, u8 nr, const u16 *scales)
return DIV_ROUND_CLOSEST(reg * scales[nr], 100);
}
-static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scales)
+static inline u8 in_to_reg(unsigned long val, u8 nr, const u16 *scales)
{
+ val = min(val, 255UL * scales[nr] / 100);
return clamp_val(DIV_ROUND_CLOSEST(val * 100, scales[nr]), 0, 255);
}
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
2026-11-09 9:25 Zhu Jun
@ 2026-11-09 20:00 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-09 20:00 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> From: zhujun <zhujun2@cmss.chinamobile.com>
>
> store_in_reg() parses an unsigned long, but in_to_reg() takes a u32 and
> multiplies it by 100 before clamping. Large limits can therefore wrap to
> a low register value. For example, 4294967296 mV becomes zero on a
> 64-bit system.
>
> Keep the input as an unsigned long and bound it to the register range
> before scaling.
>
> Fixes: 9de2e2e84e7d ("hwmon: Driver for Nuvoton NCT6775F, NCT6776F, and NCT6779D")
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109092533.5146-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
@ 2026-11-11 2:39 Zhu Jun
2026-11-11 2:58 ` sashiko-bot
0 siblings, 1 reply; 8+ messages in thread
From: Zhu Jun @ 2026-11-11 2:39 UTC (permalink / raw)
To: linux; +Cc: linux-hwmon, linux-kernel
store_in_reg() parses an unsigned long, but in_to_reg() takes a u32 and
multiplies it by 100 before clamping. Large limits can therefore wrap to
a low register value. For example, 4294967296 mV becomes zero on a
64-bit system.
Keep the input as an unsigned long and bound it to the register range
before scaling.
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/nct6775-core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/nct6775-core.c b/drivers/hwmon/nct6775-core.c
index 6e97e4f08b90..b7c1e8ceaac9 100644
--- a/drivers/hwmon/nct6775-core.c
+++ b/drivers/hwmon/nct6775-core.c
@@ -1039,8 +1039,9 @@ static inline long in_from_reg(u8 reg, u8 nr, const u16 *scales)
return DIV_ROUND_CLOSEST(reg * scales[nr], 100);
}
-static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scales)
+static inline u8 in_to_reg(unsigned long val, u8 nr, const u16 *scales)
{
+ val = min(val, 255UL * scales[nr] / 100);
return clamp_val(DIV_ROUND_CLOSEST(val * 100, scales[nr]), 0, 255);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
@ 2026-11-11 2:45 Zhu Jun
2026-11-11 3:03 ` sashiko-bot
0 siblings, 1 reply; 8+ messages in thread
From: Zhu Jun @ 2026-11-11 2:45 UTC (permalink / raw)
To: linux; +Cc: linux-hwmon, linux-kernel, Zhu Jun
store_in_reg() parses an unsigned long, but in_to_reg() takes a u32 and
multiplies it by 100 before clamping. Large limits can therefore wrap to
a low register value. For example, 4294967296 mV becomes zero on a
64-bit system.
Keep the input as an unsigned long and bound it to the register range
before scaling.
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/nct6775-core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/nct6775-core.c b/drivers/hwmon/nct6775-core.c
index 6e97e4f08b90..b7c1e8ceaac9 100644
--- a/drivers/hwmon/nct6775-core.c
+++ b/drivers/hwmon/nct6775-core.c
@@ -1039,8 +1039,9 @@ static inline long in_from_reg(u8 reg, u8 nr, const u16 *scales)
return DIV_ROUND_CLOSEST(reg * scales[nr], 100);
}
-static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scales)
+static inline u8 in_to_reg(unsigned long val, u8 nr, const u16 *scales)
{
+ val = min(val, 255UL * scales[nr] / 100);
return clamp_val(DIV_ROUND_CLOSEST(val * 100, scales[nr]), 0, 255);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
2026-11-11 2:39 [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling Zhu Jun
@ 2026-11-11 2:58 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-11 2:58 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] hwmon: (nct6775) missing Fixes: trailer for in_to_reg() overflow
fix
--
commit 4db65731cc107b583fd8b0467f24228d05ec41f5
Author: Zhu Jun <zhujun2@cmss.chinamobile.com>
> hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
>
> store_in_reg() parses an unsigned long, but in_to_reg() takes a u32 and
> multiplies it by 100 before clamping. Large limits can therefore wrap to
> a low register value. For example, 4294967296 mV becomes zero on a
> 64-bit system.
>
> Keep the input as an unsigned long and bound it to the register range
> before scaling.
>
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
[Severity: Low]
Since this fixes an integer truncation and overflow in in_to_reg(), should
it include a Fixes tag:
Fixes: 9de2e2e84e7d ("hwmon: Driver for Nuvoton NCT6775F, NCT6776F, and NCT6779D")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111023927.9234-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
2026-11-11 2:45 Zhu Jun
@ 2026-11-11 3:03 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-11 3:03 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] hwmon: (nct6775) missing Fixes trailer for in_to_reg() overflow
fix
--
commit 942ff78cd13ea05813c6ab30f0bbe111309ffcdb
Author: Zhu Jun <zhujun2@cmss.chinamobile.com>
> hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
>
> store_in_reg() parses an unsigned long, but in_to_reg() takes a u32 and
> multiplies it by 100 before clamping. Large limits can therefore wrap to
> a low register value. For example, 4294967296 mV becomes zero on a
> 64-bit system.
>
> Keep the input as an unsigned long and bound it to the register range
> before scaling.
>
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
[Severity: Low]
This fixes a bug in in_to_reg() where values parsed by store_in_reg()
can wrap when narrowed and scaled. Should this include:
Fixes: 9de2e2e84e7d ("hwmon: Driver for Nuvoton NCT6775F, NCT6776F, and NCT6779D")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111024524.9627-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
@ 2026-11-11 3:36 Zhu Jun
2026-11-11 3:40 ` sashiko-bot
0 siblings, 1 reply; 8+ messages in thread
From: Zhu Jun @ 2026-11-11 3:36 UTC (permalink / raw)
To: linux; +Cc: linux-hwmon, linux-kernel, Zhu Jun
store_in_reg() parses an unsigned long, but in_to_reg() takes a u32 and
multiplies it by 100 before clamping. Large limits can therefore wrap to
a low register value. For example, 4294967296 mV becomes zero on a
64-bit system.
Keep the input as an unsigned long and bound it to the register range
before scaling.
Fixes: 9de2e2e84e7d ("hwmon: Driver for Nuvoton NCT6775F, NCT6776F, and NCT6779D")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/nct6775-core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/nct6775-core.c b/drivers/hwmon/nct6775-core.c
index 6e97e4f08b90..b7c1e8ceaac9 100644
--- a/drivers/hwmon/nct6775-core.c
+++ b/drivers/hwmon/nct6775-core.c
@@ -1039,8 +1039,9 @@ static inline long in_from_reg(u8 reg, u8 nr, const u16 *scales)
return DIV_ROUND_CLOSEST(reg * scales[nr], 100);
}
-static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scales)
+static inline u8 in_to_reg(unsigned long val, u8 nr, const u16 *scales)
{
+ val = min(val, 255UL * scales[nr] / 100);
return clamp_val(DIV_ROUND_CLOSEST(val * 100, scales[nr]), 0, 255);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling
2026-11-11 3:36 Zhu Jun
@ 2026-11-11 3:40 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-11 3:40 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> store_in_reg() parses an unsigned long, but in_to_reg() takes a u32 and
> multiplies it by 100 before clamping. Large limits can therefore wrap to
> a low register value. For example, 4294967296 mV becomes zero on a
> 64-bit system.
>
> Keep the input as an unsigned long and bound it to the register range
> before scaling.
>
> Fixes: 9de2e2e84e7d ("hwmon: Driver for Nuvoton NCT6775F, NCT6776F, and NCT6779D")
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111033623.12046-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-11 3:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11 2:39 [PATCH] hwmon: (nct6775) Clamp voltage limits before narrowing and scaling Zhu Jun
2026-11-11 2:58 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-11 3:36 Zhu Jun
2026-11-11 3:40 ` sashiko-bot
2026-11-11 2:45 Zhu Jun
2026-11-11 3:03 ` sashiko-bot
2026-11-09 9:25 Zhu Jun
2026-11-09 20: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