Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+24 -1
+14
drivers/gpio/gpiolib.c
··· 266 266 EXPORT_SYMBOL_GPL(gpiod_to_gpio_device); 267 267 268 268 /** 269 + * gpiod_is_equal() - Check if two GPIO descriptors refer to the same pin. 270 + * @desc: Descriptor to compare. 271 + * @other: The second descriptor to compare against. 272 + * 273 + * Returns: 274 + * True if the descriptors refer to the same physical pin. False otherwise. 275 + */ 276 + bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other) 277 + { 278 + return desc == other; 279 + } 280 + EXPORT_SYMBOL_GPL(gpiod_is_equal); 281 + 282 + /** 269 283 * gpio_device_get_base() - Get the base GPIO number allocated by this device 270 284 * @gdev: GPIO device 271 285 *
+1 -1
drivers/regulator/core.c
··· 2617 2617 mutex_lock(&regulator_list_mutex); 2618 2618 2619 2619 list_for_each_entry(pin, &regulator_ena_gpio_list, list) { 2620 - if (pin->gpiod == gpiod) { 2620 + if (gpiod_is_equal(pin->gpiod, gpiod)) { 2621 2621 rdev_dbg(rdev, "GPIO is already used\n"); 2622 2622 goto update_ena_gpio_to_rdev; 2623 2623 }
+9
include/linux/gpio/consumer.h
··· 180 180 enum gpiod_flags flags, 181 181 const char *label); 182 182 183 + bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other); 184 + 183 185 #else /* CONFIG_GPIOLIB */ 184 186 185 187 #include <linux/bug.h> ··· 547 545 const char *label) 548 546 { 549 547 return ERR_PTR(-ENOSYS); 548 + } 549 + 550 + static inline bool 551 + gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other) 552 + { 553 + WARN_ON(desc || other); 554 + return false; 550 555 } 551 556 552 557 #endif /* CONFIG_GPIOLIB */