USB: mutexification of rio500

this makes the rio500 misc usb driver use mutexes and turns uninterruptible
sleep into interruptible sleep where the semantics are not affected.

Signed-off-by: Oliver Neukum <oliver@neukum.name>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
index 384fa37..fdf6847 100644
--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -69,7 +69,7 @@
         char *obuf, *ibuf;              /* transfer buffers */
         char bulk_in_ep, bulk_out_ep;   /* Endpoint assignments */
         wait_queue_head_t wait_q;       /* for timeouts */
-	struct semaphore lock;          /* general race avoidance */
+	struct mutex lock;          /* general race avoidance */
 };
 
 static struct rio_usb_data rio_instance;
@@ -78,17 +78,17 @@
 {
 	struct rio_usb_data *rio = &rio_instance;
 
-	down(&(rio->lock));
+	mutex_lock(&(rio->lock));
 
 	if (rio->isopen || !rio->present) {
-		up(&(rio->lock));
+		mutex_unlock(&(rio->lock));
 		return -EBUSY;
 	}
 	rio->isopen = 1;
 
 	init_waitqueue_head(&rio->wait_q);
 
-	up(&(rio->lock));
+	mutex_unlock(&(rio->lock));
 
 	info("Rio opened.");
 
@@ -117,7 +117,7 @@
 	int retries;
 	int retval=0;
 
-	down(&(rio->lock));
+	mutex_lock(&(rio->lock));
         /* Sanity check to make sure rio is connected, powered, etc */
         if ( rio == NULL ||
              rio->present == 0 ||
@@ -257,7 +257,7 @@
 
 
 err_out:
-	up(&(rio->lock));
+	mutex_unlock(&(rio->lock));
 	return retval;
 }
 
@@ -275,14 +275,17 @@
 	int result = 0;
 	int maxretry;
 	int errn = 0;
+	int intr;
 
-	down(&(rio->lock));
+	intr = mutex_lock_interruptible(&(rio->lock));
+	if (intr)
+		return -EINTR;
         /* Sanity check to make sure rio is connected, powered, etc */
         if ( rio == NULL ||
              rio->present == 0 ||
              rio->rio_dev == NULL )
 	{
-		up(&(rio->lock));
+		mutex_unlock(&(rio->lock));
 		return -ENODEV;
 	}
 
@@ -305,7 +308,7 @@
 				goto error;
 			}
 			if (signal_pending(current)) {
-				up(&(rio->lock));
+				mutex_unlock(&(rio->lock));
 				return bytes_written ? bytes_written : -EINTR;
 			}
 
@@ -341,12 +344,12 @@
 		buffer += copy_size;
 	} while (count > 0);
 
-	up(&(rio->lock));
+	mutex_unlock(&(rio->lock));
 
 	return bytes_written ? bytes_written : -EIO;
 
 error:
-	up(&(rio->lock));
+	mutex_unlock(&(rio->lock));
 	return errn;
 }
 
@@ -361,14 +364,17 @@
 	int result;
 	int maxretry = 10;
 	char *ibuf;
+	int intr;
 
-	down(&(rio->lock));
+	intr = mutex_lock_interruptible(&(rio->lock));
+	if (intr)
+		return -EINTR;
 	/* Sanity check to make sure rio is connected, powered, etc */
         if ( rio == NULL ||
              rio->present == 0 ||
              rio->rio_dev == NULL )
 	{
-		up(&(rio->lock));
+		mutex_unlock(&(rio->lock));
 		return -ENODEV;
 	}
 
@@ -379,11 +385,11 @@
 
 	while (count > 0) {
 		if (signal_pending(current)) {
-			up(&(rio->lock));
+			mutex_unlock(&(rio->lock));
 			return read_count ? read_count : -EINTR;
 		}
 		if (!rio->rio_dev) {
-			up(&(rio->lock));
+			mutex_unlock(&(rio->lock));
 			return -ENODEV;
 		}
 		this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count;
@@ -400,7 +406,7 @@
 			count = this_read = partial;
 		} else if (result == -ETIMEDOUT || result == 15) {	/* FIXME: 15 ??? */
 			if (!maxretry--) {
-				up(&(rio->lock));
+				mutex_unlock(&(rio->lock));
 				err("read_rio: maxretry timeout");
 				return -ETIME;
 			}
@@ -409,18 +415,18 @@
 			finish_wait(&rio->wait_q, &wait);
 			continue;
 		} else if (result != -EREMOTEIO) {
-			up(&(rio->lock));
+			mutex_unlock(&(rio->lock));
 			err("Read Whoops - result:%u partial:%u this_read:%u",
 			     result, partial, this_read);
 			return -EIO;
 		} else {
-			up(&(rio->lock));
+			mutex_unlock(&(rio->lock));
 			return (0);
 		}
 
 		if (this_read) {
 			if (copy_to_user(buffer, ibuf, this_read)) {
-				up(&(rio->lock));
+				mutex_unlock(&(rio->lock));
 				return -EFAULT;
 			}
 			count -= this_read;
@@ -428,7 +434,7 @@
 			buffer += this_read;
 		}
 	}
-	up(&(rio->lock));
+	mutex_unlock(&(rio->lock));
 	return read_count;
 }
 
@@ -480,7 +486,7 @@
 	}
 	dbg("probe_rio: ibuf address:%p", rio->ibuf);
 
-	init_MUTEX(&(rio->lock));
+	mutex_init(&(rio->lock));
 
 	usb_set_intfdata (intf, rio);
 	rio->present = 1;
@@ -496,12 +502,12 @@
 	if (rio) {
 		usb_deregister_dev(intf, &usb_rio_class);
 
-		down(&(rio->lock));
+		mutex_lock(&(rio->lock));
 		if (rio->isopen) {
 			rio->isopen = 0;
 			/* better let it finish - the release will do whats needed */
 			rio->rio_dev = NULL;
-			up(&(rio->lock));
+			mutex_unlock(&(rio->lock));
 			return;
 		}
 		kfree(rio->ibuf);
@@ -510,7 +516,7 @@
 		info("USB Rio disconnected.");
 
 		rio->present = 0;
-		up(&(rio->lock));
+		mutex_unlock(&(rio->lock));
 	}
 }