Skip to content

Commit 5f402bb

Browse files
a3flinusw
authored andcommitted
gpio: don't use same lockdep class for all devm_gpiochip_add_data users
Commit 959bc7b ("gpio: Automatically add lockdep keys") documents in its commits message its intention to "create a unique class key for each driver". It does so by having gpiochip_add_data add in-place the definition of two static lockdep classes for LOCKDEP use. That way, every caller of the macro adds their gpiochip with unique lockdep classes. There are many indirect callers of gpiochip_add_data, however, via use of devm_gpiochip_add_data. devm_gpiochip_add_data has external linkage and all its users will share the same lockdep classes, which probably is not intended. Fix this by replicating the gpio_chip_add_data statics-in-macro for the devm_ version as well. Fixes: 959bc7b ("gpio: Automatically add lockdep keys") Signed-off-by: Ahmad Fatoum <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Bartosz Golaszewski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent bb58a47 commit 5f402bb

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

drivers/gpio/gpiolib-devres.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,12 @@ static void devm_gpio_chip_release(struct device *dev, void *res)
487487
}
488488

489489
/**
490-
* devm_gpiochip_add_data() - Resource managed gpiochip_add_data()
490+
* devm_gpiochip_add_data_with_key() - Resource managed gpiochip_add_data_with_key()
491491
* @dev: pointer to the device that gpio_chip belongs to.
492492
* @gc: the GPIO chip to register
493493
* @data: driver-private data associated with this chip
494+
* @lock_key: lockdep class for IRQ lock
495+
* @request_key: lockdep class for IRQ request
494496
*
495497
* Context: potentially before irqs will work
496498
*
@@ -501,8 +503,9 @@ static void devm_gpio_chip_release(struct device *dev, void *res)
501503
* gc->base is invalid or already associated with a different chip.
502504
* Otherwise it returns zero as a success code.
503505
*/
504-
int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc,
505-
void *data)
506+
int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, void *data,
507+
struct lock_class_key *lock_key,
508+
struct lock_class_key *request_key)
506509
{
507510
struct gpio_chip **ptr;
508511
int ret;
@@ -512,7 +515,7 @@ int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc,
512515
if (!ptr)
513516
return -ENOMEM;
514517

515-
ret = gpiochip_add_data(gc, data);
518+
ret = gpiochip_add_data_with_key(gc, data, lock_key, request_key);
516519
if (ret < 0) {
517520
devres_free(ptr);
518521
return ret;
@@ -523,4 +526,4 @@ int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc,
523526

524527
return 0;
525528
}
526-
EXPORT_SYMBOL_GPL(devm_gpiochip_add_data);
529+
EXPORT_SYMBOL_GPL(devm_gpiochip_add_data_with_key);

include/linux/gpio/driver.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,26 @@ extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
525525
gpiochip_add_data_with_key(gc, data, &lock_key, \
526526
&request_key); \
527527
})
528+
#define devm_gpiochip_add_data(dev, gc, data) ({ \
529+
static struct lock_class_key lock_key; \
530+
static struct lock_class_key request_key; \
531+
devm_gpiochip_add_data_with_key(dev, gc, data, &lock_key, \
532+
&request_key); \
533+
})
528534
#else
529535
#define gpiochip_add_data(gc, data) gpiochip_add_data_with_key(gc, data, NULL, NULL)
536+
#define devm_gpiochip_add_data(dev, gc, data) \
537+
devm_gpiochip_add_data_with_key(dev, gc, data, NULL, NULL)
530538
#endif /* CONFIG_LOCKDEP */
531539

532540
static inline int gpiochip_add(struct gpio_chip *gc)
533541
{
534542
return gpiochip_add_data(gc, NULL);
535543
}
536544
extern void gpiochip_remove(struct gpio_chip *gc);
537-
extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc,
538-
void *data);
545+
extern int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, void *data,
546+
struct lock_class_key *lock_key,
547+
struct lock_class_key *request_key);
539548

540549
extern struct gpio_chip *gpiochip_find(void *data,
541550
int (*match)(struct gpio_chip *gc, void *data));

0 commit comments

Comments
 (0)