Commit 2cba72f0 authored by Oliver Neukum's avatar Oliver Neukum Committed by Greg Kroah-Hartman

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: default avatarOliver Neukum <oliver@neukum.name>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 47278107
...@@ -69,7 +69,7 @@ struct rio_usb_data { ...@@ -69,7 +69,7 @@ struct rio_usb_data {
char *obuf, *ibuf; /* transfer buffers */ char *obuf, *ibuf; /* transfer buffers */
char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */ char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */
wait_queue_head_t wait_q; /* for timeouts */ 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; static struct rio_usb_data rio_instance;
...@@ -78,17 +78,17 @@ static int open_rio(struct inode *inode, struct file *file) ...@@ -78,17 +78,17 @@ static int open_rio(struct inode *inode, struct file *file)
{ {
struct rio_usb_data *rio = &rio_instance; struct rio_usb_data *rio = &rio_instance;
down(&(rio->lock)); mutex_lock(&(rio->lock));
if (rio->isopen || !rio->present) { if (rio->isopen || !rio->present) {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return -EBUSY; return -EBUSY;
} }
rio->isopen = 1; rio->isopen = 1;
init_waitqueue_head(&rio->wait_q); init_waitqueue_head(&rio->wait_q);
up(&(rio->lock)); mutex_unlock(&(rio->lock));
info("Rio opened."); info("Rio opened.");
...@@ -117,7 +117,7 @@ ioctl_rio(struct inode *inode, struct file *file, unsigned int cmd, ...@@ -117,7 +117,7 @@ ioctl_rio(struct inode *inode, struct file *file, unsigned int cmd,
int retries; int retries;
int retval=0; int retval=0;
down(&(rio->lock)); mutex_lock(&(rio->lock));
/* Sanity check to make sure rio is connected, powered, etc */ /* Sanity check to make sure rio is connected, powered, etc */
if ( rio == NULL || if ( rio == NULL ||
rio->present == 0 || rio->present == 0 ||
...@@ -257,7 +257,7 @@ ioctl_rio(struct inode *inode, struct file *file, unsigned int cmd, ...@@ -257,7 +257,7 @@ ioctl_rio(struct inode *inode, struct file *file, unsigned int cmd,
err_out: err_out:
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return retval; return retval;
} }
...@@ -275,14 +275,17 @@ write_rio(struct file *file, const char __user *buffer, ...@@ -275,14 +275,17 @@ write_rio(struct file *file, const char __user *buffer,
int result = 0; int result = 0;
int maxretry; int maxretry;
int errn = 0; 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 */ /* Sanity check to make sure rio is connected, powered, etc */
if ( rio == NULL || if ( rio == NULL ||
rio->present == 0 || rio->present == 0 ||
rio->rio_dev == NULL ) rio->rio_dev == NULL )
{ {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return -ENODEV; return -ENODEV;
} }
...@@ -305,7 +308,7 @@ write_rio(struct file *file, const char __user *buffer, ...@@ -305,7 +308,7 @@ write_rio(struct file *file, const char __user *buffer,
goto error; goto error;
} }
if (signal_pending(current)) { if (signal_pending(current)) {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return bytes_written ? bytes_written : -EINTR; return bytes_written ? bytes_written : -EINTR;
} }
...@@ -341,12 +344,12 @@ write_rio(struct file *file, const char __user *buffer, ...@@ -341,12 +344,12 @@ write_rio(struct file *file, const char __user *buffer,
buffer += copy_size; buffer += copy_size;
} while (count > 0); } while (count > 0);
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return bytes_written ? bytes_written : -EIO; return bytes_written ? bytes_written : -EIO;
error: error:
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return errn; return errn;
} }
...@@ -361,14 +364,17 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) ...@@ -361,14 +364,17 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
int result; int result;
int maxretry = 10; int maxretry = 10;
char *ibuf; 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 */ /* Sanity check to make sure rio is connected, powered, etc */
if ( rio == NULL || if ( rio == NULL ||
rio->present == 0 || rio->present == 0 ||
rio->rio_dev == NULL ) rio->rio_dev == NULL )
{ {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return -ENODEV; return -ENODEV;
} }
...@@ -379,11 +385,11 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) ...@@ -379,11 +385,11 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
while (count > 0) { while (count > 0) {
if (signal_pending(current)) { if (signal_pending(current)) {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return read_count ? read_count : -EINTR; return read_count ? read_count : -EINTR;
} }
if (!rio->rio_dev) { if (!rio->rio_dev) {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return -ENODEV; return -ENODEV;
} }
this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count; this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count;
...@@ -400,7 +406,7 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) ...@@ -400,7 +406,7 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
count = this_read = partial; count = this_read = partial;
} else if (result == -ETIMEDOUT || result == 15) { /* FIXME: 15 ??? */ } else if (result == -ETIMEDOUT || result == 15) { /* FIXME: 15 ??? */
if (!maxretry--) { if (!maxretry--) {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
err("read_rio: maxretry timeout"); err("read_rio: maxretry timeout");
return -ETIME; return -ETIME;
} }
...@@ -409,18 +415,18 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) ...@@ -409,18 +415,18 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
finish_wait(&rio->wait_q, &wait); finish_wait(&rio->wait_q, &wait);
continue; continue;
} else if (result != -EREMOTEIO) { } else if (result != -EREMOTEIO) {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
err("Read Whoops - result:%u partial:%u this_read:%u", err("Read Whoops - result:%u partial:%u this_read:%u",
result, partial, this_read); result, partial, this_read);
return -EIO; return -EIO;
} else { } else {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return (0); return (0);
} }
if (this_read) { if (this_read) {
if (copy_to_user(buffer, ibuf, this_read)) { if (copy_to_user(buffer, ibuf, this_read)) {
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return -EFAULT; return -EFAULT;
} }
count -= this_read; count -= this_read;
...@@ -428,7 +434,7 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) ...@@ -428,7 +434,7 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
buffer += this_read; buffer += this_read;
} }
} }
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return read_count; return read_count;
} }
...@@ -480,7 +486,7 @@ static int probe_rio(struct usb_interface *intf, ...@@ -480,7 +486,7 @@ static int probe_rio(struct usb_interface *intf,
} }
dbg("probe_rio: ibuf address:%p", rio->ibuf); dbg("probe_rio: ibuf address:%p", rio->ibuf);
init_MUTEX(&(rio->lock)); mutex_init(&(rio->lock));
usb_set_intfdata (intf, rio); usb_set_intfdata (intf, rio);
rio->present = 1; rio->present = 1;
...@@ -496,12 +502,12 @@ static void disconnect_rio(struct usb_interface *intf) ...@@ -496,12 +502,12 @@ static void disconnect_rio(struct usb_interface *intf)
if (rio) { if (rio) {
usb_deregister_dev(intf, &usb_rio_class); usb_deregister_dev(intf, &usb_rio_class);
down(&(rio->lock)); mutex_lock(&(rio->lock));
if (rio->isopen) { if (rio->isopen) {
rio->isopen = 0; rio->isopen = 0;
/* better let it finish - the release will do whats needed */ /* better let it finish - the release will do whats needed */
rio->rio_dev = NULL; rio->rio_dev = NULL;
up(&(rio->lock)); mutex_unlock(&(rio->lock));
return; return;
} }
kfree(rio->ibuf); kfree(rio->ibuf);
...@@ -510,7 +516,7 @@ static void disconnect_rio(struct usb_interface *intf) ...@@ -510,7 +516,7 @@ static void disconnect_rio(struct usb_interface *intf)
info("USB Rio disconnected."); info("USB Rio disconnected.");
rio->present = 0; rio->present = 0;
up(&(rio->lock)); mutex_unlock(&(rio->lock));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment