USB: ftdi_sio: Fix read regression in 2.6.31.
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 USB: ftdi_sio: Fix read regression in 2.6.31.
Use ASYNCB_INITIALIZED to determine when to stop reading.
Since 335f8514f200e63d689113d29cb7253a5c282967 port count can no longer be used to determine when to stop reading from the device as it can be zero when the first read callbacks are made (see tty_port_block_til_read where port count is temporarily decremented during serial_open).
This fixes the regression where reads fail after connecting the device and opening the port more than once (reads usually succeed after the first open due to the device latency timer then being set to the default 16ms rather than 1ms).
---
Tested against 2.6.31 as well as Greg's patch set
(f9752c181c0f7d8bc9c16df0124bf06c5a4d4d88).
Note that ASYNCB_INITIALIZED does not yet get cleared on close in 2.6.31 (as it does in Greg's patches), but ftdi_close kills the urb so the driver stops reading at the next callback as the urb status then is non-zero.
Regards,
Johan
drivers/usb/serial/ftdi_sio.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/usb/serial/ftdi_sio.c +4 -4
@@ -2033,7 +2033,7 @@ static void ftdi_read_bulk_callback(struct urb *urb)dbg ("%s - port %d" , __func__, port->number); -if (port->port.count <=0 ) +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags))return ; tty =tty_port_tty_get (&port->port);
@@ -2089,7 +2089,7 @@ static void ftdi_process_read(struct work_struct *work)dbg ("%s - port %d" , __func__, port->number); -if (port->port.count <=0 ) +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags))return ; tty =tty_port_tty_get (&port->port);
@@ -2247,7 +2247,7 @@ static void ftdi_process_read(struct work_struct *work) }spin_unlock_irqrestore (&priv->rx_lock, flags);/* if the port is closed stop trying to read */ -if (port->port.count >0 ) +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags))/* delay processing of remainder */ schedule_delayed_work (&priv->rx_work,1 );else
@@ -2259,7 +2259,7 @@ static void ftdi_process_read(struct work_struct *work) priv->rx_processed =0 ;/* if the port is closed stop trying to read */ -if (port->port.count >0 ) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) {/* Continue trying to always read */ usb_fill_bulk_urb(port->read_urb, port->serial->dev, usb_rcvbulkpipe(port->serial->dev,
Signature · 1 line
1.6.4.2
Quoted 11 lines · Johan Hovold
Use
ASYNCB_INITIALIZEDto determine when to stop reading.Since
335f8514f200e63d689113d29cb7253a5c282967port count can no longer be used to determine when to stop reading from the device as it can be zero when the first read callbacks are made (seetty_port_block_til_readwhere port count is temporarily decremented duringserial_open).This fixes the regression where reads fail after connecting the device and opening the port more than once (reads usually succeed after the first open due to the device latency timer then being set to the default 16ms rather than 1ms).
This is a good change. It should be made in all the serial drivers, not just ftdi_sio. How'd you like to submit patches for all the rest of the drivers?
Alan Stern
Quoted 5 lines · Alan Stern
Quoted 1 line · Johan Hovold
Use
ASYNCB_INITIALIZEDto determine when to stop reading.This is a good change. It should be made in all the serial drivers, not just
ftdi_sio. How'd you like to submit patches for all the rest of the drivers?
Sure, I'll do that tomorrow.
/Johan
PATCH 1/1 USB: serial: Fix read regression in 2.6.31.
In reply to Alan SternUse ASYNCB_INITIALIZED to determine when to stop reading.
Port count can no longer be used to determine when to stop reading from the device as it can be zero when the first read callbacks are made (see tty_port_block_til_read where port count is temporarily decremented during serial_open).
---
Hi,
Here's a patch which fixes the port count issue for all drivers. I only have access to an ftdi device at the moment so that's the only driver I've been able to test (against latest git with latest patches from Greg's tree).
Regards,
Johan
drivers/usb/serial/aircable.c | 5 +++-- drivers/usb/serial/cypress_m8.c | 3 ++- drivers/usb/serial/digi_acceleport.c | 8 +++++--- drivers/usb/serial/ftdi_sio.c | 8 ++++---- drivers/usb/serial/generic.c | 3 ++- drivers/usb/serial/ir-usb.c | 3 ++- drivers/usb/serial/keyspan.c | 24 ++++++++++++++---------- drivers/usb/serial/opticon.c | 2 +- drivers/usb/serial/option.c | 4 +++- drivers/usb/serial/oti6858.c | 4 ++-- drivers/usb/serial/pl2303.c | 4 ++-- drivers/usb/serial/sierra.c | 7 +++++-- drivers/usb/serial/spcp8x5.c | 5 +++-- 13 files changed, 48 insertions(+), 32 deletions(-)
drivers/usb/serial/aircable.c +3 -2
@@ -42,6 +42,7 @@* */ +#include <linux/serial.h> #include <linux/tty.h> #include <linux/tty_flip.h> #include <linux/circ_buf.h>
@@ -468,7 +469,7 @@ static void aircable_read_bulk_callback(struct urb *urb)if (status) {dbg ("%s - urb status = %d" , __func__, status); -if (!port->port.count) { +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags)) {dbg ("%s - port is closed, exiting." , __func__);return ; }
@@ -531,7 +532,7 @@ static void aircable_read_bulk_callback(struct urb *urb)tty_kref_put (tty);/* Schedule the next read _if_ we are still open */ -if (port->port.count) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) { usb_fill_bulk_urb(port->read_urb, port->serial->dev, usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress),
drivers/usb/serial/cypress_m8.c +2 -1
@@ -1329,7 +1329,8 @@ continue_read:/* Continue trying to always read... unless the port has closed. */ -if (port->port.count >0 && priv->comm_is_ok) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags) && + priv->comm_is_ok) { usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, usb_rcvintpipe(port->serial->dev, port->interrupt_in_endpointAddress),
drivers/usb/serial/digi_acceleport.c +5 -3
@@ -244,6 +244,7 @@#include <linux/uaccess.h> #include <linux/usb.h> #include <linux/wait.h> +#include <linux/serial.h> #include <linux/usb/serial.h> /* Defines */
@@ -1265,7 +1266,8 @@ static void digi_write_bulk_callback(struct urb *urb)/* try to send any buffered data on this port, if it is open */ spin_lock (&priv->dp_port_lock); priv->dp_write_urb_in_use =0 ; -if (port->port.count && priv->dp_out_buf_len >0 ) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags) && + priv->dp_out_buf_len >0 ) { *((unsigned char *)(port->write_urb->transfer_buffer)) = (unsigned char )DIGI_CMD_SEND_DATA ; *((unsigned char *)(port->write_urb->transfer_buffer) +1 )
@@ -1663,7 +1665,7 @@ static int digi_read_inb_callback(struct urb *urb)/* do not process callbacks on closed ports */ /* but do continue the read chain */ -if (port->port.count ==0 ) +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags))return 0 ;/* short/multiple packet check */
@@ -1776,7 +1778,7 @@ static int digi_read_oob_callback(struct urb *urb) tty =tty_port_tty_get (&port->port); rts =0 ; -if (port->port.count) +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) rts = tty->termios->c_cflag &CRTSCTS ;if (opcode ==DIGI_CMD_READ_INPUT_SIGNALS ) {
drivers/usb/serial/ftdi_sio.c +4 -4
@@ -2033,7 +2033,7 @@ static void ftdi_read_bulk_callback(struct urb *urb)dbg ("%s - port %d" , __func__, port->number); -if (port->port.count <=0 ) +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags))return ; tty =tty_port_tty_get (&port->port);
@@ -2089,7 +2089,7 @@ static void ftdi_process_read(struct work_struct *work)dbg ("%s - port %d" , __func__, port->number); -if (port->port.count <=0 ) +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags))return ; tty =tty_port_tty_get (&port->port);
@@ -2247,7 +2247,7 @@ static void ftdi_process_read(struct work_struct *work) }spin_unlock_irqrestore (&priv->rx_lock, flags);/* if the port is closed stop trying to read */ -if (port->port.count >0 ) +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags))/* delay processing of remainder */ schedule_delayed_work (&priv->rx_work,1 );else
@@ -2259,7 +2259,7 @@ static void ftdi_process_read(struct work_struct *work) priv->rx_processed =0 ;/* if the port is closed stop trying to read */ -if (port->port.count >0 ) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) {/* Continue trying to always read */ usb_fill_bulk_urb(port->read_urb, port->serial->dev, usb_rcvbulkpipe(port->serial->dev,
drivers/usb/serial/generic.c +2 -1
@@ -17,6 +17,7 @@#include <linux/module.h> #include <linux/moduleparam.h> #include <linux/usb.h> +#include <linux/serial.h> #include <linux/usb/serial.h> #include <linux/uaccess.h> #include <linux/kfifo.h>
@@ -583,7 +584,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)for (i =0 ; i < serial->num_ports; i++) { port = serial->port[i]; -if (!port->port.count) +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags))continue ;if (port->read_urb) {
drivers/usb/serial/ir-usb.c +2 -1
@@ -65,6 +65,7 @@#include <linux/module.h> #include <linux/spinlock.h> #include <linux/uaccess.h> +#include <linux/serial.h> #include <linux/usb.h> #include <linux/usb/serial.h> #include <linux/usb/irda.h>
@@ -445,7 +446,7 @@ static void ir_read_bulk_callback(struct urb *urb)dbg ("%s - port %d" , __func__, port->number); -if (!port->port.count) { +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags)) {dbg ("%s - port closed." , __func__);return ; }
drivers/usb/serial/keyspan.c +14 -10
@@ -108,6 +108,7 @@#include <linux/firmware.h> #include <linux/ihex.h> #include <linux/uaccess.h> +#include <linux/serial.h> #include <linux/usb.h> #include <linux/usb/serial.h> #include "keyspan.h"
@@ -464,7 +465,7 @@ static void usa26_indat_callback(struct urb *urb)/* Resubmit urb so we continue receiving */ urb->dev = port->serial->dev; -if (port->port.count) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) { err =usb_submit_urb (urb,GFP_ATOMIC );if (err !=0 ) dbg("%s - resubmit read urb failed. (%d)",
@@ -483,7 +484,7 @@ static void usa2x_outdat_callback(struct urb *urb) p_priv =usb_get_serial_port_data (port);dbg ("%s - urb %d" , __func__, urb == p_priv->out_urbs[1 ]); -if (port->port.count) +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags))usb_serial_port_softint (port); }
@@ -615,7 +616,7 @@ static void usa28_indat_callback(struct urb *urb)/* Resubmit urb so we continue receiving */ urb->dev = port->serial->dev; -if (port->port.count) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) { err =usb_submit_urb (urb,GFP_ATOMIC );if (err !=0 ) dbg("%s - resubmit read urb failed. (%d)",
@@ -856,7 +857,7 @@ static void usa49_indat_callback(struct urb *urb)/* Resubmit urb so we continue receiving */ urb->dev = port->serial->dev; -if (port->port.count) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) { err =usb_submit_urb (urb,GFP_ATOMIC );if (err !=0 ) dbg("%s - resubmit read urb failed. (%d)",
@@ -904,10 +905,11 @@ static void usa49wg_indat_callback(struct urb *urb)/* no error on any byte */ i++;for (x =1 ; x < len ; ++x) -if (port->port.count) +if (test_bit (ASYNCB_INITIALIZED , + &port->port.flags)) {tty_insert_flip_char (tty, data[i++],0 ); -else + }else i++; }else {/*
@@ -922,13 +924,15 @@ static void usa49wg_indat_callback(struct urb *urb)if (stat &RXERROR_PARITY ) flag |=TTY_PARITY ;/* XXX should handle break (0x10) */ -if (port->port.count) +if (test_bit (ASYNCB_INITIALIZED , + &port->port.flags)) {tty_insert_flip_char (tty, data[i+1 ], flag); + } i +=2 ; } } -if (port->port.count) +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags))tty_flip_buffer_push (tty);tty_kref_put (tty); }
@@ -1013,7 +1017,7 @@ static void usa90_indat_callback(struct urb *urb)/* Resubmit urb so we continue receiving */ urb->dev = port->serial->dev; -if (port->port.count) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) { err =usb_submit_urb (urb,GFP_ATOMIC );if (err !=0 ) dbg("%s - resubmit read urb failed. (%d)",
@@ -2418,7 +2422,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial, msg.portEnabled =0 ;/* Sending intermediate configs */ else { -if (port->port.count) +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) msg.portEnabled =1 ; msg.txBreak = (p_priv->break_on); }
drivers/usb/serial/opticon.c +1 -1
@@ -499,7 +499,7 @@ static int opticon_resume(struct usb_interface *intf)int result;mutex_lock (&port->mutex); -if (port->port.count) +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) result =usb_submit_urb (priv->bulk_read_urb,GFP_NOIO );else result =0 ;
drivers/usb/serial/option.c +3 -1
@@ -39,6 +39,7 @@#include <linux/tty_flip.h> #include <linux/module.h> #include <linux/bitops.h> +#include <linux/serial.h> #include <linux/usb.h> #include <linux/usb/serial.h>
@@ -868,7 +869,8 @@ static void option_indat_callback(struct urb *urb)tty_kref_put (tty);/* Resubmit urb so we continue receiving */ -if (port->port.count && status != -ESHUTDOWN ) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags) && + status != -ESHUTDOWN ) { err =usb_submit_urb (urb,GFP_ATOMIC );if (err) printk(KERN_ERR "%s: resubmit read urb failed. "
drivers/usb/serial/oti6858.c +2 -2
@@ -927,7 +927,7 @@ static void oti6858_read_bulk_callback(struct urb *urb)spin_unlock_irqrestore (&priv->lock, flags);if (status !=0 ) { -if (!port->port.count) { +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags)) {dbg ("%s(): port is closed, exiting" , __func__);return ; }
@@ -955,7 +955,7 @@ static void oti6858_read_bulk_callback(struct urb *urb)tty_kref_put (tty);/* schedule the interrupt urb if we are still open */ -if (port->port.count !=0 ) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) { port->interrupt_in_urb->dev = port->serial->dev; result =usb_submit_urb (port->interrupt_in_urb,GFP_ATOMIC );if (result !=0 ) {
drivers/usb/serial/pl2303.c +2 -2
@@ -1070,7 +1070,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)if (status) {dbg ("%s - urb status = %d" , __func__, status); -if (!port->port.count) { +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags)) {dbg ("%s - port is closed, exiting." , __func__);return ; }
@@ -1106,7 +1106,7 @@ static void pl2303_read_bulk_callback(struct urb *urb) }tty_kref_put (tty);/* Schedule the next read _if_ we are still open */ -if (port->port.count) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) { urb->dev = port->serial->dev; result =usb_submit_urb (urb,GFP_ATOMIC );if (result)
drivers/usb/serial/sierra.c +5 -2
@@ -27,6 +27,7 @@#include <linux/tty.h> #include <linux/tty_flip.h> #include <linux/module.h> +#include <linux/serial.h> #include <linux/usb.h> #include <linux/usb/serial.h>
@@ -578,7 +579,8 @@ static void sierra_indat_callback(struct urb *urb) }/* Resubmit urb so we continue receiving */ -if (port->port.count && status != -ESHUTDOWN && status != -EPERM ) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags) && + status != -ESHUTDOWN && status != -EPERM ) {usb_mark_last_busy (port->serial->dev); err =usb_submit_urb (urb,GFP_ATOMIC );if (err)
@@ -640,7 +642,8 @@ static void sierra_instat_callback(struct urb *urb)dev_dbg (&port->dev,"%s: error %d\n" , __func__, status);/* Resubmit urb so we continue receiving IRQ data */ -if (port->port.count && status != -ESHUTDOWN && status != -ENOENT ) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags) && + status != -ESHUTDOWN && status != -ENOENT ) {usb_mark_last_busy (serial->dev); urb->dev = serial->dev; err =usb_submit_urb (urb,GFP_ATOMIC );
drivers/usb/serial/spcp8x5.c +3 -2
@@ -23,6 +23,7 @@#include <linux/tty_driver.h> #include <linux/tty_flip.h> #include <linux/module.h> +#include <linux/serial.h> #include <linux/spinlock.h> #include <linux/usb.h> #include <linux/usb/serial.h>
@@ -687,7 +688,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)/* check the urb status */ if (result) { -if (!port->port.count) +if (!test_bit (ASYNCB_INITIALIZED , &port->port.flags))return ;if (result == -EPROTO ) {/* spcp8x5 mysteriously fails with -EPROTO */
@@ -737,7 +738,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)tty_kref_put (tty);/* Schedule the next read _if_ we are still open */ -if (port->port.count) { +if (test_bit (ASYNCB_INITIALIZED , &port->port.flags)) { urb->dev = port->serial->dev; result =usb_submit_urb (urb ,GFP_ATOMIC );if (result)
Signature · 1 line
1.6.4.2
Re: [PATCH] USB: serial: Fix read regression in 2.6.31.
Quoted 8 lines · Johan Hovold
Use
ASYNCB_INITIALIZEDto determine when to stop reading.Port count can no longer be used to determine when to stop reading from the device as it can be zero when the first read callbacks are made (see
tty_port_block_til_readwhere port count is temporarily decremented duringserial_open).Signed-off-by Johan Hovold <[email protected]>
Quoted 8 lines
---
Hi,
Here's a patch which fixes the port count issue for all drivers. I only have access to an ftdi device at the moment so that's the only driver I've been able to test (against latest git with latest patches from Greg's tree).
Hm, this doesn't apply on top of the other ftdi patches. Could you respin this?
thanks,
greg k-h
Re: [PATCH] USB: serial: Fix read regression in 2.6.31.
Quoted 13 lines · Greg KH
Quoted 12 lines · Johan Hovold
Use
ASYNCB_INITIALIZEDto determine when to stop reading.Port count can no longer be used to determine when to stop reading from the device as it can be zero when the first read callbacks are made (see
tty_port_block_til_readwhere port count is temporarily decremented duringserial_open).Signed-off-by Johan Hovold <[email protected]>---
Hi,
Quoted 7 lines
Quoted 4 lines
Here's a patch which fixes the port count issue for all drivers. I only have access to an ftdi device at the moment so that's the only driver I've been able to test (against latest git with latest patches from Greg's tree).
Hm, this doesn't apply on top of the other ftdi patches. Could you respin this?
There were some issues with that patch, so please disregard that one. Sorry. There are probably still some problems with some of the other drivers (at least theoretical ones) due to the tty changes that broke ftdi, but there is currently no patch to fix them all.
/Johan
Re: [PATCH] USB: serial: Fix read regression in 2.6.31.
Quoted 19 lines · Johan Hovold
Quoted 18 lines · Greg KH
Quoted 16 lines · Johan Hovold
Use
ASYNCB_INITIALIZEDto determine when to stop reading.Port count can no longer be used to determine when to stop reading from the device as it can be zero when the first read callbacks are made (see
tty_port_block_til_readwhere port count is temporarily decremented duringserial_open).Signed-off-by Johan Hovold <[email protected]>---
Hi,
Here's a patch which fixes the port count issue for all drivers. I only have access to an ftdi device at the moment so that's the only driver I've been able to test (against latest git with latest patches from Greg's tree).
Quoted 7 lines
Quoted 2 lines
Hm, this doesn't apply on top of the other ftdi patches. Could you respin this?
There were some issues with that patch, so please disregard that one. Sorry. There are probably still some problems with some of the other drivers (at least theoretical ones) due to the tty changes that broke ftdi, but there is currently no patch to fix them all.
Ok, dropped :)
thanks,
greg k-h