From: sashiko-bot@kernel.org
To: "Ninad Naik" <ninadnaik07@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 2/3] hwmon: lm93: Change unsigned to unsigned int for clarity
Date: Thu, 07 May 2026 21:11:07 +0000 [thread overview]
Message-ID: <20260507211108.62D73C2BCB2@smtp.kernel.org> (raw)
In-Reply-To: <20260507101143.559475-3-ninadnaik07@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Broken arithmetic and unsigned underflow in `LM93_IN_REL_TO_REG` completely breaks relative voltage limit configuration.
--
commit d027c76dfc6bdf77f6a91f44199f1d10dda57fdd
Author: Ninad Naik <ninadnaik07@gmail.com>
hwmon: lm93: Change unsigned to unsigned int for clarity
This commit fixes checkpatch.pl warnings by changing unsigned to unsigned int
for clarity and to follow the latest kernel code style.
> diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c
> index c15e2a02dd86a..1a3b5da924b2e 100644
> --- a/drivers/hwmon/lm93.c
> +++ b/drivers/hwmon/lm93.c
[ ... ]
> @@ -396,7 +396,7 @@ static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid)
> * upper also determines which nibble of the register is returned
> * (the other nibble will be 0x0)
> */
> -static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid)
> +static u8 LM93_IN_REL_TO_REG(unsigned int val, int upper, int vid)
> {
> long uv_offset = vid * 1000 - val * 10000;
This isn't a regression introduced by this patch, but does this calculation
cause an unsigned underflow?
Because val is an unsigned int, the operation vid * 1000 - val * 10000 is
evaluated as unsigned. For an upper limit, the limit (val * 10000) is
typically greater than the voltage (vid * 1000), causing the subtraction to
wrap around to a large positive value.
On 64-bit systems, assigning this to long uv_offset zero-extends it. The
function then executes clamp_val(uv_offset, 12500, 200000). Because the
underflowed value is massive, it is clamped to the maximum bound (200000).
On 32-bit systems, the huge unsigned value is reinterpreted as negative and
clamped to the minimum bound (12500). For lower limits, the inverted
subtraction yields a positive value, which is then clamped against a
negative range (-400000 to -25000), forcing it to -25000.
Also, does the formula subtract in the wrong order? To correctly invert the
logic of LM93_IN_REL_FROM_REG (which computes
val = (vid * 1000 + uv_offset + 5000) / 10000), should the offset be
calculated as uv_offset = val * 10000 - vid * 1000?
Lastly, since the unbounded user input val is multiplied by 10000 prior to
any bounds checking, can large inputs silently overflow the 32-bit unsigned
integer?
Could these arithmetic regressions cause writes to the in_min or in_max
sysfs attributes for channels 6 and 7 to misconfigure the hardware
monitoring bounds, potentially masking important voltage alarms?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260507101143.559475-1-ninadnaik07@gmail.com?part=2
next prev parent reply other threads:[~2026-05-07 21:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 10:11 [PATCH 0/3] hwmon: lm93: clean up coding style issues Ninad Naik
2026-05-07 10:11 ` [PATCH 1/3] hwmon: lm93: Add missing blank lines after declarations Ninad Naik
2026-05-07 10:11 ` [PATCH 2/3] hwmon: lm93: Change unsigned to unsigned int for clarity Ninad Naik
2026-05-07 21:11 ` sashiko-bot [this message]
2026-05-07 10:11 ` [PATCH 3/3] hwmon: lm93: Remove else blocks after break or return for consistency Ninad Naik
2026-05-08 16:27 ` [PATCH 0/3] hwmon: lm93: clean up coding style issues Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260507211108.62D73C2BCB2@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=ninadnaik07@gmail.com \
--cc=sashiko@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox