Try this all-in-one patch.
Included:
* usb serial_open fix (fix ENODEV)
* usb_console_write fix (fix CR after LF)
* ftdi patch (fix oops on tty struct == NULL)
* ftdi uninitialized tmp_termios fix
* remove __init from usb_console_setup (oops on late device install)
* add usb_serial_console_disconnect (write errors after device removal)
--- linux-2.6.16/drivers/usb/serial/usb-serial.c 2006-03-19
23:53:29.000000000 -0600
+++ b/drivers/usb/serial/usb-serial.c 2006-04-10 14:21:12.000000000 -0500
@@ -197,12 +197,12 @@ static int serial_open (struct tty_struc
++port->open_count;
- if (port->open_count == 1) {
+ /* set up our port structure making the tty driver
+ * remember our port object, and us it */
+ tty->driver_data = port;
+ port->tty = tty;
- /* set up our port structure making the tty driver
- * remember our port object, and us it */
- tty->driver_data = port;
- port->tty = tty;
+ if (port->open_count == 1) {
/* lock this module before we call it
* this may fail, which means we must bail out,
@@ -988,8 +988,11 @@ void usb_serial_disconnect(struct usb_in
if (serial) {
for (i = 0; i < serial->num_ports; ++i) {
port = serial->port[i];
- if (port && port->tty)
- tty_hangup(port->tty);
+ if (port) {
+ usb_serial_console_disconnect(port);
+ if (port->tty)
+ tty_hangup(port->tty);
+ }
}
/* let the last holder of this object
* cause it to be cleaned up */
--- linux-2.6.16/drivers/usb/serial/usb-serial.h 2006-03-19
23:53:29.000000000 -0600
+++ b/drivers/usb/serial/usb-serial.h 2006-04-10 14:19:10.000000000 -0500
@@ -247,9 +247,11 @@ extern int ezusb_set_reset (struct usb_s
/* USB Serial console functions */
#ifdef CONFIG_USB_SERIAL_CONSOLE
extern void usb_serial_console_init (int debug, int minor);
+extern void usb_serial_console_disconnect(struct usb_serial_port *port);
extern void usb_serial_console_exit (void);
#else
static inline void usb_serial_console_init (int debug, int minor) { }
+extern inline void usb_serial_console_disconnect(struct usb_serial_port *port)
{}
static inline void usb_serial_console_exit (void) { }
#endif
--- linux-2.6.16/drivers/usb/serial/console.c 2006-03-19 23:53:29.000000000
-0600
+++ b/drivers/usb/serial/console.c 2006-04-10 14:34:56.000000000 -0500
@@ -54,7 +54,7 @@ static struct console usbcons;
* serial.c code, except that the specifier is "ttyUSB" instead
* of "ttyS".
*/
-static int __init usb_console_setup(struct console *co, char *options)
+static int usb_console_setup(struct console *co, char *options)
{
struct usbcons_info *info = &usbcons_info;
int baud = 9600;
@@ -213,17 +213,38 @@ static void usb_console_write(struct con
if (!port->open_count) {
dbg ("%s - port not opened", __FUNCTION__);
- goto exit;
+ return;
}
- /* pass on to the driver specific version of this function if it is
available */
- if (serial->type->write)
- retval = serial->type->write(port, buf, count);
- else
- retval = usb_serial_generic_write(port, buf, count);
-
-exit:
- dbg("%s - return value (if we had one): %d", __FUNCTION__, retval);
+ while (count) {
+ unsigned int i;
+ unsigned int lf;
+ /* search for LF so we can insert CR if necessary */
+ for (i=0, lf=0 ; i < count ; i++) {
+ if (*(buf + i) == 10) {
+ lf = 1;
+ i++;
+ break;
+ }
+ }
+ /* pass on to the driver specific version of this function if
it is available */
+ if (serial->type->write)
+ retval = serial->type->write(port, buf, i);
+ else
+ retval = usb_serial_generic_write(port, buf, i);
+ dbg("%s - return value : %d", __FUNCTION__, retval);
+ if (lf) {
+ /* append CR after LF */
+ unsigned char cr = 13;
+ if (serial->type->write)
+ retval = serial->type->write(port, &cr, 1);
+ else
+ retval = usb_serial_generic_write(port, &cr, 1);
+ dbg("%s - return value : %d", __FUNCTION__, retval);
+ }
+ buf += i;
+ count -= i;
+ }
}
static struct console usbcons = {
@@ -257,8 +278,23 @@ void usb_serial_console_init (int serial
}
}
+/*
+ * called when disconnecting a port
+ * unregister console if necessary
+ */
+void usb_serial_console_disconnect(struct usb_serial_port *port)
+{
+ if (usbcons_info.port == port)
+ usb_serial_console_exit();
+}
+
void usb_serial_console_exit (void)
{
- unregister_console(&usbcons);
+ if (usbcons_info.port) {
+ unregister_console(&usbcons);
+ usbcons_info.port = NULL;
+ if (usbcons_info.port->open_count)
+ usbcons_info.port->open_count--;
+ }
}
--- linux-2.6.16/drivers/usb/serial/ftdi_sio.c 2006-03-19 23:53:29.000000000
-0600
+++ b/drivers/usb/serial/ftdi_sio.c 2006-04-10 14:27:37.000000000 -0500
@@ -1254,7 +1254,6 @@ static void ftdi_shutdown (struct usb_se
static int ftdi_open (struct usb_serial_port *port, struct file *filp)
{ /* ftdi_open */
- struct termios tmp_termios;
struct usb_device *dev = port->serial->dev;
struct ftdi_private *priv = usb_get_serial_port_data(port);
unsigned long flags;
@@ -1264,8 +1263,8 @@ static int ftdi_open (struct usb_serial
dbg("%s", __FUNCTION__);
-
- port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
+ if (port->tty)
+ port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1
: 0;
/* No error checking for this (will get errors later anyway) */
/* See ftdi_sio.h for description of what is reset */
@@ -1279,7 +1278,8 @@ static int ftdi_open (struct usb_serial
This is same behaviour as serial.c/rs_open() - Kuba */
/* ftdi_set_termios will send usb control messages */
- ftdi_set_termios(port, &tmp_termios);
+ if (port->tty)
+ ftdi_set_termios(port, NULL);
/* FIXME: Flow control might be enabled, so it should be checked -
we have no control of defaults! */
@@ -1860,7 +1860,7 @@ static void ftdi_set_termios (struct usb
err("%s urb failed to set baudrate", __FUNCTION__);
}
/* Ensure RTS and DTR are raised when baudrate changed from 0 */
- if ((old_termios->c_cflag & CBAUD) == B0) {
+ if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) {
set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
}
}
-------------------------------------------------------
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
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel