Skip to content

Commit 74e0fcb

Browse files
committed
gpiolib: add gpiod_multi_set_value_cansleep
Merge series from David Lechner <dlechner@baylibre.com>: This series was inspired by some minor annoyance I have experienced a few times in recent reviews. Calling gpiod_set_array_value_cansleep() can be quite verbose due to having so many parameters. In most cases, we already have a struct gpio_descs that contains the first 3 parameters so we end up with 3 (or often even 6) pointer indirections at each call site. Also, people have a tendency to want to hard-code the first argument instead of using struct gpio_descs.ndescs, often without checking that ndescs >= the hard-coded value. So I'm proposing that we add a gpiod_multi_set_value_cansleep() function that is a wrapper around gpiod_set_array_value_cansleep() that has struct gpio_descs as the first parameter to make it a bit easier to read the code and avoid the hard-coding temptation. I've just done gpiod_multi_set_value_cansleep() for now since there were over 10 callers of this one. There aren't as many callers of the get and atomic variants, but we can add those too if this seems like a useful thing to do. Maintainers, if you prefer to have this go through the gpio tree, please give your Acked-by:. Several maintainers have also requested an immutable branch, so I expect that will be made available. And if there is anything leftover after the next kernel release, I will resend it.
2 parents 994719e + ad0fbce commit 74e0fcb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

include/linux/gpio/consumer.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define __LINUX_GPIO_CONSUMER_H
44

55
#include <linux/bits.h>
6+
#include <linux/err.h>
67
#include <linux/types.h>
78

89
struct acpi_device;
@@ -655,4 +656,14 @@ static inline void gpiod_unexport(struct gpio_desc *desc)
655656

656657
#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
657658

659+
static inline int gpiod_multi_set_value_cansleep(struct gpio_descs *descs,
660+
unsigned long *value_bitmap)
661+
{
662+
if (IS_ERR_OR_NULL(descs))
663+
return PTR_ERR_OR_ZERO(descs);
664+
665+
return gpiod_set_array_value_cansleep(descs->ndescs, descs->desc,
666+
descs->info, value_bitmap);
667+
}
668+
658669
#endif

sound/soc/codecs/adau1701.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,7 @@ static int adau1701_reset(struct snd_soc_component *component, unsigned int clkd
325325
__assign_bit(1, values, 1);
326326
break;
327327
}
328-
gpiod_set_array_value_cansleep(adau1701->gpio_pll_mode->ndescs,
329-
adau1701->gpio_pll_mode->desc, adau1701->gpio_pll_mode->info,
330-
values);
328+
gpiod_multi_set_value_cansleep(adau1701->gpio_pll_mode, values);
331329
}
332330

333331
adau1701->pll_clkdiv = clkdiv;

0 commit comments

Comments
 (0)