Commit b58af406 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

USB: serial: fix stalled writes

As David VomLehn points out, it was possible to receive an interrupt
before clearing the free-urb flag which could lead to the urb being
incorrectly marked as busy.

For the same reason, move tx_bytes accounting so that it will never be
negative.

Note that the free-flags set and clear operations do not need any
additional locking as they are manipulated while USB_SERIAL_WRITE_BUSY
is set.
Reported-by: default avatarDavid VomLehn <dvomlehn@cisco.com>
Tested-by: default avatarDavid VomLehn <dvomlehn@cisco.com>
Signed-off-by: default avatarJohan Hovold <jhovold@gmail.com>
Cc: stable <stable@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent b409214c
...@@ -208,18 +208,23 @@ static int usb_serial_generic_write_start(struct usb_serial_port *port) ...@@ -208,18 +208,23 @@ static int usb_serial_generic_write_start(struct usb_serial_port *port)
urb->transfer_buffer_length = count; urb->transfer_buffer_length = count;
usb_serial_debug_data(debug, &port->dev, __func__, count, usb_serial_debug_data(debug, &port->dev, __func__, count,
urb->transfer_buffer); urb->transfer_buffer);
spin_lock_irqsave(&port->lock, flags);
port->tx_bytes += count;
spin_unlock_irqrestore(&port->lock, flags);
clear_bit(i, &port->write_urbs_free);
result = usb_submit_urb(urb, GFP_ATOMIC); result = usb_submit_urb(urb, GFP_ATOMIC);
if (result) { if (result) {
dev_err(&port->dev, "%s - error submitting urb: %d\n", dev_err(&port->dev, "%s - error submitting urb: %d\n",
__func__, result); __func__, result);
set_bit(i, &port->write_urbs_free);
spin_lock_irqsave(&port->lock, flags);
port->tx_bytes -= count;
spin_unlock_irqrestore(&port->lock, flags);
clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
return result; return result;
} }
clear_bit(i, &port->write_urbs_free);
spin_lock_irqsave(&port->lock, flags);
port->tx_bytes += count;
spin_unlock_irqrestore(&port->lock, flags);
/* Try sending off another urb, unless in irq context (in which case /* Try sending off another urb, unless in irq context (in which case
* there will be no free urb). */ * there will be no free urb). */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment