Skip to content

Commit d36058b

Browse files
author
Bartosz Golaszewski
committed
gpiolib: wrap gpio_chip::set()
We have three places where we dereference the gpio_chip::set() callback. In order to make it easier to incorporate the upcoming new variant of this callback (one returning an integer value), wrap it in a helper so that the dereferencing only happens once. 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 8ce258f commit d36058b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

drivers/gpio/gpiolib.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,6 +2825,17 @@ int gpiod_direction_input_nonotify(struct gpio_desc *desc)
28252825
return ret;
28262826
}
28272827

2828+
static int gpiochip_set(struct gpio_chip *gc, unsigned int offset, int value)
2829+
{
2830+
lockdep_assert_held(&gc->gpiodev->srcu);
2831+
2832+
if (WARN_ON(unlikely(!gc->set)))
2833+
return -EOPNOTSUPP;
2834+
2835+
gc->set(gc, offset, value);
2836+
return 0;
2837+
}
2838+
28282839
static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value)
28292840
{
28302841
int val = !!value, ret = 0;
@@ -2867,7 +2878,9 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value)
28672878
* If we can't actively set the direction, we are some
28682879
* output-only chip, so just drive the output as desired.
28692880
*/
2870-
guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), val);
2881+
ret = gpiochip_set(guard.gc, gpio_chip_hwgpio(desc), val);
2882+
if (ret)
2883+
return ret;
28712884
}
28722885

28732886
if (!ret)
@@ -3557,9 +3570,7 @@ static int gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value)
35573570
return -ENODEV;
35583571

35593572
trace_gpio_value(desc_to_gpio(desc), 0, value);
3560-
guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), value);
3561-
3562-
return 0;
3573+
return gpiochip_set(guard.gc, gpio_chip_hwgpio(desc), value);
35633574
}
35643575

35653576
/*
@@ -3584,7 +3595,7 @@ static void gpio_chip_set_multiple(struct gpio_chip *gc,
35843595

35853596
/* set outputs if the corresponding mask bit is set */
35863597
for_each_set_bit(i, mask, gc->ngpio)
3587-
gc->set(gc, i, test_bit(i, bits));
3598+
gpiochip_set(gc, i, test_bit(i, bits));
35883599
}
35893600
}
35903601

0 commit comments

Comments
 (0)