Skip to content

Commit 8ce258f

Browse files
author
Bartosz Golaszewski
committed
gpiolib: make value setters have return values
Change the in-kernel consumer interface for GPIOs: make all variants of value setters that don't have a return value, return a signed integer instead. That will allow these routines to indicate failures to callers. This doesn't change the implementation just yet, we'll do it in subsequent commits. We need to update the gpio-latch module as it passes the address of value setters as a function pointer argument and thus cares about its type. Reviewed-by: Linus Walleij <[email protected]> Acked-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 129fdfe commit 8ce258f

File tree

4 files changed

+46
-35
lines changed

4 files changed

+46
-35
lines changed

drivers/gpio/gpio-latch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int gpio_latch_get_direction(struct gpio_chip *gc, unsigned int offset)
7373
}
7474

7575
static void gpio_latch_set_unlocked(struct gpio_latch_priv *priv,
76-
void (*set)(struct gpio_desc *desc, int value),
76+
int (*set)(struct gpio_desc *desc, int value),
7777
unsigned int offset, bool val)
7878
{
7979
int latch = offset / priv->n_latched_gpios;

drivers/gpio/gpiolib.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,13 +3497,13 @@ EXPORT_SYMBOL_GPL(gpiod_get_array_value);
34973497
* @desc: gpio descriptor whose state need to be set.
34983498
* @value: Non-zero for setting it HIGH otherwise it will set to LOW.
34993499
*/
3500-
static void gpio_set_open_drain_value_commit(struct gpio_desc *desc, bool value)
3500+
static int gpio_set_open_drain_value_commit(struct gpio_desc *desc, bool value)
35013501
{
35023502
int ret = 0, offset = gpio_chip_hwgpio(desc);
35033503

35043504
CLASS(gpio_chip_guard, guard)(desc);
35053505
if (!guard.gc)
3506-
return;
3506+
return -ENODEV;
35073507

35083508
if (value) {
35093509
ret = gpiochip_direction_input(guard.gc, offset);
@@ -3517,20 +3517,22 @@ static void gpio_set_open_drain_value_commit(struct gpio_desc *desc, bool value)
35173517
gpiod_err(desc,
35183518
"%s: Error in set_value for open drain err %d\n",
35193519
__func__, ret);
3520+
3521+
return ret;
35203522
}
35213523

35223524
/*
35233525
* _gpio_set_open_source_value() - Set the open source gpio's value.
35243526
* @desc: gpio descriptor whose state need to be set.
35253527
* @value: Non-zero for setting it HIGH otherwise it will set to LOW.
35263528
*/
3527-
static void gpio_set_open_source_value_commit(struct gpio_desc *desc, bool value)
3529+
static int gpio_set_open_source_value_commit(struct gpio_desc *desc, bool value)
35283530
{
35293531
int ret = 0, offset = gpio_chip_hwgpio(desc);
35303532

35313533
CLASS(gpio_chip_guard, guard)(desc);
35323534
if (!guard.gc)
3533-
return;
3535+
return -ENODEV;
35343536

35353537
if (value) {
35363538
ret = gpiochip_direction_output(guard.gc, offset, 1);
@@ -3544,16 +3546,20 @@ static void gpio_set_open_source_value_commit(struct gpio_desc *desc, bool value
35443546
gpiod_err(desc,
35453547
"%s: Error in set_value for open source err %d\n",
35463548
__func__, ret);
3549+
3550+
return ret;
35473551
}
35483552

3549-
static void gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value)
3553+
static int gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value)
35503554
{
35513555
CLASS(gpio_chip_guard, guard)(desc);
35523556
if (!guard.gc)
3553-
return;
3557+
return -ENODEV;
35543558

35553559
trace_gpio_value(desc_to_gpio(desc), 0, value);
35563560
guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), value);
3561+
3562+
return 0;
35573563
}
35583564

