(I'm not on the linux-usb ML, so please Cc me on replies.)
Hi,
I found out that unplugging and plugging back an USB-to-serial converter
such as pl2303 is not enough to undo all changes to termios which were
performed from userspace. One has to remove the usb-serial module because
that's where the remembering appears to take place. I'm on 4.6.2.
There's the TTY_DRIVER_RESET_TERMIOS option which controls termios
save/restore in the tty_init_termios and tty_free_termios. My understanding
is that this option is not aplicable here, though, because it controls what
happens upon close()/open() -- right?
I've tried doing something like this in the usb_serial_device_remove:
--- drivers/usb/serial/bus.c
+++ drivers/usb/serial/bus.c
@@ -93,18 +93,11 @@
int retval = 0;
int minor;
int autopm_err;
+ struct tty_struct *tty = NULL;
port = to_usb_serial_port(dev);
if (!port)
return -ENODEV;
+ tty = port->port.tty;
+
down_write(&tty->termios_rwsem);
+
kfree(tty->driver->termios[tty->index]);
+ tty->driver->termios[tty->index] =
NULL;
+
up_write(&tty->termios_rwsem);
+
...but I got something which looked like a deadlock at runtime -- I guess
it's because I don't understand the locking context here.
What can I do to have usbserial stop reusing the cached termios when a
physical convertor gets unplugged? Or is there some reason for this that I
don't understand? I would love to send a patch, but I feel a bit lost among
these layers.
For those who are curious about how I hit this thing -- when userspace
clears the CLOCAL through a tcsetattr() just once and the "CD" pin is not
connected anywhere, subsequent blocking open() hangs and one needs an open
fd for setting the CLOCAL back again. One obvious workaround is opening in
O_NONBLOCK followed by tcsetattr() and fcntl(fd, F_SETFL, flags &
~O_NONBLOCK). Also, I have several different USB-to-RS232 convertors
attached at a time, so a simple `modprobe -r pl2303` hadn't removed the
usbserial.ko which made it easy to hit this thing.
(I'm not on the linux-usb ML, so please Cc me on replies.)
Cheers,
Jan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html