Skip to content

Commit 22a82fa

Browse files
Helmut Grohnegregkh
authored andcommitted
tty: xilinx_uartps: Really fix id assignment
The problems started with the revert (18cc7ac). The cdns_uart_console.index is statically assigned -1. When the port is registered, Linux assigns consecutive numbers to it. It turned out that when using ttyPS1 as console, the index is not updated as we are reusing the same cdns_uart_console instance for multiple ports. When registering ttyPS0, it gets updated from -1 to 0, but when registering ttyPS1, it already is 0 and not updated. That led to 2ae11c4. It assigns the index prior to registering the uart_driver once. Unfortunately, that ended up breaking the situation where the probe order does not match the id order. When using the same device tree for both uboot and linux, it is important that the serial0 alias points to the console. So some boards reverse those aliases. This was reported by Jan Kiszka. The proposed fix was reverting the index assignment and going back to the previous iteration. However such a reversed assignement (serial0 -> uart1, serial1 -> uart0) was already partially broken by the revert (18cc7ac). While the ttyPS device works, the kmsg connection is already broken and kernel messages go missing. Reverting the id assignment does not fix this. >From the xilinx_uartps driver pov (after reverting the refactoring commits), there can be only one console. This manifests in static variables console_pprt and cdns_uart_console. These variables are not properly linked and can go out of sync. The cdns_uart_console.index is important for uart_add_one_port. We call that function for each port - one of which hopefully is the console. If it isn't, the CON_ENABLED flag is not set and console_port is cleared. The next cdns_uart_probe call then tries to register the next port using that same cdns_uart_console. It is important that console_port and cdns_uart_console (and its index in particular) stay in sync. The index assignment implemented by Shubhrajyoti Datta is correct in principle. It just may have to happen a second time if the first cdns_uart_probe call didn't encounter the console device. And we shouldn't change the index once the console uart is registered. Reported-by: Shubhrajyoti Datta <[email protected]> Reported-by: Jan Kiszka <[email protected]> Link: https://lore.kernel.org/linux-serial/[email protected]/ Fixes: 18cc7ac ("Revert "serial: uartps: Register own uart console and driver structures"") Fixes: 2ae11c4 ("tty: xilinx_uartps: Fix missing id assignment to the console") Fixes: 76ed2e1 ("Revert "tty: xilinx_uartps: Fix missing id assignment to the console"") Signed-off-by: Helmut Grohne <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/20200713073227.GA3805@laureti-dev Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ce68455 commit 22a82fa

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/tty/serial/xilinx_uartps.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,8 +1580,10 @@ static int cdns_uart_probe(struct platform_device *pdev)
15801580
* If register_console() don't assign value, then console_port pointer
15811581
* is cleanup.
15821582
*/
1583-
if (!console_port)
1583+
if (!console_port) {
1584+
cdns_uart_console.index = id;
15841585
console_port = port;
1586+
}
15851587
#endif
15861588

15871589
rc = uart_add_one_port(&cdns_uart_uart_driver, port);
@@ -1594,8 +1596,10 @@ static int cdns_uart_probe(struct platform_device *pdev)
15941596
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
15951597
/* This is not port which is used for console that's why clean it up */
15961598
if (console_port == port &&
1597-
!(cdns_uart_uart_driver.cons->flags & CON_ENABLED))
1599+
!(cdns_uart_uart_driver.cons->flags & CON_ENABLED)) {
15981600
console_port = NULL;
1601+
cdns_uart_console.index = -1;
1602+
}
15991603
#endif
16001604

16011605
cdns_uart_data->cts_override = of_property_read_bool(pdev->dev.of_node,

0 commit comments

Comments
 (0)