35593565
/*
@@ -3711,12 +3717,12 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
37113717
* This function can be called from contexts where we cannot sleep, and will
37123718
* complain if the GPIO chip functions potentially sleep.
37133719
*/
3714-
void gpiod_set_raw_value(struct gpio_desc *desc, int value)
3720+
int gpiod_set_raw_value(struct gpio_desc *desc, int value)
37153721
{
3716-
VALIDATE_DESC_VOID(desc);
3722+
VALIDATE_DESC(desc);
37173723
/* Should be using gpiod_set_raw_value_cansleep() */
37183724
WARN_ON(desc->gdev->can_sleep);
3719-
gpiod_set_raw_value_commit(desc, value);
3725+
return gpiod_set_raw_value_commit(desc, value);
37203726
}
37213727
EXPORT_SYMBOL_GPL(gpiod_set_raw_value);
37223728

@@ -3729,16 +3735,17 @@ EXPORT_SYMBOL_GPL(gpiod_set_raw_value);
37293735
* different semantic quirks like active low and open drain/source
37303736
* handling.
37313737
*/
3732-
static void gpiod_set_value_nocheck(struct gpio_desc *desc, int value)
3738+
static int gpiod_set_value_nocheck(struct gpio_desc *desc, int value)
37333739
{
37343740
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
37353741
value = !value;
3742+
37363743
if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
3737-
gpio_set_open_drain_value_commit(desc, value);
3744+
return gpio_set_open_drain_value_commit(desc, value);
37383745
else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
3739-
gpio_set_open_source_value_commit(desc, value);
3740-
else
3741-
gpiod_set_raw_value_commit(desc, value);
3746+
return gpio_set_open_source_value_commit(desc, value);
3747+
3748+
return gpiod_set_raw_value_commit(desc, value);
37423749
}
37433750

37443751
/**
@@ -3752,12 +3759,12 @@ static void gpiod_set_value_nocheck(struct gpio_desc *desc, int value)
37523759
* This function can be called from contexts where we cannot sleep, and will
37533760
* complain if the GPIO chip functions potentially sleep.
37543761
*/
3755-
void gpiod_set_value(struct gpio_desc *desc, int value)
3762+
int gpiod_set_value(struct gpio_desc *desc, int value)
37563763
{
3757-
VALIDATE_DESC_VOID(desc);
3764+
VALIDATE_DESC(desc);
37583765
/* Should be using gpiod_set_value_cansleep() */
37593766
WARN_ON(desc->gdev->can_sleep);
3760-
gpiod_set_value_nocheck(desc, value);
3767+
return gpiod_set_value_nocheck(desc, value);
37613768
}
37623769
EXPORT_SYMBOL_GPL(gpiod_set_value);
37633770

@@ -4176,11 +4183,11 @@ EXPORT_SYMBOL_GPL(gpiod_get_array_value_cansleep);
41764183
*
41774184
* This function is to be called from contexts that can sleep.
41784185
*/
4179-
void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value)
4186+
int gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value)
41804187
{
41814188
might_sleep();
4182-
VALIDATE_DESC_VOID(desc);
4183-
gpiod_set_raw_value_commit(desc, value);
4189+
VALIDATE_DESC(desc);
4190+
return gpiod_set_raw_value_commit(desc, value);
41844191
}
41854192
EXPORT_SYMBOL_GPL(gpiod_set_raw_value_cansleep);
41864193

@@ -4194,11 +4201,11 @@ EXPORT_SYMBOL_GPL(gpiod_set_raw_value_cansleep);
41944201
*
41954202
* This function is to be called from contexts that can sleep.
41964203
*/
4197-
void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
4204+
int gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
41984205
{
41994206
might_sleep();
4200-
VALIDATE_DESC_VOID(desc);
4201-
gpiod_set_value_nocheck(desc, value);
4207+
VALIDATE_DESC(desc);
4208+
return gpiod_set_value_nocheck(desc, value);
42024209
}
42034210
EXPORT_SYMBOL_GPL(gpiod_set_value_cansleep);
42044211

include/linux/gpio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static inline int gpio_get_value_cansleep(unsigned gpio)
9191
}
9292
static inline void gpio_set_value_cansleep(unsigned gpio, int value)
9393
{
94-
return gpiod_set_raw_value_cansleep(gpio_to_desc(gpio), value);
94+
gpiod_set_raw_value_cansleep(gpio_to_desc(gpio), value);
9595
}
9696

