From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-gpio@vger.kernel.org, Bartosz Golaszewski <brgl@bgdev.pl>,
Linus Walleij <linus.walleij@linaro.org>,
Mika Westerberg <westeri@kernel.org>
Subject: Re: [PATCH 18/44] drivers/gpio: use min() instead of min_t()
Date: Tue, 25 Nov 2025 11:55:51 +0200 [thread overview]
Message-ID: <aSV9JxrZdJZNhSL4@smile.fi.intel.com> (raw)
In-Reply-To: <20251120093743.1cf9bb8f@pumpkin>
On Thu, Nov 20, 2025 at 09:37:43AM +0000, David Laight wrote:
> On Thu, 20 Nov 2025 10:01:29 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > On Wed, Nov 19, 2025 at 10:41:14PM +0000, david.laight.linux@gmail.com wrote:
> > >
> > > min_t(u16, a, b) casts an 'unsigned long' to 'u16'.
> > > Use min(a, b) instead as it promotes the both values to int
> > > and so cannot discard significant bits.
> > >
> > > In this case the values should be ok.
> > >
> > > Detected by an extra check added to min_t().
...
> > > acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
> >
> > > - length = min_t(u16, agpio->pin_table_length, pin_index + bits);
> > > + length = min(agpio->pin_table_length, pin_index + bits);
> >
> > Now, if you look closer at the code, the pin_index alone has the problem you
> > are targeting here.
>
> The compiler warning happens because 'pin_index + bits' is 'int' and the compiler
> doesn't know the value fits in 16 bits.
> It should fit, but only if the caller passes in valid data.
I meant that assignment to pin_index already cuts the higher bits
from the input.
> > On top of that the iterator and 'length' are signed, while
> > the result of min_t(u16) is unsigned (however it has no difference in this case).
>
> Actually the result type of min_t(u16) is 'int' (:? promotes char/short to int).
> So the u16 cast does '(pin_index + bits) & 0xffff', everything is then promoted
> to 'int' for all the comparisons (etc).
Sure, but the value is positive even if int is signed. That's why I put
a remark in the parentheses that it has no difference in this case.
...
> > TL;DR: I apply this patch with subject changed, but I think more work needs to
> > be done if you want to fix it fully.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-11-25 9:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 22:40 [PATCH 00/44] Change a lot of min_t() that might mask high bits david.laight.linux
2025-11-19 22:41 ` [PATCH 18/44] drivers/gpio: use min() instead of min_t() david.laight.linux
2025-11-20 8:01 ` Andy Shevchenko
2025-11-20 9:37 ` David Laight
2025-11-25 9:55 ` Andy Shevchenko [this message]
2025-11-20 1:47 ` [PATCH 00/44] Change a lot of min_t() that might mask high bits Jakub Kicinski
2025-11-20 9:38 ` Lorenzo Stoakes
2025-11-20 14:52 ` (subset) " Jens Axboe
2025-11-24 9:49 ` Herbert Xu
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=aSV9JxrZdJZNhSL4@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=brgl@bgdev.pl \
--cc=david.laight.linux@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=westeri@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;
as well as URLs for NNTP newsgroup(s).