|
16 | 16 | #include <linux/slab.h>
|
17 | 17 | #include <linux/tty.h>
|
18 | 18 | #include <linux/console.h>
|
| 19 | +#include <linux/serial.h> |
19 | 20 | #include <linux/usb.h>
|
20 | 21 | #include <linux/usb/serial.h>
|
21 | 22 |
|
@@ -63,7 +64,7 @@ static int usb_console_setup(struct console *co, char *options)
|
63 | 64 | char *s;
|
64 | 65 | struct usb_serial *serial;
|
65 | 66 | struct usb_serial_port *port;
|
66 |
| - int retval = 0; |
| 67 | + int retval; |
67 | 68 | struct tty_struct *tty = NULL;
|
68 | 69 | struct ktermios *termios = NULL, dummy;
|
69 | 70 |
|
@@ -116,13 +117,17 @@ static int usb_console_setup(struct console *co, char *options)
|
116 | 117 | return -ENODEV;
|
117 | 118 | }
|
118 | 119 |
|
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]; |
120 | 125 | tty_port_tty_set(&port->port, NULL);
|
121 | 126 |
|
122 | 127 | info->port = port;
|
123 | 128 |
|
124 | 129 | ++port->port.count;
|
125 |
| - if (port->port.count == 1) { |
| 130 | + if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) { |
126 | 131 | if (serial->type->set_termios) {
|
127 | 132 | /*
|
128 | 133 | * allocate a fake tty so the driver can initialize
|
@@ -168,25 +173,30 @@ static int usb_console_setup(struct console *co, char *options)
|
168 | 173 | kfree(termios);
|
169 | 174 | kfree(tty);
|
170 | 175 | }
|
| 176 | + set_bit(ASYNCB_INITIALIZED, &port->port.flags); |
171 | 177 | }
|
172 | 178 | /* Now that any required fake tty operations are completed restore
|
173 | 179 | * the tty port count */
|
174 | 180 | --port->port.count;
|
175 | 181 | /* The console is special in terms of closing the device so
|
176 | 182 | * indicate this port is now acting as a system console. */
|
177 | 183 | port->console = 1;
|
178 |
| - retval = 0; |
179 | 184 |
|
180 |
| -out: |
| 185 | + mutex_unlock(&serial->disc_mutex); |
181 | 186 | return retval;
|
182 |
| -free_termios: |
| 187 | + |
| 188 | + free_termios: |
183 | 189 | kfree(termios);
|
184 | 190 | tty_port_tty_set(&port->port, NULL);
|
185 |
| -free_tty: |
| 191 | + free_tty: |
186 | 192 | kfree(tty);
|
187 |
| -reset_open_count: |
| 193 | + reset_open_count: |
188 | 194 | 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; |
190 | 200 | }
|
191 | 201 |
|
192 | 202 | static void usb_console_write(struct console *co,
|
|
0 commit comments