aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/ir-usb.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/ir-usb.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/ir-usb.c')
-rw-r--r--drivers/usb/serial/ir-usb.c81
1 files changed, 33 insertions, 48 deletions
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 0063c11c8081..e59155c6607d 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -85,15 +85,17 @@ static int buffer_size;
85/* if overridden by the user, then use the specified number of XBOFs */ 85/* if overridden by the user, then use the specified number of XBOFs */
86static int xbof = -1; 86static int xbof = -1;
87 87
88static int ir_startup(struct usb_serial *serial); 88static int ir_startup (struct usb_serial *serial);
89static int ir_open(struct usb_serial_port *port, struct file *filep); 89static int ir_open(struct tty_struct *tty, struct usb_serial_port *port,
90static void ir_close(struct usb_serial_port *port, struct file *filep); 90 struct file *filep);
91static int ir_write(struct usb_serial_port *port, 91static void ir_close(struct tty_struct *tty, struct usb_serial_port *port,
92 const unsigned char *buf, int count); 92 struct file *filep);
93static void ir_write_bulk_callback(struct urb *urb); 93static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
94static void ir_read_bulk_callback(struct urb *urb); 94 const unsigned char *buf, int count);
95static void ir_set_termios(struct usb_serial_port *port, 95static void ir_write_bulk_callback (struct urb *urb);
96 struct ktermios *old_termios); 96static void ir_read_bulk_callback (struct urb *urb);
97static void ir_set_termios(struct tty_struct *tty,
98 struct usb_serial_port *port, struct ktermios *old_termios);
97 99
98/* Not that this lot means you can only have one per system */ 100/* Not that this lot means you can only have one per system */
99static u8 ir_baud; 101static u8 ir_baud;
@@ -295,7 +297,8 @@ static int ir_startup(struct usb_serial *serial)
295 return 0; 297 return 0;
296} 298}
297 299
298static int ir_open(struct usb_serial_port *port, struct file *filp) 300static int ir_open(struct tty_struct *tty,
301 struct usb_serial_port *port, struct file *filp)
299{ 302{
300 char *buffer; 303 char *buffer;
301 int result = 0; 304 int result = 0;
@@ -343,7 +346,8 @@ static int ir_open(struct usb_serial_port *port, struct file *filp)
343 return result; 346 return result;
344} 347}
345 348
346static void ir_close(struct usb_serial_port *port, struct file *filp) 349static void ir_close(struct tty_struct *tty,
350 struct usb_serial_port *port, struct file * filp)
347{ 351{
348 dbg("%s - port %d", __func__, port->number); 352 dbg("%s - port %d", __func__, port->number);
349 353
@@ -351,8 +355,8 @@ static void ir_close(struct usb_serial_port *port, struct file *filp)
351 usb_kill_urb(port->read_urb); 355 usb_kill_urb(port->read_urb);
352} 356}
353 357
354static int ir_write(struct usb_serial_port *port, 358static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
355 const unsigned char *buf, int count) 359 const unsigned char *buf, int count)
356{ 360{
357 unsigned char *transfer_buffer; 361 unsigned char *transfer_buffer;
358 int result; 362 int result;
@@ -360,11 +364,6 @@ static int ir_write(struct usb_serial_port *port,
360 364
361 dbg("%s - port = %d, count = %d", __func__, port->number, count); 365 dbg("%s - port = %d, count = %d", __func__, port->number, count);
362 366
363 if (!port->tty) {
364 dev_err(&port->dev, "%s - no tty???\n", __func__);
365 return 0;
366 }
367
368 if (count == 0) 367 if (count == 0)
369 return 0; 368 return 0;
370 369
@@ -450,14 +449,13 @@ static void ir_read_bulk_callback(struct urb *urb)
450 449
451 dbg("%s - port %d", __func__, port->number); 450 dbg("%s - port %d", __func__, port->number);
452 451
453 if (!port->open_count) { 452 if (!port->port.count) {
454 dbg("%s - port closed.", __func__); 453 dbg("%s - port closed.", __func__);
455 return; 454 return;
456 } 455 }
457 456
458 switch (status) { 457 switch (status) {
459 case 0: /* Successful */ 458 case 0: /* Successful */
460
461 /* 459 /*
462 * The first byte of the packet we get from the device 460 * The first byte of the packet we get from the device
463 * contains a busy indicator and baud rate change. 461 * contains a busy indicator and baud rate change.
@@ -465,19 +463,11 @@ static void ir_read_bulk_callback(struct urb *urb)
465 */ 463 */
466 if ((*data & 0x0f) > 0) 464 if ((*data & 0x0f) > 0)
467 ir_baud = *data & 0x0f; 465 ir_baud = *data & 0x0f;
468 466 usb_serial_debug_data(debug, &port->dev, __func__,
469 usb_serial_debug_data( 467 urb->actual_length, data);
470 debug, 468 tty = port->port.tty;
471 &port->dev,
472 __func__,
473 urb->actual_length,
474 data);
475
476 tty = port->tty;
477
478 if (tty_buffer_request_room(tty, urb->actual_length - 1)) { 469 if (tty_buffer_request_room(tty, urb->actual_length - 1)) {
479 tty_insert_flip_string(tty, data + 1, 470 tty_insert_flip_string(tty, data+1, urb->actual_length - 1);
480 urb->actual_length - 1);
481 tty_flip_buffer_push(tty); 471 tty_flip_buffer_push(tty);
482 } 472 }
483 473
@@ -488,11 +478,10 @@ static void ir_read_bulk_callback(struct urb *urb)
488 */ 478 */
489 479
490 case -EPROTO: /* taking inspiration from pl2303.c */ 480 case -EPROTO: /* taking inspiration from pl2303.c */
491 481 /* Continue trying to always read */
492 /* Continue trying to always read */
493 usb_fill_bulk_urb( 482 usb_fill_bulk_urb(
494 port->read_urb, 483 port->read_urb,
495 port->serial->dev, 484 port->serial->dev,
496 usb_rcvbulkpipe(port->serial->dev, 485 usb_rcvbulkpipe(port->serial->dev,
497 port->bulk_in_endpointAddress), 486 port->bulk_in_endpointAddress),
498 port->read_urb->transfer_buffer, 487 port->read_urb->transfer_buffer,
@@ -502,23 +491,19 @@ static void ir_read_bulk_callback(struct urb *urb)
502 491
503 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 492 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
504 if (result) 493 if (result)
505 dev_err(&port->dev, 494 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
506 "%s - failed resubmitting read urb, error %d\n",
507 __func__, result); 495 __func__, result);
508 break; 496 break ;
509
510 default: 497 default:
511 dbg("%s - nonzero read bulk status received: %d", 498 dbg("%s - nonzero read bulk status received: %d",
512 __func__, 499 __func__, status);
513 status); 500 break ;
514 break;
515 } 501 }
516
517 return; 502 return;
518} 503}
519 504
520static void ir_set_termios(struct usb_serial_port *port, 505static void ir_set_termios(struct tty_struct *tty,
521 struct ktermios *old_termios) 506 struct usb_serial_port *port, struct ktermios *old_termios)
522{ 507{
523 unsigned char *transfer_buffer; 508 unsigned char *transfer_buffer;
524 int result; 509 int result;
@@ -527,7 +512,7 @@ static void ir_set_termios(struct usb_serial_port *port,
527 512
528 dbg("%s - port %d", __func__, port->number); 513 dbg("%s - port %d", __func__, port->number);
529 514
530 baud = tty_get_baud_rate(port->tty); 515 baud = tty_get_baud_rate(tty);
531 516
532 /* 517 /*
533 * FIXME, we should compare the baud request against the 518 * FIXME, we should compare the baud request against the
@@ -600,8 +585,8 @@ static void ir_set_termios(struct usb_serial_port *port,
600 __func__, result); 585 __func__, result);
601 586
602 /* Only speed changes are supported */ 587 /* Only speed changes are supported */
603 tty_termios_copy_hw(port->tty->termios, old_termios); 588 tty_termios_copy_hw(tty->termios, old_termios);
604 tty_encode_baud_rate(port->tty, baud, baud); 589 tty_encode_baud_rate(tty, baud, baud);
605} 590}
606 591
607static int __init ir_init(void) 592static int __init ir_init(void)