summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2025-04-09 17:51:31 +0100
committerMark Brown <broonie@kernel.org>2025-04-09 17:51:31 +0100
commit36ddc9ec8f3ec00eb4c88631807d02f96e05c0e7 (patch)
tree8c6b9859d4aae29bf88eabf9d6ebb9cedb85adb3 /drivers
parent4a7c28e659b85c96ebc87ad00d11c47a538dc15e (diff)
parentaaf6223ea2a1ff9316a81bf851fd5a0e82635b60 (diff)
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().
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/gpiolib.c14
-rw-r--r--drivers/regulator/core.c2
2 files changed, 15 insertions, 1 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b8197502a5ac..2e5b6982e76d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -266,6 +266,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
*
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 90629a756693..7a248dc8d2e2 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -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;
}