From 507ca9bc0476662f3463888d583864834eab1e11 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sat, 23 Apr 2005 12:49:16 -0700 Subject: [PATCH] USB: add ability for usb-serial drivers to determine if their write urb is currently being used. This removes a lot of racy and buggy code by trying to check the status of the urb. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/omninet.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'drivers/usb/serial/omninet.c') diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c index b5f2c06d4f3..6a99ae192df 100644 --- a/drivers/usb/serial/omninet.c +++ b/drivers/usb/serial/omninet.c @@ -254,10 +254,15 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf dbg("%s - write request of 0 bytes", __FUNCTION__); return (0); } - if (wport->write_urb->status == -EINPROGRESS) { + + spin_lock(&port->lock); + if (port->write_urb_busy) { + spin_unlock(&port->lock); dbg("%s - already writing", __FUNCTION__); - return (0); + return 0; } + port->write_urb_busy = 1; + spin_unlock(&port->lock); count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; @@ -275,9 +280,10 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf wport->write_urb->dev = serial->dev; result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); - if (result) + if (result) { + port->write_urb_busy = 0; err("%s - failed submitting write urb, error %d", __FUNCTION__, result); - else + } else result = count; return result; @@ -291,7 +297,7 @@ static int omninet_write_room (struct usb_serial_port *port) int room = 0; // Default: no room - if (wport->write_urb->status != -EINPROGRESS) + if (wport->write_urb_busy) room = wport->bulk_out_size - OMNINET_HEADERLEN; // dbg("omninet_write_room returns %d", room); @@ -306,6 +312,7 @@ static void omninet_write_bulk_callback (struct urb *urb, struct pt_regs *regs) // dbg("omninet_write_bulk_callback, port %0x\n", port); + port->write_urb_busy = 0; if (urb->status) { dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); return; -- cgit v1.2.3