linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	"Claus H . Stovgaard" <cst@phaseone.com>
Subject: Re: [PATCH] gpio: don't WARN() on NULL descs if gpiolib is disabled
Date: Tue, 9 Jul 2019 15:30:22 +0200	[thread overview]
Message-ID: <CACRpkdb5xKHZja0mkd-wZJ+YHZpGJaDrkA0dv60MNYKXFcPK4w@mail.gmail.com> (raw)
In-Reply-To: <20190708082343.30726-1-brgl@bgdev.pl>

Hi Bartosz,

On Mon, Jul 8, 2019 at 10:25 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> If gpiolib is disabled, we use the inline stubs from gpio/consumer.h
> instead of regular definitions of GPIO API. The stubs for 'optional'
> variants of gpiod_get routines return NULL in this case as if the
> relevant GPIO wasn't found. This is correct so far.
>
> Calling other (non-gpio_get) stubs from this header triggers a warning
> because the GPIO descriptor couldn't have been requested. The warning
> however is unconditional (WARN_ON(1)) and is emitted even if the passed
> descriptor pointer is NULL.
>
> We don't want to force the users of 'optional' gpio_get to check the
> returned pointer before calling e.g. gpiod_set_value() so let's only
> WARN on non-NULL descriptors.
>
> Reported-by: Claus H. Stovgaard <cst@phaseone.com>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

I remember I had this discussion in the past, and I made a large
refactoring to make it possible for drivers that need gpiod_*
calls to simply do:

select GPIOLIB

in Kconfig.

This should solve also this problem I think.

However I do realize that there may be situations where people
simply want to make GPIO support entirely optional without
having to e.g. create custom stubs and encapsulate things
inside if IS_ENABLED(CONFIG_GPIOLIB).

I was thinking something like this in the stubs:

gpiod_get[_index]() {
    return POISON;
}

gpiod_get[_index]_optional() {
   return NULL;
}

This way all gpiod_get() and optional calls are properly
handled and the semantic that only _optional calls
can return NULL is preserved. (Your patch would
violate this.)

Then other stubs can do:

gpiod_set_value() {
  WARN_ON(desc);
}

As in your patch, and all will be smooth provided the
_optional calls have been used to obtain the desc.

Yours,
Linus Walleij

  parent reply	other threads:[~2019-07-09 13:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-08  8:23 [PATCH] gpio: don't WARN() on NULL descs if gpiolib is disabled Bartosz Golaszewski
2019-07-08 10:18 ` Claus H. Stovgaard
2019-07-09 13:30 ` Linus Walleij [this message]
2019-07-09 14:20   ` Bartosz Golaszewski
2019-07-16 21:46     ` Linus Walleij
2019-07-20 18:03       ` Bartosz Golaszewski
2019-07-20 19:44         ` Linus Walleij
2019-07-22  6:14           ` Bartosz Golaszewski
2019-07-10 13:09   ` Enrico Weigelt, metux IT consult
2019-07-10 20:02   ` Claus H. Stovgaard

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=CACRpkdb5xKHZja0mkd-wZJ+YHZpGJaDrkA0dv60MNYKXFcPK4w@mail.gmail.com \
    --to=linus.walleij@linaro.org \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=cst@phaseone.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).