Skip to content

Commit 985616f

Browse files
committed
USB: serial: cyberjack: fix write-URB completion race
The write-URB busy flag was being cleared before the completion handler was done with the URB, something which could lead to corrupt transfers due to a racing write request if the URB is resubmitted. Fixes: 507ca9b ("[PATCH] USB: add ability for usb-serial drivers to determine if their write urb is currently being used.") Cc: stable <stable@vger.kernel.org> # 2.6.13 Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
1 parent a46b973 commit 985616f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

drivers/usb/serial/cyberjack.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,12 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
357357
struct device *dev = &port->dev;
358358
int status = urb->status;
359359
unsigned long flags;
360+
bool resubmitted = false;
360361

361-
set_bit(0, &port->write_urbs_free);
362362
if (status) {
363363
dev_dbg(dev, "%s - nonzero write bulk status received: %d\n",
364364
__func__, status);
365+
set_bit(0, &port->write_urbs_free);
365366
return;
366367
}
367368

@@ -394,6 +395,8 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
394395
goto exit;
395396
}
396397

398+
resubmitted = true;
399+
397400
dev_dbg(dev, "%s - priv->wrsent=%d\n", __func__, priv->wrsent);
398401
dev_dbg(dev, "%s - priv->wrfilled=%d\n", __func__, priv->wrfilled);
399402

@@ -410,6 +413,8 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
410413

411414
exit:
412415
spin_unlock_irqrestore(&priv->lock, flags);
416+
if (!resubmitted)
417+
set_bit(0, &port->write_urbs_free);
413418
usb_serial_port_softint(port);
414419
}
415420

0 commit comments

Comments
 (0)