* [PATCH] tty: serial: cpm_uart: Fix behaviour for non existing GPIOs
@ 2020-06-06 7:30 Christophe Leroy
2020-06-08 6:41 ` Johan Hovold
2020-06-10 11:18 ` Linus Walleij
0 siblings, 2 replies; 3+ messages in thread
From: Christophe Leroy @ 2020-06-06 7:30 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Linus Walleij
Cc: linux-kernel, linuxppc-dev, linux-serial
devm_gpiod_get_index() doesn't return NULL but -ENOENT when the
requested GPIO doesn't exist, leading to the following messages:
[ 2.742468] gpiod_direction_input: invalid GPIO (errorpointer)
[ 2.748147] can't set direction for gpio #2: -2
[ 2.753081] gpiod_direction_input: invalid GPIO (errorpointer)
[ 2.758724] can't set direction for gpio #3: -2
[ 2.763666] gpiod_direction_output: invalid GPIO (errorpointer)
[ 2.769394] can't set direction for gpio #4: -2
[ 2.774341] gpiod_direction_input: invalid GPIO (errorpointer)
[ 2.779981] can't set direction for gpio #5: -2
[ 2.784545] ff000a20.serial: ttyCPM1 at MMIO 0xfff00a20 (irq = 39, base_baud = 8250000) is a CPM UART
Use IS_ERR_OR_NULL() to properly check gpiod validity.
Fixes: 97cbaf2c829b ("tty: serial: cpm_uart: Convert to use GPIO descriptors")
Cc: stable@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
drivers/tty/serial/cpm_uart/cpm_uart_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
index a04f74d2e854..3cbe24802296 100644
--- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
@@ -1217,7 +1217,7 @@ static int cpm_uart_init_port(struct device_node *np,
gpiod = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS);
- if (gpiod) {
+ if (!IS_ERR_OR_NULL(gpiod)) {
if (i == GPIO_RTS || i == GPIO_DTR)
ret = gpiod_direction_output(gpiod, 0);
else
--
2.25.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tty: serial: cpm_uart: Fix behaviour for non existing GPIOs
2020-06-06 7:30 [PATCH] tty: serial: cpm_uart: Fix behaviour for non existing GPIOs Christophe Leroy
@ 2020-06-08 6:41 ` Johan Hovold
2020-06-10 11:18 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2020-06-08 6:41 UTC (permalink / raw)
To: Christophe Leroy
Cc: Greg Kroah-Hartman, Jiri Slaby, Linus Walleij, linux-kernel,
linuxppc-dev, linux-serial
On Sat, Jun 06, 2020 at 07:30:21AM +0000, Christophe Leroy wrote:
> devm_gpiod_get_index() doesn't return NULL but -ENOENT when the
> requested GPIO doesn't exist, leading to the following messages:
>
> [ 2.742468] gpiod_direction_input: invalid GPIO (errorpointer)
> [ 2.748147] can't set direction for gpio #2: -2
> [ 2.753081] gpiod_direction_input: invalid GPIO (errorpointer)
> [ 2.758724] can't set direction for gpio #3: -2
> [ 2.763666] gpiod_direction_output: invalid GPIO (errorpointer)
> [ 2.769394] can't set direction for gpio #4: -2
> [ 2.774341] gpiod_direction_input: invalid GPIO (errorpointer)
> [ 2.779981] can't set direction for gpio #5: -2
> [ 2.784545] ff000a20.serial: ttyCPM1 at MMIO 0xfff00a20 (irq = 39, base_baud = 8250000) is a CPM UART
>
> Use IS_ERR_OR_NULL() to properly check gpiod validity.
Why check for NULL at all?
> Fixes: 97cbaf2c829b ("tty: serial: cpm_uart: Convert to use GPIO descriptors")
> Cc: stable@vger.kernel.org
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> drivers/tty/serial/cpm_uart/cpm_uart_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
> index a04f74d2e854..3cbe24802296 100644
> --- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
> +++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
> @@ -1217,7 +1217,7 @@ static int cpm_uart_init_port(struct device_node *np,
>
> gpiod = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS);
>
> - if (gpiod) {
> + if (!IS_ERR_OR_NULL(gpiod)) {
> if (i == GPIO_RTS || i == GPIO_DTR)
> ret = gpiod_direction_output(gpiod, 0);
> else
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tty: serial: cpm_uart: Fix behaviour for non existing GPIOs
2020-06-06 7:30 [PATCH] tty: serial: cpm_uart: Fix behaviour for non existing GPIOs Christophe Leroy
2020-06-08 6:41 ` Johan Hovold
@ 2020-06-10 11:18 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2020-06-10 11:18 UTC (permalink / raw)
To: Christophe Leroy
Cc: Greg Kroah-Hartman, Jiri Slaby, linux-kernel,
linuxppc-dev@lists.ozlabs.org list, open list:SERIAL DRIVERS
Hi Christophe!
On Sat, Jun 6, 2020 at 9:30 AM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
> gpiod = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS);
>
> - if (gpiod) {
> + if (!IS_ERR_OR_NULL(gpiod)) {
> if (i == GPIO_RTS || i == GPIO_DTR)
> ret = gpiod_direction_output(gpiod, 0);
> else
This code, and the way descriptors are used in the driver leads
me to believe that the right solution is to use the optional
call with a hard error check:
gpiod = devm_gpiod_get_index_optional(...);
if (IS_ERR(gpiod))
return PTR_ERR(gpiod);
if (gpiod) {
... followed by the old code ...
This makes sure that the array member is left NULL if there is no
GPIO on this line, and all other errors, such as -EPROBE_DEFER
which currently absolutely does not work, will lead to us properly
exiting with an error.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-10 11:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-06 7:30 [PATCH] tty: serial: cpm_uart: Fix behaviour for non existing GPIOs Christophe Leroy
2020-06-08 6:41 ` Johan Hovold
2020-06-10 11:18 ` Linus Walleij
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).