serial: 8250_omap: Fix gpio check for auto RTS and CTS
PATCH 1/1 serial: 8250_omap: Fix gpio check for auto RTS and CTS
There are two checks to see if the manual gpio is configured, but these the check is seeing if the structure is NULL instead it should check to see if there are CTS and/or RTS pins defined.
This patch uses checks for those individual pins instead of checking for the structure itself.
drivers/tty/serial/8250/8250_omap.c +3 -2
@@ -141,7 +141,7 @@ static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)serial8250_do_set_mctrl (port, mctrl); -if (!up->gpios) { +if (!mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS )) {/* * Turn off autoRTS if RTS is lowered and restore autoRTS * setting if RTS is raised
@@ -456,7 +456,8 @@ static void omap_8250_set_termios(struct uart_port *port, up->port.status &= ~(UPSTAT_AUTOCTS |UPSTAT_AUTORTS |UPSTAT_AUTOXOFF );if (termios->c_cflag &CRTSCTS && up->port.flags &UPF_HARD_FLOW && - !up->gpios) { + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS ) && + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_CTS )) {/* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ up->port.status |=UPSTAT_AUTOCTS |UPSTAT_AUTORTS ; priv->efr |=UART_EFR_CTS ;
Signature · 1 line
2.17.1
Hi Adam,
Quoted 24 lines · Adam Ford
There are two checks to see if the manual gpio is configured, but these the check is seeing if the structure is NULL instead it should check to see if there are CTS and/or RTS pins defined.
This patch uses checks for those individual pins instead of checking for the structure itself.
Signed-off-by Adam Ford <[email protected]>drivers/tty/serial/8250/8250_omap.c +1
-1@@ -141,7 +141,7 @@ static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)serial8250_do_set_mctrl (port, mctrl); -if (!up->gpios) { +if (!mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS )) {/* * Turn off autoRTS if RTS is lowered and restore autoRTS * setting if RTS is raised
drivers/tty/serial/8250/8250_omap.c static void omap_8250_set_termios(struct uart_port *port, · line 463
Quoted 9 lines
drivers/tty/serial/8250/8250_omap.c +2
-1@@ -456,7 +456,8 @@ static void omap_8250_set_termios(struct uart_port *port, up->port.status &= ~(UPSTAT_AUTOCTS |UPSTAT_AUTORTS |UPSTAT_AUTOXOFF );if (termios->c_cflag &CRTSCTS && up->port.flags &UPF_HARD_FLOW && - !up->gpios) { + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS ) && + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_CTS )) {/* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ up->port.status |=UPSTAT_AUTOCTS |UPSTAT_AUTORTS ; priv->efr |=UART_EFR_CTS ;
Looks good to me but !up->gpios must remain as otherwise, we will get NULL pointer dereference. What do you think?
Also adding some more people who can be interested in testing this approach.
Cheers,
Yegor
Quoted 30 lines · Yegor Yefremov
Hi Adam,
Quoted 26 lines · Adam Ford
There are two checks to see if the manual gpio is configured, but these the check is seeing if the structure is NULL instead it should check to see if there are CTS and/or RTS pins defined.
This patch uses checks for those individual pins instead of checking for the structure itself.
Signed-off-by Adam Ford <[email protected]>drivers/tty/serial/8250/8250_omap.c +1
-1@@ -141,7 +141,7 @@ static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)serial8250_do_set_mctrl (port, mctrl); -if (!up->gpios) { +if (!mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS )) {/* * Turn off autoRTS if RTS is lowered and restore autoRTS * setting if RTS is raised @@ -456,7 +456,8 @@ static void omap_8250_set_termios(struct uart_port *port, up->port.status &= ~(UPSTAT_AUTOCTS |UPSTAT_AUTORTS |UPSTAT_AUTOXOFF );
Quoted 10 lines
drivers/tty/serial/8250/8250_omap.c static void omap_8250_set_termios(struct uart_port *port, · line 463
Quoted 7 lines
drivers/tty/serial/8250/8250_omap.c +2
-1if (termios->c_cflag &CRTSCTS && up->port.flags &UPF_HARD_FLOW && - !up->gpios) { + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS ) && + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_CTS )) {/* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ up->port.status |=UPSTAT_AUTOCTS |UPSTAT_AUTORTS ; priv->efr |=UART_EFR_CTS ;Looks good to me but !up->gpios must remain as otherwise, we will get NULL pointer dereference. What do you think?
I was not seeing up->gpios ever NULL so the contents inside the check never was executed. When I removed the check, the performance came back. I looked at examples on how other devices checked for RTS and CTS, and I noticed that the Atmel serial driver did something like the above.
Quoted 2 lines
Also adding some more people who can be interested in testing this approach.
I am open for ideas. If something is better, but something is either incorrectly setting up->gpios to non-NULL or the check for non-NULL is wrong.
adam
Quoted 3 lines
Cheers,
Yegor
drivers/tty/serial/8250/8250_core.c
Quoted 15 lines · Adam Ford
Quoted 11 lines · Yegor Yefremov
Hi Adam,
Quoted 7 lines · Adam Ford
There are two checks to see if the manual gpio is configured, but these the check is seeing if the structure is NULL instead it should check to see if there are CTS and/or RTS pins defined.
This patch uses checks for those individual pins instead of checking for the structure itself.
drivers/tty/serial/8250/8250_core.c +0
-0
index e682390..d5fdb71 100644
drivers/tty/serial/8250/8250_core.c +0 -0
@@ -1031,6 +1031,8 @@ int serial8250_register_8250_port(struct
uart_8250_port *up)
} else {
uart->gpios = gpios;
}
+ } else {
+ uart->gpios = NULL;
}
serial8250_set_defaults(uart);Quoted 37 lines
Quoted 19 lines
Quoted 19 lines
Signed-off-by Adam Ford <[email protected]>drivers/tty/serial/8250/8250_omap.c +1
-1@@ -141,7 +141,7 @@ static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)serial8250_do_set_mctrl (port, mctrl); -if (!up->gpios) { +if (!mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS )) {/* * Turn off autoRTS if RTS is lowered and restore autoRTS * setting if RTS is raised @@ -456,7 +456,8 @@ static void omap_8250_set_termios(struct uart_port *port, up->port.status &= ~(UPSTAT_AUTOCTS |UPSTAT_AUTORTS |UPSTAT_AUTOXOFF );Quoted 10 lines
drivers/tty/serial/8250/8250_omap.c static void omap_8250_set_termios(struct uart_port *port, · line 463
Quoted 7 lines
drivers/tty/serial/8250/8250_omap.c +2
-1if (termios->c_cflag &CRTSCTS && up->port.flags &UPF_HARD_FLOW && - !up->gpios) { + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS ) && + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_CTS )) {/* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ up->port.status |=UPSTAT_AUTOCTS |UPSTAT_AUTORTS ; priv->efr |=UART_EFR_CTS ;Looks good to me but !up->gpios must remain as otherwise, we will get NULL pointer dereference. What do you think?
I was not seeing
up->gpiosever NULL so the contents inside the check never was executed. When I removed the check, the performance came back. I looked at examples on how other devices checked for RTS and CTS, and I noticed that the Atmel serial driver did something like the above.Quoted 1 line
Quoted 5 lines
Quoted 1 line
Also adding some more people who can be interested in testing this approach.
I am open for ideas. If something is better, but something is either incorrectly setting
up->gpiosto non-NULL or the check for non-NULL is wrong.
I wonder whether we forgot to add this assignment for the ACPI systems:
(quoted diff) +0 -0
b/drivers/tty/serial/8250/8250_core.c
index e682390..d5fdb71 100644
drivers/tty/serial/8250/8250_core.c +0 -0
@@ -1031,6 +1031,8 @@ int serial8250_register_8250_port(struct
uart_8250_port *up)
} else {
uart->gpios = gpios;
}
+ } else {
+ uart->gpios = NULL;
}
serial8250_set_defaults(uart);Quoted 29 lines · Yegor Yefremov
drivers/tty/serial/8250/8250_core.c
Quoted 15 lines · Adam Ford
Quoted 11 lines · Yegor Yefremov
Hi Adam,
Quoted 7 lines · Adam Ford
There are two checks to see if the manual gpio is configured, but these the check is seeing if the structure is NULL instead it should check to see if there are CTS and/or RTS pins defined.
This patch uses checks for those individual pins instead of checking for the structure itself.
drivers/tty/serial/8250/8250_core.c +0
-0index e682390..d5fdb71 100644
drivers/tty/serial/8250/8250_core.c +2
-0@@ -1031,6 +1031,8 @@ int serial8250_register_8250_port(struct uart_8250_port *up) }else { uart->gpios = gpios; } + }else { + uart->gpios =NULL ; }
Quoted 30 lines
serial8250_set_defaults(uart);Quoted 29 lines
Quoted 29 lines
Quoted 17 lines
Signed-off-by Adam Ford <[email protected]>drivers/tty/serial/8250/8250_omap.c +1
-1@@ -141,7 +141,7 @@ static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)serial8250_do_set_mctrl (port, mctrl); -if (!up->gpios) { +if (!mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS )) {/* * Turn off autoRTS if RTS is lowered and restore autoRTS * setting if RTS is raised drivers/tty/serial/8250/8250_omap.c static void omap_8250_set_termios(struct uart_port *port, · line 463
Quoted 9 lines
drivers/tty/serial/8250/8250_omap.c +2
-1@@ -456,7 +456,8 @@ static void omap_8250_set_termios(struct uart_port *port, up->port.status &= ~(UPSTAT_AUTOCTS |UPSTAT_AUTORTS |UPSTAT_AUTOXOFF );if (termios->c_cflag &CRTSCTS && up->port.flags &UPF_HARD_FLOW && - !up->gpios) { + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS ) && + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_CTS )) {/* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ up->port.status |=UPSTAT_AUTOCTS |UPSTAT_AUTORTS ; priv->efr |=UART_EFR_CTS ;Looks good to me but !up->gpios must remain as otherwise, we will get NULL pointer dereference. What do you think?
What we if add a check to make sure we deference it? I was thinking something like:
(quoted diff) +0 -0
b/drivers/tty/serial/serial_mctrl_gpio.c
index d9074303c88e..fb4781292d40 100644
drivers/tty/serial/serial_mctrl_gpio.c +3 -0
@@ -66,6 +66,9 @@ EXPORT_SYMBOL_GPL(mctrl_gpio_set);struct gpio_desc *mctrl_gpio_to_gpiod (struct mctrl_gpios *gpios,enum mctrl_gpio_idx gidx) { +if (gpios ==NULL ) +return NULL ; +return gpios->gpio[gidx]; }EXPORT_SYMBOL_GPL (mctrl_gpio_to_gpiod);
This should make my previous patch tolerate situations where gpios is NULL. It also explictly looks for conditions where the gpios are manually configured for RTS and/or CTS.
Quoted 8 lines
Quoted 8 lines
I was not seeing
up->gpiosever NULL so the contents inside the check never was executed. When I removed the check, the performance came back. I looked at examples on how other devices checked for RTS and CTS, and I noticed that the Atmel serial driver did something like the above.Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Also adding some more people who can be interested in testing this approach.
I am open for ideas. If something is better, but something is either incorrectly setting
up->gpiosto non-NULL or the check for non-NULL is wrong.I wonder whether we forgot to add this assignment for the ACPI systems:
I unwound my patch and applied your patch instead, but it is back to having corrupt frames again.
Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +0
-0
drivers/tty/serial/8250/8250_core.c int serial8250_register_8250_port(struct · line 1038
Quoted 8 lines
drivers/tty/serial/8250/8250_core.c +2
-0@@ -1031,6 +1031,8 @@ int serial8250_register_8250_port(struct uart_8250_port *up) }else { uart->gpios = gpios; } + }else { + uart->gpios =NULL ; }
I did not check the value of uart->gpios after this patch, but since the flow control code isn't executing, I am guessing it's still not NULL.
Quoted 1 line
serial8250_set_defaults(uart);
adam
Quoted 82 lines · Adam Ford
Quoted 29 lines · Yegor Yefremov
drivers/tty/serial/8250/8250_core.c
Quoted 15 lines · Adam Ford
Quoted 11 lines · Yegor Yefremov
Hi Adam,
Quoted 7 lines · Adam Ford
There are two checks to see if the manual gpio is configured, but these the check is seeing if the structure is NULL instead it should check to see if there are CTS and/or RTS pins defined.
This patch uses checks for those individual pins instead of checking for the structure itself.
drivers/tty/serial/8250/8250_core.c +0
-0index e682390..d5fdb71 100644
drivers/tty/serial/8250/8250_core.c +2
-0@@ -1031,6 +1031,8 @@ int serial8250_register_8250_port(struct uart_8250_port *up) }else { uart->gpios = gpios; } + }else { + uart->gpios =NULL ; }Quoted 30 lines
serial8250_set_defaults(uart);Quoted 29 lines
Quoted 29 lines
Quoted 17 lines
Signed-off-by Adam Ford <[email protected]>drivers/tty/serial/8250/8250_omap.c +1
-1@@ -141,7 +141,7 @@ static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)serial8250_do_set_mctrl (port, mctrl); -if (!up->gpios) { +if (!mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS )) {/* * Turn off autoRTS if RTS is lowered and restore autoRTS * setting if RTS is raised drivers/tty/serial/8250/8250_omap.c static void omap_8250_set_termios(struct uart_port *port, · line 463
Quoted 9 lines
drivers/tty/serial/8250/8250_omap.c +2
-1@@ -456,7 +456,8 @@ static void omap_8250_set_termios(struct uart_port *port, up->port.status &= ~(UPSTAT_AUTOCTS |UPSTAT_AUTORTS |UPSTAT_AUTOXOFF );if (termios->c_cflag &CRTSCTS && up->port.flags &UPF_HARD_FLOW && - !up->gpios) { + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_RTS ) && + !mctrl_gpio_to_gpiod (up->gpios,UART_GPIO_CTS )) {/* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ up->port.status |=UPSTAT_AUTOCTS |UPSTAT_AUTORTS ; priv->efr |=UART_EFR_CTS ;Looks good to me but !up->gpios must remain as otherwise, we will get NULL pointer dereference. What do you think?
What we if add a check to make sure we deference it? I was thinking something like:
drivers/tty/serial/serial_mctrl_gpio.c +3
-0@@ -66,6 +66,9 @@ EXPORT_SYMBOL_GPL(mctrl_gpio_set);struct gpio_desc *mctrl_gpio_to_gpiod (struct mctrl_gpios *gpios,enum mctrl_gpio_idx gidx) { +if (gpios ==NULL ) +return NULL ; +return gpios->gpio[gidx]; }EXPORT_SYMBOL_GPL (mctrl_gpio_to_gpiod);
Quoted 3 lines
This should make my previous patch tolerate situations where gpios is NULL. It also explictly looks for conditions where the gpios are manually configured for RTS and/or CTS.
I like this idea. This would solve my concern.
Yegor
Quoted 40 lines
Quoted 8 lines
Quoted 8 lines
I was not seeing
up->gpiosever NULL so the contents inside the check never was executed. When I removed the check, the performance came back. I looked at examples on how other devices checked for RTS and CTS, and I noticed that the Atmel serial driver did something like the above.Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Also adding some more people who can be interested in testing this approach.
I am open for ideas. If something is better, but something is either incorrectly setting
up->gpiosto non-NULL or the check for non-NULL is wrong.I wonder whether we forgot to add this assignment for the ACPI systems:
I unwound my patch and applied your patch instead, but it is back to having corrupt frames again.
Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +0
-0drivers/tty/serial/8250/8250_core.c int serial8250_register_8250_port(struct · line 1038
Quoted 8 lines
drivers/tty/serial/8250/8250_core.c +2
-0@@ -1031,6 +1031,8 @@ int serial8250_register_8250_port(struct uart_8250_port *up) }else { uart->gpios = gpios; } + }else { + uart->gpios =NULL ; }I did not check the value of
uart->gpiosafter this patch, but since the flow control code isn't executing, I am guessing it's still not NULL.Quoted 1 line
serial8250_set_defaults(uart);adam