Skip to content

Commit 8a5b477

Browse files
author
Bartosz Golaszewski
committed
gpio: add the can_sleep flag to struct gpio_device
Duplicating the can_sleep value in GPIO device will allow us to not needlessly dereference the chip pointer in several places and reduce the number of SRCU read-only critical sections. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Acked-by: Andy Shevchenko <[email protected]>
1 parent c5cf334 commit 8a5b477

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

drivers/gpio/gpiolib.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
901901
}
902902

903903
gdev->ngpio = gc->ngpio;
904+
gdev->can_sleep = gc->can_sleep;
904905

905906
scoped_guard(mutex, &gpio_devices_lock) {
906907
/*
@@ -3072,7 +3073,7 @@ int gpiod_get_raw_value(const struct gpio_desc *desc)
30723073
{
30733074
VALIDATE_DESC(desc);
30743075
/* Should be using gpiod_get_raw_value_cansleep() */
3075-
WARN_ON(desc->gdev->chip->can_sleep);
3076+
WARN_ON(desc->gdev->can_sleep);
30763077
return gpiod_get_raw_value_commit(desc);
30773078
}
30783079
EXPORT_SYMBOL_GPL(gpiod_get_raw_value);
@@ -3093,7 +3094,7 @@ int gpiod_get_value(const struct gpio_desc *desc)
30933094

30943095
VALIDATE_DESC(desc);
30953096
/* Should be using gpiod_get_value_cansleep() */
3096-
WARN_ON(desc->gdev->chip->can_sleep);
3097+
WARN_ON(desc->gdev->can_sleep);
30973098

30983099
value = gpiod_get_raw_value_commit(desc);
30993100
if (value < 0)
@@ -3366,7 +3367,7 @@ void gpiod_set_raw_value(struct gpio_desc *desc, int value)
33663367
{
33673368
VALIDATE_DESC_VOID(desc);
33683369
/* Should be using gpiod_set_raw_value_cansleep() */
3369-
WARN_ON(desc->gdev->chip->can_sleep);
3370+
WARN_ON(desc->gdev->can_sleep);
33703371
gpiod_set_raw_value_commit(desc, value);
33713372
}
33723373
EXPORT_SYMBOL_GPL(gpiod_set_raw_value);
@@ -3407,7 +3408,7 @@ void gpiod_set_value(struct gpio_desc *desc, int value)
34073408
{
34083409
VALIDATE_DESC_VOID(desc);
34093410
/* Should be using gpiod_set_value_cansleep() */
3410-
WARN_ON(desc->gdev->chip->can_sleep);
3411+
WARN_ON(desc->gdev->can_sleep);
34113412
gpiod_set_value_nocheck(desc, value);
34123413
}
34133414
EXPORT_SYMBOL_GPL(gpiod_set_value);
@@ -3471,7 +3472,7 @@ EXPORT_SYMBOL_GPL(gpiod_set_array_value);
34713472
int gpiod_cansleep(const struct gpio_desc *desc)
34723473
{
34733474
VALIDATE_DESC(desc);
3474-
return desc->gdev->chip->can_sleep;
3475+
return desc->gdev->can_sleep;
34753476
}
34763477
EXPORT_SYMBOL_GPL(gpiod_cansleep);
34773478

drivers/gpio/gpiolib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* @descs: array of ngpio descriptors.
3535
* @ngpio: the number of GPIO lines on this GPIO device, equal to the size
3636
* of the @descs array.
37+
* @can_sleep: indicate whether the GPIO chip driver's callbacks can sleep
38+
* implying that they cannot be used from atomic context
3739
* @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned
3840
* at device creation time.
3941
* @label: a descriptive name for the GPIO device, such as the part number
@@ -64,6 +66,7 @@ struct gpio_device {
6466
struct gpio_desc *descs;
6567
int base;
6668
u16 ngpio;
69+
bool can_sleep;
6770
const char *label;
6871
void *data;
6972
struct list_head list;

0 commit comments

Comments
 (0)