On Sat, Apr 26, 2014 at 12:10 AM, Thierry Reding
<[email protected]> wrote:
> From: Thierry Reding <[email protected]>
>
> Introduce gpiod_get_optional() and gpiod_get_index_optional() helpers
> that make it easier for drivers to handle optional GPIOs.
>
> Currently in order to handle optional GPIOs, a driver needs to special
> case error handling for -ENOENT, such as this:
>
>         gpio = gpiod_get(dev, "foo");
>         if (IS_ERR(gpio)) {
>                 if (PTR_ERR(gpio) != -ENOENT)
>                         return PTR_ERR(gpio);
>
>                 gpio = NULL;
>         }
>
>         if (gpio) {
>                 /* set up GPIO */
>         }
>
> With these new helpers the above is reduced to:
>
>         gpio = gpiod_get_optional(dev, "foo");
>         if (IS_ERR(gpio))
>                 return PTR_ERR(gpio);
>
>         if (gpio) {
>                 /* set up GPIO */
>         }
>
> While at it, device-managed variants of these functions are also
> provided.

Patch is sound and the introduced functions are useful indeed.

Reviewed-by: Alexandre Courbot <[email protected]>

It makes me wonder whether this should not have been the behavior of
gpiod_get() directly... My aversion for IS_ERR_OR_NULL drove the
current design, which may not have been optimal.

Oh, well.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to