linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Courbot <gnurou@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] gpio: Add helpers for optional GPIOs
Date: Thu, 1 May 2014 15:02:07 +0900	[thread overview]
Message-ID: <CAAVeFuJCMyqJAY40QJZjn8igjzc1dcRLusiDQ3b4znQFKfvwRA@mail.gmail.com> (raw)
In-Reply-To: <1398438606-19718-2-git-send-email-thierry.reding@gmail.com>

On Sat, Apr 26, 2014 at 12:10 AM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> 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 <acourbot@nvidia.com>

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.

  reply	other threads:[~2014-05-01  6:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-25 15:10 [PATCH 1/2] gpio: Add missing device-managed documentation Thierry Reding
2014-04-25 15:10 ` [PATCH 2/2] gpio: Add helpers for optional GPIOs Thierry Reding
2014-05-01  6:02   ` Alexandre Courbot [this message]
2014-05-09 11:50   ` Linus Walleij
2014-05-02 22:19 ` [PATCH 1/2] gpio: Add missing device-managed documentation Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAVeFuJCMyqJAY40QJZjn8igjzc1dcRLusiDQ3b4znQFKfvwRA@mail.gmail.com \
    --to=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).