On 2/8/24 00:12, Nuno Sá wrote:
On Wed, 2024-02-07 at 08:49 -0800, Guenter Roeck wrote:
On 2/7/24 02:19, Nuno Sá wrote:
Hi Dan,
On Wed, 2024-02-07 at 12:51 +0300, Dan Carpenter wrote:
Hello Nuno Sa,
The patch 848a5019ded5: "hwmon: ltc4282: add support for the LTC4282
chip" from Jan 29, 2024 (linux-next), leads to the following Smatch
static checker warning:
drivers/hwmon/ltc4282.c:732 ltc4282_write_voltage_byte_cached()
warn: no lower bound on 'val' rl='s64min-4294967294'
drivers/hwmon/ltc4282.c
723 static int ltc4282_write_voltage_byte_cached(const struct
ltc4282_state *st,
724 u32 reg, u32 fs,
long
val,
725 u32 *cache_raw)
726 {
727 u32 in;
728
729 if (val >= fs)
730 in = U8_MAX;
731 else
--> 732 in = DIV_ROUND_CLOSEST(val * U8_MAX, fs);
Yeah, I guess we should likely clamp it between 0 and fs
val = clamp_val(val, 0, fs);
in = DIV_ROUND_CLOSEST(val * U8_MAX, fs);
maybe.
Should I fix that inline or do you want to send a follow-up patch ?
Guenter
Whatever makes your life easier... I can send a patch if that is your
preference.
I updated the original patch.
Thanks,
Guenter