USB serial: update the console driver

This patch (as1292) modifies the USB serial console driver, to make it
compatible with the recent changes to the USB serial core.  The most
important change is that serial->disc_mutex now has to be unlocked
following a successful call to usb_serial_get_by_index().

Other less notable changes include:

	Use the requested port number instead of port 0 always.

	Prevent the serial device from being autosuspended.

	Use the ASYNCB_INITIALIZED flag bit to indicate when the
	port hardware has been initialized.

In spite of these changes, there's no question that the USB serial
console code is still a big hack.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Alan Stern 2009-09-04 15:29:59 -04:00 committed by Live-CD User
parent 320348c8d5
commit 7bd032dc27

View File

@ -16,6 +16,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tty.h> #include <linux/tty.h>
#include <linux/console.h> #include <linux/console.h>
#include <linux/serial.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/serial.h> #include <linux/usb/serial.h>
@ -63,7 +64,7 @@ static int usb_console_setup(struct console *co, char *options)
char *s; char *s;
struct usb_serial *serial; struct usb_serial *serial;
struct usb_serial_port *port; struct usb_serial_port *port;
int retval = 0; int retval;
struct tty_struct *tty = NULL; struct tty_struct *tty = NULL;
struct ktermios *termios = NULL, dummy; struct ktermios *termios = NULL, dummy;
@ -116,13 +117,17 @@ static int usb_console_setup(struct console *co, char *options)
return -ENODEV; return -ENODEV;
} }
port = serial->port[0]; retval = usb_autopm_get_interface(serial->interface);
if (retval)
goto error_get_interface;
port = serial->port[co->index - serial->minor];
tty_port_tty_set(&port->port, NULL); tty_port_tty_set(&port->port, NULL);
info->port = port; info->port = port;
++port->port.count; ++port->port.count;
if (port->port.count == 1) { if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
if (serial->type->set_termios) { if (serial->type->set_termios) {
/* /*
* allocate a fake tty so the driver can initialize * allocate a fake tty so the driver can initialize
@ -168,6 +173,7 @@ static int usb_console_setup(struct console *co, char *options)
kfree(termios); kfree(termios);
kfree(tty); kfree(tty);
} }
set_bit(ASYNCB_INITIALIZED, &port->port.flags);
} }
/* Now that any required fake tty operations are completed restore /* Now that any required fake tty operations are completed restore
* the tty port count */ * the tty port count */
@ -175,18 +181,22 @@ static int usb_console_setup(struct console *co, char *options)
/* The console is special in terms of closing the device so /* The console is special in terms of closing the device so
* indicate this port is now acting as a system console. */ * indicate this port is now acting as a system console. */
port->console = 1; port->console = 1;
retval = 0;
out: mutex_unlock(&serial->disc_mutex);
return retval; return retval;
free_termios:
free_termios:
kfree(termios); kfree(termios);
tty_port_tty_set(&port->port, NULL); tty_port_tty_set(&port->port, NULL);
free_tty: free_tty:
kfree(tty); kfree(tty);
reset_open_count: reset_open_count:
port->port.count = 0; port->port.count = 0;
goto out; usb_autopm_put_interface(serial->interface);
error_get_interface:
usb_serial_put(serial);
mutex_unlock(&serial->disc_mutex);
return retval;
} }
static void usb_console_write(struct console *co, static void usb_console_write(struct console *co,