Skip to content

Commit 3b7c747

Browse files
andy-shevBartosz Golaszewski
authored andcommitted
gpiolib: Provide to_gpio_device() helper
Provide to_gpio_device() helper which can be utilized in the existing and future code. While at it, make sure it becomes no-op at compilation time. Signed-off-by: Andy Shevchenko <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 4ef339b commit 3b7c747

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

drivers/gpio/gpiolib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ EXPORT_SYMBOL_GPL(gpiochip_line_is_valid);
549549

550550
static void gpiodevice_release(struct device *dev)
551551
{
552-
struct gpio_device *gdev = container_of(dev, struct gpio_device, dev);
552+
struct gpio_device *gdev = to_gpio_device(dev);
553553
unsigned long flags;
554554

555555
spin_lock_irqsave(&gpio_lock, flags);

drivers/gpio/gpiolib.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
/**
2222
* struct gpio_device - internal state container for GPIO devices
23-
* @id: numerical ID number for the GPIO chip
2423
* @dev: the GPIO device struct
2524
* @chrdev: character device for the GPIO device
25+
* @id: numerical ID number for the GPIO chip
2626
* @mockdev: class device used by the deprecated sysfs interface (may be
2727
* NULL)
2828
* @owner: helps prevent removal of modules exporting active GPIOs
@@ -47,9 +47,9 @@
4747
* userspace.
4848
*/
4949
struct gpio_device {
50-
int id;
5150
struct device dev;
5251
struct cdev chrdev;
52+
int id;
5353
struct device *mockdev;
5454
struct module *owner;
5555
struct gpio_chip *chip;
@@ -72,6 +72,11 @@ struct gpio_device {
7272
#endif
7373
};
7474

75+
static inline struct gpio_device *to_gpio_device(struct device *dev)
76+
{
77+
return container_of(dev, struct gpio_device, dev);
78+
}
79+
7580
/* gpio suffixes used for ACPI and device tree lookup */
7681
static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
7782

0 commit comments

Comments
 (0)