Skip to content

Commit 12c91ce

Browse files
tony-lindgrengregkh
authored andcommitted
serial: core: Add serial_base_match_and_update_preferred_console()
Let's add serial_base_match_and_update_preferred_console() for consoles using DEVNAME:0.0 style naming. The earlier approach to add it caused issues in the kernel command line ordering as we were calling __add_preferred_console() again for the deferred consoles. Signed-off-by: Tony Lindgren <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Tested-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7640f1a commit 12c91ce

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

drivers/tty/serial/serial_base.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,19 @@ void serial_ctrl_unregister_port(struct uart_driver *drv, struct uart_port *port
4949

5050
int serial_core_register_port(struct uart_driver *drv, struct uart_port *port);
5151
void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port);
52+
53+
#ifdef CONFIG_SERIAL_CORE_CONSOLE
54+
55+
int serial_base_match_and_update_preferred_console(struct uart_driver *drv,
56+
struct uart_port *port);
57+
58+
#else
59+
60+
static inline
61+
int serial_base_match_and_update_preferred_console(struct uart_driver *drv,
62+
struct uart_port *port)
63+
{
64+
return 0;
65+
}
66+
67+
#endif

drivers/tty/serial/serial_base_bus.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* The serial core bus manages the serial core controller instances.
99
*/
1010

11+
#include <linux/cleanup.h>
1112
#include <linux/container_of.h>
1213
#include <linux/device.h>
1314
#include <linux/idr.h>
@@ -204,6 +205,42 @@ void serial_base_port_device_remove(struct serial_port_device *port_dev)
204205
put_device(&port_dev->dev);
205206
}
206207

208+
#ifdef CONFIG_SERIAL_CORE_CONSOLE
209+
210+
/**
211+
* serial_base_match_and_update_preferred_console - Match and update a preferred console
212+
* @drv: Serial port device driver
213+
* @port: Serial port instance
214+
*
215+
* Tries to match and update the preferred console for a serial port for
216+
* the kernel command line option console=DEVNAME:0.0.
217+
*
218+
* Cannot be called early for ISA ports, depends on struct device.
219+
*
220+
* Return: 0 on success, negative error code on failure.
221+
*/
222+
int serial_base_match_and_update_preferred_console(struct uart_driver *drv,
223+
struct uart_port *port)
224+
{
225+
const char *port_match __free(kfree) = NULL;
226+
int ret;
227+
228+
port_match = kasprintf(GFP_KERNEL, "%s:%d.%d", dev_name(port->dev),
229+
port->ctrl_id, port->port_id);
230+
if (!port_match)
231+
return -ENOMEM;
232+
233+
ret = match_devname_and_update_preferred_console(port_match,
234+
drv->dev_name,
235+
port->line);
236+
if (ret == -ENOENT)
237+
return 0;
238+
239+
return ret;
240+
}
241+
242+
#endif
243+
207244
static int serial_base_init(void)
208245
{
209246
int ret;

drivers/tty/serial/serial_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,6 +3422,10 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
34223422
if (ret)
34233423
goto err_unregister_ctrl_dev;
34243424

3425+
ret = serial_base_match_and_update_preferred_console(drv, port);
3426+
if (ret)
3427+
goto err_unregister_port_dev;
3428+
34253429
ret = serial_core_add_one_port(drv, port);
34263430
if (ret)
34273431
goto err_unregister_port_dev;

0 commit comments

Comments
 (0)