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>
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index 7b7422f..5a2d045 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -61,12 +61,12 @@
 #define BT_IGNITIONPRO_ID	0x2000  /* This one seems to be a re-branded ZyXEL device */
 
 /* function prototypes */
-static int  omninet_open		(struct usb_serial_port *port, struct file *filp);
-static void omninet_close		(struct usb_serial_port *port, struct file *filp);
+static int  omninet_open		(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
+static void omninet_close		(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
 static void omninet_read_bulk_callback	(struct urb *urb);
 static void omninet_write_bulk_callback	(struct urb *urb);
-static int  omninet_write		(struct usb_serial_port *port, const unsigned char *buf, int count);
-static int  omninet_write_room		(struct usb_serial_port *port);
+static int  omninet_write		(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count);
+static int  omninet_write_room		(struct tty_struct *tty);
 static void omninet_shutdown		(struct usb_serial *serial);
 static int omninet_attach		(struct usb_serial *serial);
 
@@ -157,7 +157,8 @@
 	return 0;
 }
 
-static int omninet_open (struct usb_serial_port *port, struct file *filp)
+static int omninet_open(struct tty_struct *tty,
+			struct usb_serial_port *port, struct file *filp)
 {
 	struct usb_serial	*serial = port->serial;
 	struct usb_serial_port	*wport;
@@ -166,7 +167,7 @@
 	dbg("%s - port %d", __func__, port->number);
 
 	wport = serial->port[1];
-	wport->tty = port->tty;
+	wport->port.tty = tty;		/* FIXME */
 
 	/* Start reading from the device */
 	usb_fill_bulk_urb(port->read_urb, serial->dev, 
@@ -181,7 +182,8 @@
 	return result;
 }
 
-static void omninet_close (struct usb_serial_port *port, struct file * filp)
+static void omninet_close(struct tty_struct *tty,
+			struct usb_serial_port *port, struct file * filp)
 {
 	dbg("%s - port %d", __func__, port->number);
 	usb_kill_urb(port->read_urb);
@@ -221,9 +223,9 @@
 
 	if (urb->actual_length && header->oh_len) {
 		for (i = 0; i < header->oh_len; i++) {
-			 tty_insert_flip_char(port->tty, data[OMNINET_DATAOFFSET + i], 0);
+			 tty_insert_flip_char(port->port.tty, data[OMNINET_DATAOFFSET + i], 0);
 	  	}
-	  	tty_flip_buffer_push(port->tty);
+	  	tty_flip_buffer_push(port->port.tty);
 	}
 
 	/* Continue trying to always read  */
@@ -238,7 +240,8 @@
 	return;
 }
 
-static int omninet_write (struct usb_serial_port *port, const unsigned char *buf, int count)
+static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
+					const unsigned char *buf, int count)
 {
 	struct usb_serial 	*serial	= port->serial;
 	struct usb_serial_port 	*wport	= serial->port[1];
@@ -290,8 +293,9 @@
 }
 
 
-static int omninet_write_room (struct usb_serial_port *port)
+static int omninet_write_room (struct tty_struct *tty)
 {
+	struct usb_serial_port *port = tty->driver_data;
 	struct usb_serial 	*serial = port->serial;
 	struct usb_serial_port 	*wport 	= serial->port[1];