gpio: don't WARN() on NULL descs if gpiolib is disabled
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Mon, 8 Jul 2019 08:23:43 +0000 (10:23 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 16 Sep 2019 06:22:22 +0000 (08:22 +0200)
commitc9c90711ee88429766dc3c7a942c8d1905bb0113
tree2ff981730e596ac0b22555461ab52a679663c835
parenta532a120a5cd1d9c6bfe761d5aa546274d5d2819
gpio: don't WARN() on NULL descs if gpiolib is disabled

[ Upstream commit ffe0bbabb0cffceceae07484fde1ec2a63b1537c ]

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.

Cc: stable@vger.kernel.org
Reported-by: Claus H. Stovgaard <cst@phaseone.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/gpio/consumer.h