9797
static inline int gpio_get_value(unsigned gpio)
@@ -100,7 +100,7 @@ static inline int gpio_get_value(unsigned gpio)
100100
}
101101
static inline void gpio_set_value(unsigned gpio, int value)
102102
{
103-
return gpiod_set_raw_value(gpio_to_desc(gpio), value);
103+
gpiod_set_raw_value(gpio_to_desc(gpio), value);
104104
}
105105

106106
static inline int gpio_to_irq(unsigned gpio)

include/linux/gpio/consumer.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int gpiod_get_array_value(unsigned int array_size,
118118
struct gpio_desc **desc_array,
119119
struct gpio_array *array_info,
120120
unsigned long *value_bitmap);
121-
void gpiod_set_value(struct gpio_desc *desc, int value);
121+
int gpiod_set_value(struct gpio_desc *desc, int value);
122122
int gpiod_set_array_value(unsigned int array_size,
123123
struct gpio_desc **desc_array,
124124
struct gpio_array *array_info,
@@ -128,7 +128,7 @@ int gpiod_get_raw_array_value(unsigned int array_size,
128128
struct gpio_desc **desc_array,
129129
struct gpio_array *array_info,
130130
unsigned long *value_bitmap);
131-
void gpiod_set_raw_value(struct gpio_desc *desc, int value);
131+
int gpiod_set_raw_value(struct gpio_desc *desc, int value);
132132
int gpiod_set_raw_array_value(unsigned int array_size,
133133
struct gpio_desc **desc_array,
134134
struct gpio_array *array_info,
@@ -140,7 +140,7 @@ int gpiod_get_array_value_cansleep(unsigned int array_size,
140140
struct gpio_desc **desc_array,
141141
struct gpio_array *array_info,
142142
unsigned long *value_bitmap);
143-
void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
143+
int gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
144144
int gpiod_set_array_value_cansleep(unsigned int array_size,
145145
struct gpio_desc **desc_array,
146146
struct gpio_array *array_info,
@@ -150,7 +150,7 @@ int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
150150
struct gpio_desc **desc_array,
151151
struct gpio_array *array_info,
152152
unsigned long *value_bitmap);
153-
void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
153+
int gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
154154
int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
155155
struct gpio_desc **desc_array,
156156
struct gpio_array *array_info,
@@ -360,10 +360,11 @@ static inline int gpiod_get_array_value(unsigned int array_size,
360360
WARN_ON(desc_array);
361361
return 0;
362362
}
363-
static inline void gpiod_set_value(struct gpio_desc *desc, int value)
363+
static inline int gpiod_set_value(struct gpio_desc *desc, int value)
364364
{
365365
/* GPIO can never have been requested */
366366
WARN_ON(desc);
367+
return 0;
367368
}
368369
static inline int gpiod_set_array_value(unsigned int array_size,
369370
struct gpio_desc **desc_array,
@@ -389,10 +390,11 @@ static inline int gpiod_get_raw_array_value(unsigned int array_size,
389390
WARN_ON(desc_array);
390391
return 0;
391392
}
392-
static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
393+
static inline int gpiod_set_raw_value(struct gpio_desc *desc, int value)
393394
{
394395
/* GPIO can never have been requested */
395396
WARN_ON(desc);
397+
return 0;
396398
}
397399
static inline int gpiod_set_raw_array_value(unsigned int array_size,
398400
struct gpio_desc **desc_array,
@@ -419,10 +421,11 @@ static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
419421
WARN_ON(desc_array);
420422
return 0;
421423
}
422-
static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
424+
static inline int gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
423425
{
424426
/* GPIO can never have been requested */
425427
WARN_ON(desc);
428+
return 0;
426429
}
427430
static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
428431
struct gpio_desc **desc_array,
@@ -448,11 +451,12 @@ static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
448451
WARN_ON(desc_array);
449452
return 0;
450453
}
451-
static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
452-
int value)
454+
static inline int gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
455+
int value)
453456
{
454457
/* GPIO can never have been requested */
455458
WARN_ON(desc);
459+
return 0;
456460
}
457461
static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
458462
struct gpio_desc **desc_array,

0 commit comments

Comments
 (0)