Message ID | 20250206-gpio-set-array-helper-v2-1-1c5f048f79c3@baylibre.com |
---|---|
State | New |
Headers | show |
Series | gpiolib: add gpiod_multi_set_value_cansleep | expand |
Hi David, On Thu, 6 Feb 2025 at 23:48, David Lechner <dlechner@baylibre.com> wrote: > Add a new gpiod_multi_set_value_cansleep() helper function with fewer > parameters than gpiod_set_array_value_cansleep(). > > Calling gpiod_set_array_value_cansleep() can get quite verbose. In many > cases, the first arguments all come from the same struct gpio_descs, so > having a separate function where we can just pass that cuts down on the > boilerplate. > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org> > Signed-off-by: David Lechner <dlechner@baylibre.com> Thanks for your patch! > --- a/include/linux/gpio/consumer.h > +++ b/include/linux/gpio/consumer.h > @@ -655,4 +655,11 @@ static inline void gpiod_unexport(struct gpio_desc *desc) > > #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ > > +static inline int gpiod_multi_set_value_cansleep(struct gpio_descs *descs, > + unsigned long *value_bitmap) > +{ > + return gpiod_set_array_value_cansleep(descs->ndescs, descs->desc, > + descs->info, value_bitmap); I am wondering whether this needs a check for !IS_ERR_OR_NULL(descs), to handle the !CONFIG_GPIOLIB and gpiod_get_array_optional() cases? Slightly related: shouldn't gpiod_put_array() (both the implementation and the !CONFIG_GPIOLIB dummy) allow the caller to pass NULL, to streamline the gpiod_get_array_optional() case? > +} > + > #endif Gr{oetje,eeting}s, Geert
Hi David, On Fri, 7 Feb 2025 at 17:29, David Lechner <dlechner@baylibre.com> wrote: > On 2/7/25 3:10 AM, Geert Uytterhoeven wrote: > > On Thu, 6 Feb 2025 at 23:48, David Lechner <dlechner@baylibre.com> wrote: > >> Add a new gpiod_multi_set_value_cansleep() helper function with fewer > >> parameters than gpiod_set_array_value_cansleep(). > >> > >> Calling gpiod_set_array_value_cansleep() can get quite verbose. In many > >> cases, the first arguments all come from the same struct gpio_descs, so > >> having a separate function where we can just pass that cuts down on the > >> boilerplate. > >> > >> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> > >> Signed-off-by: David Lechner <dlechner@baylibre.com> > > > > Thanks for your patch! > > > >> --- a/include/linux/gpio/consumer.h > >> +++ b/include/linux/gpio/consumer.h > >> @@ -655,4 +655,11 @@ static inline void gpiod_unexport(struct gpio_desc *desc) > >> > >> #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ > >> > >> +static inline int gpiod_multi_set_value_cansleep(struct gpio_descs *descs, > >> + unsigned long *value_bitmap) > >> +{ > >> + return gpiod_set_array_value_cansleep(descs->ndescs, descs->desc, > >> + descs->info, value_bitmap); > > > > I am wondering whether this needs a check for !IS_ERR_OR_NULL(descs), > > to handle the !CONFIG_GPIOLIB and gpiod_get_array_optional() cases? > > I don't think it is strictly needed, but could be convenient for future use > cases. If we add it, should it be: > > if (IS_ERR_OR_NULL(descs)) > return PTR_ERR(descs); return PTR_ERR_OR_ZERO(descs); (the compiler should optimize away checks common to IS_ERR_OR_NULL() and PTR_ERR_OR_ZERO()). > or: > > if (!descs) > return -EINVAL; > > if (IS_ERR(descs)) > return PTR_ERR(descs); > > ? The former. > For comparison, gpiod_set_array_value_cansleep() will return -EINVAL if the > first argument is NULL. That function cannot take an argument returned by a *_optional() call, if I'm not mistaken. Gr{oetje,eeting}s, Geert
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index db2dfbae8edbd12059826183b1c0f73c7a58ff40..278a197a9deba11dadbff0b58507df91be658f34 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -655,4 +655,11 @@ static inline void gpiod_unexport(struct gpio_desc *desc) #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ +static inline int gpiod_multi_set_value_cansleep(struct gpio_descs *descs, + unsigned long *value_bitmap) +{ + return gpiod_set_array_value_cansleep(descs->ndescs, descs->desc, + descs->info, value_bitmap); +} + #endif