Re: [PATCH 1/2] gpio: provide gpiod_is_equal()
From: Bartosz Golaszewski
Date: Wed Apr 09 2025 - 13:04:42 EST
On Wed, Apr 9, 2025 at 4:32 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxx> wrote:
>
> On Mon, Apr 07, 2025 at 09:08:14AM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
> >
> > There are users in the kernel that directly compare raw GPIO descriptor
> > pointers in order to determine whether they refer to the same physical
> > GPIO pin. This accidentally works like this but is not guaranteed by any
> > API contract. Let's provide a comparator function that hides the actual
> > logic.
>
> ...
>
> > +bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other)
> > +{
> > + return desc == other;
>
> I think it's better to have the one checked against NULL. That's how
> comparators make more sense, see, for example, 1b1bb7b29b10 ("drivers:
> base: Don't match devices with NULL of_node/fwnode/etc").
>
Yeah I guess it can be improved in a follow-up.
> Ideally it should be IS_ERR_OR_NULL(), but we have here a principal disagreement,
> so this might be yet another (buggy) function in GPIOLIB.
>
Our disagreement has nothing to do with this. In fact validating
against IS_ERR() (and returning false) makes more sense than just
accepting IS_ERR() in acting like it's a valid descriptor.
I will send a follow-up tomorrow.
Bartosz