Skip to content

Commit 1559d14

Browse files
author
Bartosz Golaszewski
committed
gpiolib: provide gpio_device_to_device()
There are users in the kernel who need to retrieve the address of the struct device backing the GPIO device. Currently they needlessly poke in the internals of GPIOLIB. Add a dedicated getter function. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Peter Rosin <peda@axentia.se> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Acked-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 4f3b436 commit 1559d14

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

drivers/gpio/gpiolib.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,23 @@ void gpio_device_put(struct gpio_device *gdev)
11891189
}
11901190
EXPORT_SYMBOL_GPL(gpio_device_put);
11911191

1192+
/**
1193+
* gpio_device_to_device() - Retrieve the address of the underlying struct
1194+
* device.
1195+
* @gdev: GPIO device for which to return the address.
1196+
*
1197+
* This does not increase the reference count of the GPIO device nor the
1198+
* underlying struct device.
1199+
*
1200+
* Returns:
1201+
* Address of struct device backing this GPIO device.
1202+
*/
1203+
struct device *gpio_device_to_device(struct gpio_device *gdev)
1204+
{
1205+
return &gdev->dev;
1206+
}
1207+
EXPORT_SYMBOL_GPL(gpio_device_to_device);
1208+
11921209
#ifdef CONFIG_GPIOLIB_IRQCHIP
11931210

11941211
/*

include/linux/gpio/driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ void gpio_device_put(struct gpio_device *gdev);
619619
DEFINE_FREE(gpio_device_put, struct gpio_device *,
620620
if (IS_ERR_OR_NULL(_T)) gpio_device_put(_T));
621621

622+
struct device *gpio_device_to_device(struct gpio_device *gdev);
623+
622624
bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset);
623625
int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset);
624626
void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset);

0 commit comments

Comments
 (0)