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

Configure Feed

Select the types of activity you want to include in your feed.

gpiolib: provide gpiod_to_gpio_device()

Accessing struct gpio_chip backing a GPIO device is only allowed for the
actual providers of that chip.

Similarly to how we introduced gpio_device_find() in order to replace
the abused gpiochip_find(), let's introduce a counterpart to
gpiod_to_chip() that returns a reference to the GPIO device owning the
descriptor. This is done in order to later remove gpiod_to_chip()
entirely.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Peter Rosin <peda@axentia.se>
Acked-by: Linus Walleij <linus.walleij@linaro.org>

+22
+21
drivers/gpio/gpiolib.c
··· 221 221 EXPORT_SYMBOL_GPL(gpiod_to_chip); 222 222 223 223 /** 224 + * gpiod_to_gpio_device() - Return the GPIO device to which this descriptor 225 + * belongs. 226 + * @desc: Descriptor for which to return the GPIO device. 227 + * 228 + * This *DOES NOT* increase the reference count of the GPIO device as it's 229 + * expected that the descriptor is requested and the users already holds a 230 + * reference to the device. 231 + * 232 + * Returns: 233 + * Address of the GPIO device owning this descriptor. 234 + */ 235 + struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc) 236 + { 237 + if (!desc) 238 + return NULL; 239 + 240 + return desc->gdev; 241 + } 242 + EXPORT_SYMBOL_GPL(gpiod_to_gpio_device); 243 + 244 + /** 224 245 * gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device 225 246 * @gdev: GPIO device 226 247 *
+1
include/linux/gpio/driver.h
··· 785 785 void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset); 786 786 787 787 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 788 + struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc); 788 789 789 790 #else /* CONFIG_GPIOLIB */ 790 791