diff options
| author | Thierry Reding <treding@nvidia.com> | 2017-11-07 13:15:59 -0500 |
|---|---|---|
| committer | Linus Walleij <linus.walleij@linaro.org> | 2017-11-08 08:24:51 -0500 |
| commit | 959bc7b22bd25a3a907fbb9b26a1d0cbdf98ef40 (patch) | |
| tree | 4fa59fb33b124369f71dc037e198775b26e08ea4 /drivers/gpio | |
| parent | 8302cf585288f75fd253f6b9a094d51ae371a3f3 (diff) | |
gpio: Automatically add lockdep keys
In order to avoid lockdep boilerplate in individual drivers, turn the
gpiochip_add_data() function into a macro that creates a unique class
key for each driver.
Note that this has the slight disadvantage of adding a key for each
driver registered with the system. However, these keys are 8 bytes in
size, which is negligible and a small price to pay for generic
infrastructure.
Suggested-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Acked-by: Grygorii Strashko <grygorii.strashko@ti.com>
[renane __gpiochip_add_data() to gpiochip_add_data_with_key]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
| -rw-r--r-- | drivers/gpio/gpiolib.c | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6d5c366a1378..961b5da38bb9 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
| @@ -72,7 +72,8 @@ static LIST_HEAD(gpio_lookup_list); | |||
| 72 | LIST_HEAD(gpio_devices); | 72 | LIST_HEAD(gpio_devices); |
| 73 | 73 | ||
| 74 | static void gpiochip_free_hogs(struct gpio_chip *chip); | 74 | static void gpiochip_free_hogs(struct gpio_chip *chip); |
| 75 | static int gpiochip_add_irqchip(struct gpio_chip *gpiochip); | 75 | static int gpiochip_add_irqchip(struct gpio_chip *gpiochip, |
| 76 | struct lock_class_key *key); | ||
| 76 | static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip); | 77 | static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip); |
| 77 | static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip); | 78 | static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip); |
| 78 | static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip); | 79 | static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip); |
| @@ -1098,30 +1099,8 @@ static void gpiochip_setup_devs(void) | |||
| 1098 | } | 1099 | } |
| 1099 | } | 1100 | } |
| 1100 | 1101 | ||
| 1101 | /** | 1102 | int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, |
| 1102 | * gpiochip_add_data() - register a gpio_chip | 1103 | struct lock_class_key *key) |
| 1103 | * @chip: the chip to register, with chip->base initialized | ||
| 1104 | * @data: driver-private data associated with this chip | ||
| 1105 | * | ||
| 1106 | * Context: potentially before irqs will work | ||
| 1107 | * | ||
| 1108 | * When gpiochip_add_data() is called very early during boot, so that GPIOs | ||
| 1109 | * can be freely used, the chip->parent device must be registered before | ||
| 1110 | * the gpio framework's arch_initcall(). Otherwise sysfs initialization | ||
| 1111 | * for GPIOs will fail rudely. | ||
| 1112 | * | ||
| 1113 | * gpiochip_add_data() must only be called after gpiolib initialization, | ||
| 1114 | * ie after core_initcall(). | ||
| 1115 | * | ||
| 1116 | * If chip->base is negative, this requests dynamic assignment of | ||
| 1117 | * a range of valid GPIOs. | ||
| 1118 | * | ||
| 1119 | * Returns: | ||
| 1120 | * A negative errno if the chip can't be registered, such as because the | ||
| 1121 | * chip->base is invalid or already associated with a different chip. | ||
| 1122 | * Otherwise it returns zero as a success code. | ||
| 1123 | */ | ||
| 1124 | int gpiochip_add_data(struct gpio_chip *chip, void *data) | ||
| 1125 | { | 1104 | { |
| 1126 | unsigned long flags; | 1105 | unsigned long flags; |
| 1127 | int status = 0; | 1106 | int status = 0; |
| @@ -1267,7 +1246,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) | |||
| 1267 | if (status) | 1246 | if (status) |
| 1268 | goto err_remove_from_list; | 1247 | goto err_remove_from_list; |
| 1269 | 1248 | ||
| 1270 | status = gpiochip_add_irqchip(chip); | 1249 | status = gpiochip_add_irqchip(chip, key); |
| 1271 | if (status) | 1250 | if (status) |
| 1272 | goto err_remove_chip; | 1251 | goto err_remove_chip; |
| 1273 | 1252 | ||
| @@ -1314,7 +1293,7 @@ err_free_gdev: | |||
| 1314 | kfree(gdev); | 1293 | kfree(gdev); |
| 1315 | return status; | 1294 | return status; |
| 1316 | } | 1295 | } |
| 1317 | EXPORT_SYMBOL_GPL(gpiochip_add_data); | 1296 | EXPORT_SYMBOL_GPL(gpiochip_add_data_with_key); |
| 1318 | 1297 | ||
| 1319 | /** | 1298 | /** |
| 1320 | * gpiochip_get_data() - get per-subdriver data for the chip | 1299 | * gpiochip_get_data() - get per-subdriver data for the chip |
| @@ -1733,8 +1712,10 @@ static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) | |||
| 1733 | /** | 1712 | /** |
| 1734 | * gpiochip_add_irqchip() - adds an IRQ chip to a GPIO chip | 1713 | * gpiochip_add_irqchip() - adds an IRQ chip to a GPIO chip |
| 1735 | * @gpiochip: the GPIO chip to add the IRQ chip to | 1714 | * @gpiochip: the GPIO chip to add the IRQ chip to |
| 1715 | * @lock_key: lockdep class | ||
| 1736 | */ | 1716 | */ |
| 1737 | static int gpiochip_add_irqchip(struct gpio_chip *gpiochip) | 1717 | static int gpiochip_add_irqchip(struct gpio_chip *gpiochip, |
| 1718 | struct lock_class_key *lock_key) | ||
| 1738 | { | 1719 | { |
| 1739 | struct irq_chip *irqchip = gpiochip->irq.chip; | 1720 | struct irq_chip *irqchip = gpiochip->irq.chip; |
| 1740 | const struct irq_domain_ops *ops; | 1721 | const struct irq_domain_ops *ops; |
| @@ -1771,6 +1752,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip) | |||
| 1771 | 1752 | ||
| 1772 | gpiochip->to_irq = gpiochip_to_irq; | 1753 | gpiochip->to_irq = gpiochip_to_irq; |
| 1773 | gpiochip->irq.default_type = type; | 1754 | gpiochip->irq.default_type = type; |
| 1755 | gpiochip->irq.lock_key = lock_key; | ||
| 1774 | 1756 | ||
| 1775 | if (gpiochip->irq.domain_ops) | 1757 | if (gpiochip->irq.domain_ops) |
| 1776 | ops = gpiochip->irq.domain_ops; | 1758 | ops = gpiochip->irq.domain_ops; |
| @@ -1957,7 +1939,8 @@ EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_key); | |||
| 1957 | 1939 | ||
| 1958 | #else /* CONFIG_GPIOLIB_IRQCHIP */ | 1940 | #else /* CONFIG_GPIOLIB_IRQCHIP */ |
| 1959 | 1941 | ||
| 1960 | static inline int gpiochip_add_irqchip(struct gpio_chip *gpiochip) | 1942 | static inline int gpiochip_add_irqchip(struct gpio_chip *gpiochip, |
| 1943 | struct lock_dep_class *lock_key) | ||
| 1961 | { | 1944 | { |
| 1962 | return 0; | 1945 | return 0; |
| 1963 | } | 1946 | } |
