Re: [PATCH 1/2] gpio: provide gpiod_is_equal()

From: Andy Shevchenko
Date: Wed Apr 09 2025 - 10:32:57 EST


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").

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.

> +}

--
With Best Regards,
Andy Shevchenko