Skip to contentSkip to conversation

serial: sh-sci: prevent setup of uninitialized serial console

PATCH In review Alexandre Courbot 2 participants 2 messages Feb 9, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: sh-sci: prevent setup of uninitialized serial console

Commit 906b17dc089f7fa87e37a9cfe6ee185efc90e0da introduced a condition where the kernel will crash unless a earlyprintk parameter is specified.

Without this parameter, sci_console_init is called during early console setup without any port being initialized, and the kernel crashes a little bit later when uart_set_options attemps to invoke set_termios on a port with an ops member equal to NULL.

This patch just checks in sci_console_init that the port is properly initialized, and aborts the early console setup if it is not.

---
 drivers/tty/serial/sh-sci.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/tty/serial/sh-sci.c +6 -0
index 0257fd5..e180bc9 100644
@@ -1830,6 +1830,12 @@ static int __devinit serial_console_setup(struct console *co, char *options)
 	sci_port = &sci_ports[co->index];
 	port = &sci_port->port;
 
+	/*
+	 * Refuse to handle uninitialized ports.
+	 */
+	if (!port->ops)
+		return -ENODEV;
+
 	ret = sci_remap_port(port);
 	if (unlikely(ret != 0))
 		return ret;
Signature · 1 line
1.7.4
#1 lore raw
Quoted 8 lines · Alexandre Courbot

Commit 906b17dc089f7fa87e37a9cfe6ee185efc90e0da introduced a condition where the kernel will crash unless a earlyprintk parameter is specified.

Without this parameter, sci_console_init is called during early console setup without any port being initialized, and the kernel crashes a little bit later when uart_set_options attemps to invoke set_termios on a port with an ops member equal to NULL.

Quoted 4 lines

This patch just checks in sci_console_init that the port is properly initialized, and aborts the early console setup if it is not.

Looks good. Applied, thanks.