Hi list,

as was recently discussed, sleep_on and derivates, which have a little race 
problem are used 21 times in drivers/usb
The attached patch should fix one such place in printer.
It even compiles.
20 more to go. People let's kill them all.

        Regards
                Oliver
--- drivers/usb/printer.c.alt	Wed May  2 10:41:46 2001
+++ drivers/usb/printer.c	Wed May  2 10:49:14 2001
@@ -388,6 +388,7 @@
 static ssize_t usblp_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
 {
 	struct usblp *usblp = file->private_data;
+	DECLARE_WAITQUEUE(wait, current);
 
 	if (!usblp->bidir)
 		return -EINVAL;
@@ -396,12 +397,19 @@
 
 		if (file->f_flags & O_NONBLOCK)
 			return -EAGAIN;
-
+		
+		current->state = TASK_INTERRUPTIBLE;
+		add_wait_queue(&usblp->wait, &wait);
 		while (usblp->readurb.status == -EINPROGRESS) {
-			if (signal_pending(current))
+			if (signal_pending(current)) {
+				remove_wait_queue(&usblp->wait, &wait);
+				current->state = TASK_RUNNING;
 				return -EINTR;
-			interruptible_sleep_on(&usblp->wait);
+			}
+			schedule();
 		}
+		remove_wait_queue(&usblp->wait, &wait);
+		current->state = TASK_RUNNING;
 	}
 
 	if (!usblp->dev)
@@ -668,3 +676,4 @@
 
 MODULE_AUTHOR("Michael Gee, Pavel Machek, Vojtech Pavlik, Randy Dunlap");
 MODULE_DESCRIPTION("USB Printer Device Class driver");
+

Reply via email to