[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251120093743.1cf9bb8f@pumpkin>
Date: Thu, 20 Nov 2025 09:37:43 +0000
From: David Laight <david.laight.linux@...il.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: linux-kernel@...r.kernel.org, linux-acpi@...r.kernel.org,
linux-gpio@...r.kernel.org, Bartosz Golaszewski <brgl@...ev.pl>, Linus
Walleij <linus.walleij@...aro.org>, Mika Westerberg <westeri@...nel.org>
Subject: Re: [PATCH 18/44] drivers/gpio: use min() instead of min_t()
On Thu, 20 Nov 2025 10:01:29 +0200
Andy Shevchenko <andriy.shevchenko@...ux.intel.com> wrote:
> On Wed, Nov 19, 2025 at 10:41:14PM +0000, david.laight.linux@...il.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().
>
> In most of the patches you need to follow the commonly used Subject prefix.
> This can be done by doing
I did look up quite a few files to see what had been used previously.
But it is a bit tedious with 44 patches.
> git log --oneline --no-merges -- $FILE(S)_OF_INTEREST
I wasn't aware of that spell :-)
...
>
> > 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.
> 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).
David
>
> ...
>
> 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.
>
Powered by blists - more mailing lists