aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/console.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:09:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:22 -0400
commit95da310e66ee8090119596c70ca8432e57f9a97f (patch)
tree7f18c30e9c9ad4d7d53df6453fa338be06f09a85 /drivers/usb/serial/console.c
parent1aa3692da57c773e5c76de55c5c4a953962d360e (diff)
usb_serial: API all change
USB serial likes to use port->tty back pointers for the real work it does and to do so without any actual locking. Unfortunately when you consider hangup events, hangup/parallel reopen or even worse hangup followed by parallel close events the tty->port and port->tty pointers are not guaranteed to be the same as port->tty is the active tty while tty->port is the port the tty may or may not still be attached to. So rework the entire API to pass the tty struct. For console cases we need to pass both for now. This shows up multiple drivers that immediately crash with USB console some of which have been fixed in the process. Longer term we need a proper tty as console abstraction Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb/serial/console.c')
-rw-r--r--drivers/usb/serial/console.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 201184c3fb87..940f5de68980 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -145,12 +145,12 @@ static int usb_console_setup(struct console *co, char *options)
145 } 145 }
146 146
147 port = serial->port[0]; 147 port = serial->port[0];
148 port->tty = NULL; 148 port->port.tty = NULL;
149 149
150 info->port = port; 150 info->port = port;
151 151
152 ++port->open_count; 152 ++port->port.count;
153 if (port->open_count == 1) { 153 if (port->port.count == 1) {
154 if (serial->type->set_termios) { 154 if (serial->type->set_termios) {
155 /* 155 /*
156 * allocate a fake tty so the driver can initialize 156 * allocate a fake tty so the driver can initialize
@@ -171,15 +171,15 @@ static int usb_console_setup(struct console *co, char *options)
171 } 171 }
172 memset(&dummy, 0, sizeof(struct ktermios)); 172 memset(&dummy, 0, sizeof(struct ktermios));
173 tty->termios = termios; 173 tty->termios = termios;
174 port->tty = tty; 174 port->port.tty = tty;
175 } 175 }
176 176
177 /* only call the device specific open if this 177 /* only call the device specific open if this
178 * is the first time the port is opened */ 178 * is the first time the port is opened */
179 if (serial->type->open) 179 if (serial->type->open)
180 retval = serial->type->open(port, NULL); 180 retval = serial->type->open(NULL, port, NULL);
181 else 181 else
182 retval = usb_serial_generic_open(port, NULL); 182 retval = usb_serial_generic_open(NULL, port, NULL);
183 183
184 if (retval) { 184 if (retval) {
185 err("could not open USB console port"); 185 err("could not open USB console port");
@@ -188,9 +188,9 @@ static int usb_console_setup(struct console *co, char *options)
188 188
189 if (serial->type->set_termios) { 189 if (serial->type->set_termios) {
190 termios->c_cflag = cflag; 190 termios->c_cflag = cflag;
191 serial->type->set_termios(port, &dummy); 191 serial->type->set_termios(NULL, port, &dummy);
192 192
193 port->tty = NULL; 193 port->port.tty = NULL;
194 kfree(termios); 194 kfree(termios);
195 kfree(tty); 195 kfree(tty);
196 } 196 }
@@ -203,11 +203,11 @@ out:
203 return retval; 203 return retval;
204free_termios: 204free_termios:
205 kfree(termios); 205 kfree(termios);
206 port->tty = NULL; 206 port->port.tty = NULL;
207free_tty: 207free_tty:
208 kfree(tty); 208 kfree(tty);
209reset_open_count: 209reset_open_count:
210 port->open_count = 0; 210 port->port.count = 0;
211goto out; 211goto out;
212} 212}
213 213
@@ -227,7 +227,7 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
227 227
228 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 228 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
229 229
230 if (!port->open_count) { 230 if (!port->port.count) {
231 dbg ("%s - port not opened", __func__); 231 dbg ("%s - port not opened", __func__);
232 return; 232 return;
233 } 233 }
@@ -245,17 +245,17 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
245 } 245 }
246 /* pass on to the driver specific version of this function if it is available */ 246 /* pass on to the driver specific version of this function if it is available */
247 if (serial->type->write) 247 if (serial->type->write)
248 retval = serial->type->write(port, buf, i); 248 retval = serial->type->write(NULL, port, buf, i);
249 else 249 else
250 retval = usb_serial_generic_write(port, buf, i); 250 retval = usb_serial_generic_write(NULL, port, buf, i);
251 dbg("%s - return value : %d", __func__, retval); 251 dbg("%s - return value : %d", __func__, retval);
252 if (lf) { 252 if (lf) {
253 /* append CR after LF */ 253 /* append CR after LF */
254 unsigned char cr = 13; 254 unsigned char cr = 13;
255 if (serial->type->write) 255 if (serial->type->write)
256 retval = serial->type->write(port, &cr, 1); 256 retval = serial->type->write(NULL, port, &cr, 1);
257 else 257 else
258 retval = usb_serial_generic_write(port, &cr, 1); 258 retval = usb_serial_generic_write(NULL, port, &cr, 1);
259 dbg("%s - return value : %d", __func__, retval); 259 dbg("%s - return value : %d", __func__, retval);
260 } 260 }
261 buf += i; 261 buf += i;
@@ -306,8 +306,8 @@ void usb_serial_console_exit (void)
306{ 306{
307 if (usbcons_info.port) { 307 if (usbcons_info.port) {
308 unregister_console(&usbcons); 308 unregister_console(&usbcons);
309 if (usbcons_info.port->open_count) 309 if (usbcons_info.port->port.count)
310 usbcons_info.port->open_count--; 310 usbcons_info.port->port.count--;
311 usbcons_info.port = NULL; 311 usbcons_info.port = NULL;
312 } 312 }
313} 313}