Skip to content

Commit 7bd032d

Browse files
AlanSternLive-CD User
authored andcommitted
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>
1 parent 320348c commit 7bd032d

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

drivers/usb/serial/console.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/slab.h>
1717
#include <linux/tty.h>
1818
#include <linux/console.h>
19+
#include <linux/serial.h>
1920
#include <linux/usb.h>
2021
#include <linux/usb/serial.h>
2122

@@ -63,7 +64,7 @@ static int usb_console_setup(struct console *co, char *options)
6364
char *s;
6465
struct usb_serial *serial;
6566
struct usb_serial_port *port;
66-
int retval = 0;
67+
int retval;
6768
struct tty_struct *tty = NULL;
6869
struct ktermios *termios = NULL, dummy;
6970

@@ -116,13 +117,17 @@ static int usb_console_setup(struct console *co, char *options)
116117
return -ENODEV;
117118
}
118119

119-
port = serial->port[0];
120+
retval = usb_autopm_get_interface(serial->interface);
121+
if (retval)
122+
goto error_get_interface;
123+
124+
port = serial->port[co->index - serial->minor];
120125
tty_port_tty_set(&port->port, NULL);
121126

122127
info->port = port;
123128

124129
++port->port.count;
125-
if (port->port.count == 1) {
130+
if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
126131
if (serial->type->set_termios) {
127132
/*
128133
* allocate a fake tty so the driver can initialize
@@ -168,25 +173,30 @@ static int usb_console_setup(struct console *co, char *options)
168173
kfree(termios);
169174
kfree(tty);
170175
}
176+
set_bit(ASYNCB_INITIALIZED, &port->port.flags);
171177
}
172178
/* Now that any required fake tty operations are completed restore
173179
* the tty port count */
174180
--port->port.count;
175181
/* The console is special in terms of closing the device so
176182
* indicate this port is now acting as a system console. */
177183
port->console = 1;
178-
retval = 0;
179184

180-
out:
185+
mutex_unlock(&serial->disc_mutex);
181186
return retval;
182-
free_termios:
187+
188+
free_termios:
183189
kfree(termios);
184190
tty_port_tty_set(&port->port, NULL);
185-
free_tty:
191+
free_tty:
186192
kfree(tty);
187-
reset_open_count:
193+
reset_open_count:
188194
port->port.count = 0;
189-
goto out;
195+
usb_autopm_put_interface(serial->interface);
196+
error_get_interface:
197+
usb_serial_put(serial);
198+
mutex_unlock(&serial->disc_mutex);
199+
return retval;
190200
}
191201

192202
static void usb_console_write(struct console *co,

0 commit comments

Comments
 (0)