diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2005-04-23 15:49:16 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-06-27 17:43:47 -0400 |
commit | 507ca9bc0476662f3463888d583864834eab1e11 (patch) | |
tree | 421a373de235fcb4cb46a4723a1e9f00a71f709a /drivers/usb/serial/safe_serial.c | |
parent | f4df0e334a9fc731689e8ba4f42a0d72a7491348 (diff) |
[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 <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/serial/safe_serial.c')
-rw-r--r-- | drivers/usb/serial/safe_serial.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c index 0e85ed6c6c19..96a17568cbf1 100644 --- a/drivers/usb/serial/safe_serial.c +++ b/drivers/usb/serial/safe_serial.c | |||
@@ -299,10 +299,14 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i | |||
299 | dbg ("%s - write request of 0 bytes", __FUNCTION__); | 299 | dbg ("%s - write request of 0 bytes", __FUNCTION__); |
300 | return (0); | 300 | return (0); |
301 | } | 301 | } |
302 | if (port->write_urb->status == -EINPROGRESS) { | 302 | spin_lock(&port->lock); |
303 | dbg ("%s - already writing", __FUNCTION__); | 303 | if (port->write_urb_busy) { |
304 | return (0); | 304 | spin_unlock(&port->lock); |
305 | dbg("%s - already writing", __FUNCTION__); | ||
306 | return 0; | ||
305 | } | 307 | } |
308 | port->write_urb_busy = 1; | ||
309 | spin_unlock(&port->lock); | ||
306 | 310 | ||
307 | packet_length = port->bulk_out_size; // get max packetsize | 311 | packet_length = port->bulk_out_size; // get max packetsize |
308 | 312 | ||
@@ -354,6 +358,7 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i | |||
354 | #endif | 358 | #endif |
355 | port->write_urb->dev = port->serial->dev; | 359 | port->write_urb->dev = port->serial->dev; |
356 | if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { | 360 | if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { |
361 | port->write_urb_busy = 0; | ||
357 | err ("%s - failed submitting write urb, error %d", __FUNCTION__, result); | 362 | err ("%s - failed submitting write urb, error %d", __FUNCTION__, result); |
358 | return 0; | 363 | return 0; |
359 | } | 364 | } |
@@ -368,7 +373,7 @@ static int safe_write_room (struct usb_serial_port *port) | |||
368 | 373 | ||
369 | dbg ("%s", __FUNCTION__); | 374 | dbg ("%s", __FUNCTION__); |
370 | 375 | ||
371 | if (port->write_urb->status != -EINPROGRESS) | 376 | if (port->write_urb_busy) |
372 | room = port->bulk_out_size - (safe ? 2 : 0); | 377 | room = port->bulk_out_size - (safe ? 2 : 0); |
373 | 378 | ||
374 | if (room) { | 379 | if (room) { |