Commit 311eab8d authored by Christophe Leroy's avatar Christophe Leroy Committed by Greg Kroah-Hartman

tty: serial: cpm_uart: Fix behaviour for non existing GPIOs

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 devm_gpiod_get_index_optional() instead.

At the same time, handle the error case and properly exit
with an error.

Fixes: 97cbaf2c ("tty: serial: cpm_uart: Convert to use GPIO descriptors")
Cc: stable@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/694a25fdce548c5ee8b060ef6a4b02746b8f25c0.1591986307.git.christophe.leroy@csgroup.euSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 48778464
...@@ -1215,7 +1215,12 @@ static int cpm_uart_init_port(struct device_node *np, ...@@ -1215,7 +1215,12 @@ static int cpm_uart_init_port(struct device_node *np,
pinfo->gpios[i] = NULL; pinfo->gpios[i] = NULL;
gpiod = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS); gpiod = devm_gpiod_get_index_optional(dev, NULL, i, GPIOD_ASIS);
if (IS_ERR(gpiod)) {
ret = PTR_ERR(gpiod);
goto out_irq;
}
if (gpiod) { if (gpiod) {
if (i == GPIO_RTS || i == GPIO_DTR) if (i == GPIO_RTS || i == GPIO_DTR)
...@@ -1237,6 +1242,8 @@ static int cpm_uart_init_port(struct device_node *np, ...@@ -1237,6 +1242,8 @@ static int cpm_uart_init_port(struct device_node *np,
return cpm_uart_request_port(&pinfo->port); return cpm_uart_request_port(&pinfo->port);
out_irq:
irq_dispose_mapping(pinfo->port.irq);
out_pram: out_pram:
cpm_uart_unmap_pram(pinfo, pram); cpm_uart_unmap_pram(pinfo, pram);
out_mem: out_mem:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment