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

gpio: move the subdriver data pointer into gpio_device

We move to manage this pointer under gpiolib control rather than
leave it in the subdevice's gpio_chip. We can not NULL it after
gpiochip_remove so at to keep things tight.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+18 -8
+15 -2
drivers/gpio/gpiolib.c
··· 480 480 goto err_free_gdev; 481 481 } 482 482 gdev->ngpio = chip->ngpio; 483 - /* FIXME: move driver data into gpio_device dev_set_drvdata() */ 484 - chip->data = data; 483 + gdev->data = data; 485 484 486 485 spin_lock_irqsave(&gpio_lock, flags); 487 486 ··· 602 603 EXPORT_SYMBOL_GPL(gpiochip_add_data); 603 604 604 605 /** 606 + * gpiochip_get_data() - get per-subdriver data for the chip 607 + */ 608 + void *gpiochip_get_data(struct gpio_chip *chip) 609 + { 610 + return chip->gpiodev->data; 611 + } 612 + EXPORT_SYMBOL_GPL(gpiochip_get_data); 613 + 614 + /** 605 615 * gpiochip_remove() - unregister a gpio_chip 606 616 * @chip: the chip to unregister 607 617 * ··· 634 626 gpiochip_remove_pin_ranges(chip); 635 627 gpiochip_free_hogs(chip); 636 628 of_gpiochip_remove(chip); 629 + /* 630 + * We accept no more calls into the driver from this point, so 631 + * NULL the driver data pointer 632 + */ 633 + gdev->data = NULL; 637 634 638 635 spin_lock_irqsave(&gpio_lock, flags); 639 636 for (i = 0; i < gdev->ngpio; i++) {
+2
drivers/gpio/gpiolib.h
··· 37 37 * of the @descs array. 38 38 * @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned 39 39 * at device creation time. 40 + * @data: per-instance data assigned by the driver 40 41 * @list: links gpio_device:s together for traversal 41 42 * 42 43 * This state container holds most of the runtime variable data ··· 55 54 struct gpio_desc *descs; 56 55 int base; 57 56 u16 ngpio; 57 + void *data; 58 58 struct list_head list; 59 59 60 60 #ifdef CONFIG_PINCTRL
+1 -6
include/linux/gpio/driver.h
··· 25 25 * @gpiodev: the internal state holder, opaque struct 26 26 * @parent: optional parent device providing the GPIOs 27 27 * @owner: helps prevent removal of modules exporting active GPIOs 28 - * @data: per-instance data assigned by the driver 29 28 * @request: optional hook for chip-specific activation, such as 30 29 * enabling module power and clock; may sleep 31 30 * @free: optional hook for chip-specific deactivation, such as ··· 108 109 struct gpio_device *gpiodev; 109 110 struct device *parent; 110 111 struct module *owner; 111 - void *data; 112 112 113 113 int (*request)(struct gpio_chip *chip, 114 114 unsigned offset); ··· 200 202 bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset); 201 203 202 204 /* get driver data */ 203 - static inline void *gpiochip_get_data(struct gpio_chip *chip) 204 - { 205 - return chip->data; 206 - } 205 + void *gpiochip_get_data(struct gpio_chip *chip); 207 206 208 207 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 209 208