On Thu, 13 Apr 2006, Paul Fulghum wrote:

> On Thu, 2006-04-13 at 22:25 +0200, Guennadi Liakhovetski wrote:
> > +void usb_serial_console_disconnect(struct usb_serial *serial)
> > +{
> > +   if (serial && serial->port && serial->port[0] && serial->port[0] == 
> > usbcons_info.port) {
> > +           usbcons_info.port->open_count--;
> > +           usbcons_info.port = NULL;
> > +   }
> > +}
> 
> I think you need unregister_console(&usbcons);
> on disconnect. If the device is reinstalled later,
> the console is registered again in usb_serial_console_init().
> Until it is unregistered, the console subsystem keeps trying
> to write to an ejected usb console.
> 
> The check for disconnected state prevents the write call
> from causing harm, but it is still making unnecessary calls.

Well, looked through the code again - I think, you are right. An updated 
version below. I just used your initial (slightly modified to my 
tastes:-)) approach - calling usb_serial_console_exit() from 
usb_serial_console_disconnect().

Thanks
Guennadi
---
Guennadi Liakhovetski

Prevent sending further output to a USB-serial console after the dongle is
disconnected.

Signed-off-by: Guennadi Liakhovetski <[EMAIL PROTECTED]>

diff -u a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
--- a/drivers/usb/serial/console.c      13 Jan 2005 21:09:08 -0000
+++ b/drivers/usb/serial/console.c      11 Apr 2006 18:03:29 -0000
@@ -202,7 +202,7 @@
        struct usb_serial *serial;
        int retval = -ENODEV;
 
-       if (!port)
+       if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED)
                return;
        serial = port->serial;
 
@@ -234,6 +234,12 @@
        .index =        -1,
 };
 
+void usb_serial_console_disconnect(struct usb_serial *serial)
+{
+       if (serial && serial->port && serial->port[0] && serial->port[0] == 
usbcons_info.port)
+               usb_serial_console_exit();
+}
+
 void usb_serial_console_init (int serial_debug, int minor)
 {
        debug = serial_debug;
@@ -259,6 +265,11 @@
 
 void usb_serial_console_exit (void)
 {
-       unregister_console(&usbcons);
+       if (usbcons_info.port) {
+               unregister_console(&usbcons);
+               if (usbcons_info.port->open_count)
+                       usbcons_info.port->open_count--;
+               usbcons_info.port = NULL;
+       }
 }
 
diff -u a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
--- a/drivers/usb/serial/usb-serial.c   30 Mar 2006 19:18:07 -0000
+++ b/drivers/usb/serial/usb-serial.c   11 Apr 2006 18:02:12 -0000
@@ -271,7 +271,7 @@
        struct usb_serial_port *port = tty->driver_data;
        int retval = -EINVAL;
 
-       if (!port)
+       if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED)
                goto exit;
 
        dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count);
@@ -982,6 +982,7 @@
        struct device *dev = &interface->dev;
        struct usb_serial_port *port;
 
+       usb_serial_console_disconnect(serial);
        dbg ("%s", __FUNCTION__);
 
        usb_set_intfdata (interface, NULL);
diff -u a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h
--- a/drivers/usb/serial/usb-serial.h   30 Mar 2006 19:18:07 -0000
+++ b/drivers/usb/serial/usb-serial.h   11 Apr 2006 18:02:12 -0000
@@ -248,9 +248,11 @@
 #ifdef CONFIG_USB_SERIAL_CONSOLE
 extern void usb_serial_console_init (int debug, int minor);
 extern void usb_serial_console_exit (void);
+extern void usb_serial_console_disconnect(struct usb_serial *serial);
 #else
 static inline void usb_serial_console_init (int debug, int minor) { }
 static inline void usb_serial_console_exit (void) { }
+static inline void usb_serial_console_disconnect(struct usb_serial *serial) {}
 #endif
 
 /* Functions needed by other parts of the usbserial core */


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to