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 /include/linux/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 'include/linux/gpio')
| -rw-r--r-- | include/linux/gpio/driver.h | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index a77d4ada060c..8dd282c5167a 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h | |||
| @@ -321,7 +321,41 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip, | |||
| 321 | unsigned offset); | 321 | unsigned offset); |
| 322 | 322 | ||
| 323 | /* add/remove chips */ | 323 | /* add/remove chips */ |
| 324 | extern int gpiochip_add_data(struct gpio_chip *chip, void *data); | 324 | extern int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, |
| 325 | struct lock_class_key *lock_key); | ||
| 326 | |||
| 327 | /** | ||
| 328 | * gpiochip_add_data() - register a gpio_chip | ||
| 329 | * @chip: the chip to register, with chip->base initialized | ||
| 330 | * @data: driver-private data associated with this chip | ||
| 331 | * | ||
| 332 | * Context: potentially before irqs will work | ||
| 333 | * | ||
| 334 | * When gpiochip_add_data() is called very early during boot, so that GPIOs | ||
| 335 | * can be freely used, the chip->parent device must be registered before | ||
| 336 | * the gpio framework's arch_initcall(). Otherwise sysfs initialization | ||
| 337 | * for GPIOs will fail rudely. | ||
| 338 | * | ||
| 339 | * gpiochip_add_data() must only be called after gpiolib initialization, | ||
| 340 | * ie after core_initcall(). | ||
| 341 | * | ||
| 342 | * If chip->base is negative, this requests dynamic assignment of | ||
| 343 | * a range of valid GPIOs. | ||
| 344 | * | ||
| 345 | * Returns: | ||
| 346 | * A negative errno if the chip can't be registered, such as because the | ||
| 347 | * chip->base is invalid or already associated with a different chip. | ||
| 348 | * Otherwise it returns zero as a success code. | ||
| 349 | */ | ||
| 350 | #ifdef CONFIG_LOCKDEP | ||
| 351 | #define gpiochip_add_data(chip, data) ({ \ | ||
| 352 | static struct lock_class_key key; \ | ||
| 353 | gpiochip_add_data_with_key(chip, data, &key); \ | ||
| 354 | }) | ||
| 355 | #else | ||
| 356 | #define gpiochip_add_data(chip, data) gpiochip_add_data_with_key(chip, data, NULL) | ||
| 357 | #endif | ||
| 358 | |||
| 325 | static inline int gpiochip_add(struct gpio_chip *chip) | 359 | static inline int gpiochip_add(struct gpio_chip *chip) |
| 326 | { | 360 | { |
| 327 | return gpiochip_add_data(chip, NULL); | 361 | return gpiochip_add_data(chip, NULL); |
