ChangeSet 1.1119.3.4, 2003/09/05 15:46:55-07:00, greg@kroah.com

[PATCH] USB: fix oops when yanking a usb-serial device from the system with the port still opened.

Thanks to Ian Abbott <abbotti@mev.co.uk> for help finding this bug.


 drivers/usb/serial/usbserial.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)


diff -Nru a/drivers/usb/serial/usbserial.c b/drivers/usb/serial/usbserial.c
--- a/drivers/usb/serial/usbserial.c	Fri Sep  5 17:10:53 2003
+++ b/drivers/usb/serial/usbserial.c	Fri Sep  5 17:10:53 2003
@@ -556,7 +556,10 @@
 		else
 			generic_close(port, filp);
 		port->open_count = 0;
-		port->tty = NULL;
+		if (port->tty) {
+			port->tty->driver_data = NULL;
+			port->tty = NULL;
+		}
 	}
 
 	if (port->serial->type->owner)
@@ -1401,12 +1404,9 @@
 		for (i = 0; i < serial->num_ports; ++i) {
 			port = &serial->port[i];
 			down (&port->sem);
-			if (port->tty != NULL) {
-				while (port->open_count > 0) {
+			if (port->tty != NULL)
+				while (port->open_count > 0)
 					__serial_close(port, NULL);
-				}
-				port->tty->driver_data = NULL;
-			}
 			up (&port->sem);
 		}
 
