Skip to content

Commit f13968b

Browse files
chleroygregkh
authored andcommitted
tty: serial: cpm_uart: Fix behaviour for non existing GPIOs
commit 311eab8 upstream. 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: 97cbaf2 ("tty: serial: cpm_uart: Convert to use GPIO descriptors") Cc: [email protected] Cc: Linus Walleij <[email protected]> Signed-off-by: Christophe Leroy <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/694a25fdce548c5ee8b060ef6a4b02746b8f25c0.1591986307.git.christophe.leroy@csgroup.eu Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent df858e2 commit f13968b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/tty/serial/cpm_uart/cpm_uart_core.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,12 @@ static int cpm_uart_init_port(struct device_node *np,
12151215

12161216
pinfo->gpios[i] = NULL;
12171217

1218-
gpiod = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS);
1218+
gpiod = devm_gpiod_get_index_optional(dev, NULL, i, GPIOD_ASIS);
1219+
1220+
if (IS_ERR(gpiod)) {
1221+
ret = PTR_ERR(gpiod);
1222+
goto out_irq;
1223+
}
12191224

12201225
if (gpiod) {
12211226
if (i == GPIO_RTS || i == GPIO_DTR)
@@ -1237,6 +1242,8 @@ static int cpm_uart_init_port(struct device_node *np,
12371242

12381243
return cpm_uart_request_port(&pinfo->port);
12391244

1245+
out_irq:
1246+
irq_dispose_mapping(pinfo->port.irq);
12401247
out_pram:
12411248
cpm_uart_unmap_pram(pinfo, pram);
12421249
out_mem:

0 commit comments

Comments
 (0)