From: David Laight <david.laight.linux@gmail.com>
To: "Pradhan, Sanman" <sanman.pradhan@hpe.com>
Cc: "linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
"linux@roeck-us.net" <linux@roeck-us.net>,
"linux@weissschuh.net" <linux@weissschuh.net>,
"cosmo.chou@quantatw.com" <cosmo.chou@quantatw.com>,
"mail@carsten-spiess.de" <mail@carsten-spiess.de>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
Sanman Pradhan <psanman@juniper.net>
Subject: Re: [PATCH v2 2/3] hwmon: (isl28022) Fix integer overflow in power calculation on 32-bit
Date: Wed, 8 Apr 2026 09:42:19 +0100 [thread overview]
Message-ID: <20260408094219.3aaa4ad2@pumpkin> (raw)
In-Reply-To: <20260407212122.278824-1-sanman.pradhan@hpe.com>
On Tue, 7 Apr 2026 21:21:31 +0000
"Pradhan, Sanman" <sanman.pradhan@hpe.com> wrote:
> From: Sanman Pradhan <psanman@juniper.net>
>
> Thanks for the review.
>
> Yes, I checked this.
>
> In this driver, gain is limited to {1, 2, 4, 8} by
> isl28022_read_properties(), and regval is a 16-bit register value
> (max 65535). The worst-case numerator is:
>
> 51200000 * 8 * 65535 = 26843136000000
>
> which is well below U64_MAX, so the multiply cannot overflow.
>
> I'll switch to min_t(u64, ...) here to make the type handling explicit
> for the u64 result of div_u64(), if that's ok, and send a v3.
No, use min() not min_t().
min_t() doesn't make the type handling 'explicit', it just casts both
values to the specified type and lets you live with any consequences.
min() attempts to stop you doing 'really silly thing' (mostly trying
to stop negative signed values becoming very large signed values).
Even if the compiler generates a signedness warning from min()
replacing it with min_t() really ought to be a last resort.
Not the least of the problems is that people have a habit of using
the type they want for the result, so you'll find:
x = clamp_t(u8, y, 0, 255);
That is just:
x = clamp((u8)y, (u8)0, (u8)255);
which just masks the high bits instead of the intended saturation.
David
>
> Thank you.
>
> Regards,
> Sanman Pradhan
next prev parent reply other threads:[~2026-04-08 8:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 17:37 [PATCH v2 0/3] hwmon: Fix bugs in pt5161l, isl28022, and powerz Pradhan, Sanman
2026-04-07 17:37 ` [PATCH v2 1/3] hwmon: (pt5161l) Fix bugs in pt5161l_read_block_data() Pradhan, Sanman
2026-04-07 17:38 ` [PATCH v2 2/3] hwmon: (isl28022) Fix integer overflow in power calculation on 32-bit Pradhan, Sanman
2026-04-07 19:21 ` David Laight
2026-04-07 21:21 ` Pradhan, Sanman
2026-04-08 8:42 ` David Laight [this message]
2026-04-07 17:38 ` [PATCH v2 3/3] hwmon: (powerz) Fix use-after-free and signal handling on USB disconnect Pradhan, Sanman
2026-04-07 21:22 ` Pradhan, Sanman
2026-04-07 23:38 ` 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=20260408094219.3aaa4ad2@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=cosmo.chou@quantatw.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=linux@weissschuh.net \
--cc=mail@carsten-spiess.de \
--cc=psanman@juniper.net \
--cc=sanman.pradhan@hpe.com \
--cc=stable@vger.kernel.org \
/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