[PATCH]races in usblp

Oliver Neukum <[email protected]>
Newsgroups gmane.linux.usb.devel
Organization Novell
Message-ID <[email protected]>
Hi,

usblp has an issue with urbs being resubmitted without status being read
first. In this case it is complicated by a race in the write path. Busy is
checked without a lock and the check not redone under lock.

	Regards
		Oliver
Signed-off-by: Oliver Neukum <[email protected]>
-- 

--- a/drivers/usb/class/usblp.c	2007-03-19 10:59:52.000000000 +0100
+++ b/drivers/usb/class/usblp.c	2007-03-30 11:01:47.000000000 +0200
@@ -286,6 +288,7 @@
 	if (unlikely(urb->status))
 		warn("usblp%d: nonzero read/write bulk status received: %d",
 			usblp->minor, urb->status);
+	smp_mb();
 	usblp->rcomplete = 1;
 unplug:
 	wake_up_interruptible(&usblp->wait);
@@ -302,6 +305,7 @@
 	if (unlikely(urb->status))
 		warn("usblp%d: nonzero read/write bulk status received: %d",
 			usblp->minor, urb->status);
+	smp_mb();
 	usblp->wcomplete = 1;
 unplug:
 	wake_up_interruptible(&usblp->wait);
@@ -666,7 +670,7 @@
 				writecount += transfer_length;
 				return writecount ? writecount : -EAGAIN;
 			}
-
+lost_race:
 			timeout = USBLP_WRITE_TIMEOUT;
 
 			rv = wait_event_interruptible_timeout(usblp->wait, usblp->wcomplete || !usblp->present , timeout);
@@ -686,6 +690,17 @@
 			return writecount ? writecount : -ENODEV;
 		}
 
+		/* need to recheck under lock */
+		if (!usblp->wcomplete) { /* lost the race to another thread */
+			mutex_unlock(&usblp->mut);
+			if (writecount) {
+				count = writecount;
+				break;
+			} else {
+				goto lost_race;
+			}
+		}
+
 		if (usblp->writeurb->status != 0) {
 			if (usblp->quirks & USBLP_QUIRK_BIDIR) {
 				if (!usblp->wcomplete)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.