gpio: don't compare raw GPIO descriptor pointers

Merge series from Bartosz Golaszewski <brgl@bgdev.pl>:

Handling of shared GPIOs in the kernel needs some improvements. Let's
start with a simple change of not comparing GPIO descriptor pointers
directly as there's nothing that guarantees that the same physical pin
will always be represented by a single GPIO descriptor obtained by
calling gpiod_get().
This commit is contained in:
Mark Brown 2025-04-09 17:51:31 +01:00
commit 36ddc9ec8f
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
3 changed files with 24 additions and 1 deletions

View File

@ -265,6 +265,20 @@ struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc)
}
EXPORT_SYMBOL_GPL(gpiod_to_gpio_device);
/**
* gpiod_is_equal() - Check if two GPIO descriptors refer to the same pin.
* @desc: Descriptor to compare.
* @other: The second descriptor to compare against.
*
* Returns:
* True if the descriptors refer to the same physical pin. False otherwise.
*/
bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other)
{
return desc == other;
}
EXPORT_SYMBOL_GPL(gpiod_is_equal);
/**
* gpio_device_get_base() - Get the base GPIO number allocated by this device
* @gdev: GPIO device

View File

@ -2617,7 +2617,7 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
mutex_lock(&regulator_list_mutex);
list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
if (pin->gpiod == gpiod) {
if (gpiod_is_equal(pin->gpiod, gpiod)) {
rdev_dbg(rdev, "GPIO is already used\n");
goto update_ena_gpio_to_rdev;
}

View File

@ -180,6 +180,8 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
enum gpiod_flags flags,
const char *label);
bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other);
#else /* CONFIG_GPIOLIB */
#include <linux/bug.h>
@ -547,6 +549,13 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
return ERR_PTR(-ENOSYS);
}
static inline bool
gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other)
{
WARN_ON(desc || other);
return false;
}
#endif /* CONFIG_GPIOLIB */
#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_HTE)