aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/kl5kusb105.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/kl5kusb105.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/kl5kusb105.c')
-rw-r--r--drivers/usb/serial/kl5kusb105.c74
1 files changed, 43 insertions, 31 deletions
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 79787eda9524..4a38ec8f5fe3 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -74,29 +74,33 @@ static int debug;
74 */ 74 */
75static int klsi_105_startup (struct usb_serial *serial); 75static int klsi_105_startup (struct usb_serial *serial);
76static void klsi_105_shutdown (struct usb_serial *serial); 76static void klsi_105_shutdown (struct usb_serial *serial);
77static int klsi_105_open (struct usb_serial_port *port, 77static int klsi_105_open (struct tty_struct *tty,
78 struct usb_serial_port *port,
78 struct file *filp); 79 struct file *filp);
79static void klsi_105_close (struct usb_serial_port *port, 80static void klsi_105_close (struct tty_struct *tty,
81 struct usb_serial_port *port,
80 struct file *filp); 82 struct file *filp);
81static int klsi_105_write (struct usb_serial_port *port, 83static int klsi_105_write (struct tty_struct *tty,
84 struct usb_serial_port *port,
82 const unsigned char *buf, 85 const unsigned char *buf,
83 int count); 86 int count);
84static void klsi_105_write_bulk_callback (struct urb *urb); 87static void klsi_105_write_bulk_callback (struct urb *urb);
85static int klsi_105_chars_in_buffer (struct usb_serial_port *port); 88static int klsi_105_chars_in_buffer (struct tty_struct *tty);
86static int klsi_105_write_room (struct usb_serial_port *port); 89static int klsi_105_write_room (struct tty_struct *tty);
87 90
88static void klsi_105_read_bulk_callback (struct urb *urb); 91static void klsi_105_read_bulk_callback (struct urb *urb);
89static void klsi_105_set_termios (struct usb_serial_port *port, 92static void klsi_105_set_termios (struct tty_struct *tty,
93 struct usb_serial_port *port,
90 struct ktermios *old); 94 struct ktermios *old);
91static void klsi_105_throttle (struct usb_serial_port *port); 95static void klsi_105_throttle (struct tty_struct *tty);
92static void klsi_105_unthrottle (struct usb_serial_port *port); 96static void klsi_105_unthrottle (struct tty_struct *tty);
93/* 97/*
94static void klsi_105_break_ctl (struct usb_serial_port *port, 98static void klsi_105_break_ctl (struct tty_struct *tty,
95 int break_state ); 99 int break_state );
96 */ 100 */
97static int klsi_105_tiocmget (struct usb_serial_port *port, 101static int klsi_105_tiocmget (struct tty_struct *tty,
98 struct file *file); 102 struct file *file);
99static int klsi_105_tiocmset (struct usb_serial_port *port, 103static int klsi_105_tiocmset (struct tty_struct *tty,
100 struct file *file, unsigned int set, 104 struct file *file, unsigned int set,
101 unsigned int clear); 105 unsigned int clear);
102 106
@@ -361,7 +365,8 @@ static void klsi_105_shutdown (struct usb_serial *serial)
361 } 365 }
362} /* klsi_105_shutdown */ 366} /* klsi_105_shutdown */
363 367
364static int klsi_105_open (struct usb_serial_port *port, struct file *filp) 368static int klsi_105_open(struct tty_struct *tty,
369 struct usb_serial_port *port, struct file *filp)
365{ 370{
366 struct klsi_105_private *priv = usb_get_serial_port_data(port); 371 struct klsi_105_private *priv = usb_get_serial_port_data(port);
367 int retval = 0; 372 int retval = 0;
@@ -375,7 +380,7 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
375 380
376 /* force low_latency on so that our tty_push actually forces 381 /* force low_latency on so that our tty_push actually forces
377 * the data through 382 * the data through
378 * port->tty->low_latency = 1; */ 383 * tty->low_latency = 1; */
379 384
380 /* Do a defined restart: 385 /* Do a defined restart:
381 * Set up sane default baud rate and send the 'READ_ON' 386 * Set up sane default baud rate and send the 'READ_ON'
@@ -393,12 +398,12 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
393 398
394 /* set up termios structure */ 399 /* set up termios structure */
395 spin_lock_irqsave (&priv->lock, flags); 400 spin_lock_irqsave (&priv->lock, flags);
396 priv->termios.c_iflag = port->tty->termios->c_iflag; 401 priv->termios.c_iflag = tty->termios->c_iflag;
397 priv->termios.c_oflag = port->tty->termios->c_oflag; 402 priv->termios.c_oflag = tty->termios->c_oflag;
398 priv->termios.c_cflag = port->tty->termios->c_cflag; 403 priv->termios.c_cflag = tty->termios->c_cflag;
399 priv->termios.c_lflag = port->tty->termios->c_lflag; 404 priv->termios.c_lflag = tty->termios->c_lflag;
400 for (i=0; i<NCCS; i++) 405 for (i=0; i<NCCS; i++)
401 priv->termios.c_cc[i] = port->tty->termios->c_cc[i]; 406 priv->termios.c_cc[i] = tty->termios->c_cc[i];
402 priv->cfg.pktlen = cfg.pktlen; 407 priv->cfg.pktlen = cfg.pktlen;
403 priv->cfg.baudrate = cfg.baudrate; 408 priv->cfg.baudrate = cfg.baudrate;
404 priv->cfg.databits = cfg.databits; 409 priv->cfg.databits = cfg.databits;
@@ -452,7 +457,8 @@ exit:
452} /* klsi_105_open */ 457} /* klsi_105_open */
453 458
454 459
455static void klsi_105_close (struct usb_serial_port *port, struct file *filp) 460static void klsi_105_close(struct tty_struct *tty,
461 struct usb_serial_port *port, struct file *filp)
456{ 462{
457 struct klsi_105_private *priv = usb_get_serial_port_data(port); 463 struct klsi_105_private *priv = usb_get_serial_port_data(port);
458 int rc; 464 int rc;
@@ -493,8 +499,8 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
493#define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */ 499#define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
494 500
495 501
496static int klsi_105_write (struct usb_serial_port *port, 502static int klsi_105_write(struct tty_struct *tty,
497 const unsigned char *buf, int count) 503 struct usb_serial_port *port, const unsigned char *buf, int count)
498{ 504{
499 struct klsi_105_private *priv = usb_get_serial_port_data(port); 505 struct klsi_105_private *priv = usb_get_serial_port_data(port);
500 int result, size; 506 int result, size;
@@ -584,8 +590,9 @@ static void klsi_105_write_bulk_callback ( struct urb *urb)
584 590
585 591
586/* return number of characters currently in the writing process */ 592/* return number of characters currently in the writing process */
587static int klsi_105_chars_in_buffer (struct usb_serial_port *port) 593static int klsi_105_chars_in_buffer (struct tty_struct *tty)
588{ 594{
595 struct usb_serial_port *port = tty->driver_data;
589 int chars = 0; 596 int chars = 0;
590 int i; 597 int i;
591 unsigned long flags; 598 unsigned long flags;
@@ -605,8 +612,9 @@ static int klsi_105_chars_in_buffer (struct usb_serial_port *port)
605 return (chars); 612 return (chars);
606} 613}
607 614
608static int klsi_105_write_room (struct usb_serial_port *port) 615static int klsi_105_write_room (struct tty_struct *tty)
609{ 616{
617 struct usb_serial_port *port = tty->driver_data;
610 unsigned long flags; 618 unsigned long flags;
611 int i; 619 int i;
612 int room = 0; 620 int room = 0;
@@ -660,7 +668,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
660 } else { 668 } else {
661 int bytes_sent = ((__u8 *) data)[0] + 669 int bytes_sent = ((__u8 *) data)[0] +
662 ((unsigned int) ((__u8 *) data)[1] << 8); 670 ((unsigned int) ((__u8 *) data)[1] << 8);
663 tty = port->tty; 671 tty = port->port.tty;
664 /* we should immediately resubmit the URB, before attempting 672 /* we should immediately resubmit the URB, before attempting
665 * to pass the data on to the tty layer. But that needs locking 673 * to pass the data on to the tty layer. But that needs locking
666 * against re-entry an then mixed-up data because of 674 * against re-entry an then mixed-up data because of
@@ -699,11 +707,11 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
699} /* klsi_105_read_bulk_callback */ 707} /* klsi_105_read_bulk_callback */
700 708
701 709
702static void klsi_105_set_termios (struct usb_serial_port *port, 710static void klsi_105_set_termios (struct tty_struct *tty,
711 struct usb_serial_port *port,
703 struct ktermios *old_termios) 712 struct ktermios *old_termios)
704{ 713{
705 struct klsi_105_private *priv = usb_get_serial_port_data(port); 714 struct klsi_105_private *priv = usb_get_serial_port_data(port);
706 struct tty_struct *tty = port->tty;
707 unsigned int iflag = tty->termios->c_iflag; 715 unsigned int iflag = tty->termios->c_iflag;
708 unsigned int old_iflag = old_termios->c_iflag; 716 unsigned int old_iflag = old_termios->c_iflag;
709 unsigned int cflag = tty->termios->c_cflag; 717 unsigned int cflag = tty->termios->c_cflag;
@@ -863,8 +871,9 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
863 871
864 872
865#if 0 873#if 0
866static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state ) 874static void mct_u232_break_ctl( struct tty_struct *tty, int break_state )
867{ 875{
876 struct usb_serial_port *port = tty->driver_data;
868 struct usb_serial *serial = port->serial; 877 struct usb_serial *serial = port->serial;
869 struct mct_u232_private *priv = (struct mct_u232_private *)port->private; 878 struct mct_u232_private *priv = (struct mct_u232_private *)port->private;
870 unsigned char lcr = priv->last_lcr; 879 unsigned char lcr = priv->last_lcr;
@@ -878,8 +887,9 @@ static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
878} /* mct_u232_break_ctl */ 887} /* mct_u232_break_ctl */
879#endif 888#endif
880 889
881static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file) 890static int klsi_105_tiocmget (struct tty_struct *tty, struct file *file)
882{ 891{
892 struct usb_serial_port *port = tty->driver_data;
883 struct klsi_105_private *priv = usb_get_serial_port_data(port); 893 struct klsi_105_private *priv = usb_get_serial_port_data(port);
884 unsigned long flags; 894 unsigned long flags;
885 int rc; 895 int rc;
@@ -900,7 +910,7 @@ static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file)
900 return (int)line_state; 910 return (int)line_state;
901} 911}
902 912
903static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file, 913static int klsi_105_tiocmset (struct tty_struct *tty, struct file *file,
904 unsigned int set, unsigned int clear) 914 unsigned int set, unsigned int clear)
905{ 915{
906 int retval = -EINVAL; 916 int retval = -EINVAL;
@@ -929,14 +939,16 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
929 return retval; 939 return retval;
930} 940}
931 941
932static void klsi_105_throttle (struct usb_serial_port *port) 942static void klsi_105_throttle (struct tty_struct *tty)
933{ 943{
944 struct usb_serial_port *port = tty->driver_data;
934 dbg("%s - port %d", __func__, port->number); 945 dbg("%s - port %d", __func__, port->number);
935 usb_kill_urb(port->read_urb); 946 usb_kill_urb(port->read_urb);
936} 947}
937 948
938static void klsi_105_unthrottle (struct usb_serial_port *port) 949static void klsi_105_unthrottle (struct tty_struct *tty)
939{ 950{
951 struct usb_serial_port *port = tty->driver_data;
940 int result; 952 int result;
941 953
942 dbg("%s - port %d", __func__, port->number); 954 dbg("%s - port %d", __func__, port->number);