Make sure hardware buffers are empty before returning 0. This fixes a problem reported by Jarkko Huijts who noted that port close returns before all data has been transferred. Based on a solution proposed by Jarkko Huijts. Reported-by: Jarkko Huijts <jarkko.huijts@xxxxxxxxx> Signed-off-by: Johan Hovold <jhovold@xxxxxxxxx> --- drivers/usb/serial/ftdi_sio.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 3312d7a..03bf6d2 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -921,6 +921,7 @@ static void ftdi_set_termios(struct tty_struct *tty, static int ftdi_tiocmget(struct tty_struct *tty); static int ftdi_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); +static int ftdi_chars_in_buffer(struct tty_struct *tty); static int ftdi_get_icount(struct tty_struct *tty, struct serial_icounter_struct *icount); static int ftdi_ioctl(struct tty_struct *tty, @@ -950,6 +951,7 @@ static struct usb_serial_driver ftdi_sio_device = { .open = ftdi_open, .close = ftdi_close, .dtr_rts = ftdi_dtr_rts, + .chars_in_buffer = ftdi_chars_in_buffer, .throttle = usb_serial_generic_throttle, .unthrottle = usb_serial_generic_unthrottle, .process_read_urb = ftdi_process_read_urb, @@ -2371,6 +2373,29 @@ static int ftdi_tiocmset(struct tty_struct *tty, return update_mctrl(port, set, clear); } +static int ftdi_chars_in_buffer(struct tty_struct *tty) +{ + struct usb_serial_port *port = tty->driver_data; + unsigned char buf[2]; + int count; + int ret; + + count = usb_serial_generic_chars_in_buffer(tty); + if (count) + goto out; + + /* Check if hardware buffer is empty. */ + ret = ftdi_get_modem_status(tty, buf); + if (ret == 2) { + if (!(buf[1] & FTDI_RS_TEMT)) + count = 1; + } +out: + dev_dbg(&port->dev, "%s - %d\n", __func__, count); + + return count; +} + static int ftdi_get_icount(struct tty_struct *tty, struct serial_icounter_struct *icount) { -- 1.7.12 -- 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