Commit f6380455 authored by Duncan Sands's avatar Duncan Sands Committed by Greg Kroah-Hartman

[PATCH] USB usbfs: replace the per-file semaphore with the per-device semaphore

 devio.c		|   43 +++++++++++++++++++++++--------------------
 usbdevice_fs.h	|    1 -
 2 files changed, 23 insertions(+), 21 deletions(-)
parent 8e082a0d
...@@ -92,14 +92,15 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig) ...@@ -92,14 +92,15 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig)
static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
{ {
struct dev_state *ps = (struct dev_state *)file->private_data; struct dev_state *ps = (struct dev_state *)file->private_data;
struct usb_device *dev = ps->dev;
ssize_t ret = 0; ssize_t ret = 0;
unsigned len; unsigned len;
loff_t pos; loff_t pos;
int i; int i;
pos = *ppos; pos = *ppos;
down_read(&ps->devsem); down(&dev->serialize);
if (!connected(ps->dev)) { if (!connected(dev)) {
ret = -ENODEV; ret = -ENODEV;
goto err; goto err;
} else if (pos < 0) { } else if (pos < 0) {
...@@ -111,7 +112,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l ...@@ -111,7 +112,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l
len = sizeof(struct usb_device_descriptor) - pos; len = sizeof(struct usb_device_descriptor) - pos;
if (len > nbytes) if (len > nbytes)
len = nbytes; len = nbytes;
if (copy_to_user(buf, ((char *)&ps->dev->descriptor) + pos, len)) { if (copy_to_user(buf, ((char *)&dev->descriptor) + pos, len)) {
ret = -EFAULT; ret = -EFAULT;
goto err; goto err;
} }
...@@ -123,9 +124,9 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l ...@@ -123,9 +124,9 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l
} }
pos = sizeof(struct usb_device_descriptor); pos = sizeof(struct usb_device_descriptor);
for (i = 0; nbytes && i < ps->dev->descriptor.bNumConfigurations; i++) { for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
struct usb_config_descriptor *config = struct usb_config_descriptor *config =
(struct usb_config_descriptor *)ps->dev->rawdescriptors[i]; (struct usb_config_descriptor *)dev->rawdescriptors[i];
unsigned int length = le16_to_cpu(config->wTotalLength); unsigned int length = le16_to_cpu(config->wTotalLength);
if (*ppos < pos + length) { if (*ppos < pos + length) {
...@@ -133,7 +134,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l ...@@ -133,7 +134,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l
/* The descriptor may claim to be longer than it /* The descriptor may claim to be longer than it
* really is. Here is the actual allocated length. */ * really is. Here is the actual allocated length. */
unsigned alloclen = unsigned alloclen =
ps->dev->config[i].desc.wTotalLength; dev->config[i].desc.wTotalLength;
len = length - (*ppos - pos); len = length - (*ppos - pos);
if (len > nbytes) if (len > nbytes)
...@@ -143,7 +144,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l ...@@ -143,7 +144,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l
if (alloclen > (*ppos - pos)) { if (alloclen > (*ppos - pos)) {
alloclen -= (*ppos - pos); alloclen -= (*ppos - pos);
if (copy_to_user(buf, if (copy_to_user(buf,
ps->dev->rawdescriptors[i] + (*ppos - pos), dev->rawdescriptors[i] + (*ppos - pos),
min(len, alloclen))) { min(len, alloclen))) {
ret = -EFAULT; ret = -EFAULT;
goto err; goto err;
...@@ -160,7 +161,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l ...@@ -160,7 +161,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l
} }
err: err:
up_read(&ps->devsem); up(&dev->serialize);
return ret; return ret;
} }
...@@ -521,7 +522,6 @@ static int usbdev_open(struct inode *inode, struct file *file) ...@@ -521,7 +522,6 @@ static int usbdev_open(struct inode *inode, struct file *file)
INIT_LIST_HEAD(&ps->async_pending); INIT_LIST_HEAD(&ps->async_pending);
INIT_LIST_HEAD(&ps->async_completed); INIT_LIST_HEAD(&ps->async_completed);
init_waitqueue_head(&ps->wait); init_waitqueue_head(&ps->wait);
init_rwsem(&ps->devsem);
ps->discsignr = 0; ps->discsignr = 0;
ps->disctask = current; ps->disctask = current;
ps->disccontext = NULL; ps->disccontext = NULL;
...@@ -538,19 +538,20 @@ static int usbdev_open(struct inode *inode, struct file *file) ...@@ -538,19 +538,20 @@ static int usbdev_open(struct inode *inode, struct file *file)
static int usbdev_release(struct inode *inode, struct file *file) static int usbdev_release(struct inode *inode, struct file *file)
{ {
struct dev_state *ps = (struct dev_state *)file->private_data; struct dev_state *ps = (struct dev_state *)file->private_data;
struct usb_device *dev = ps->dev;
unsigned int i; unsigned int i;
lock_kernel(); down(&dev->serialize);
list_del_init(&ps->list); list_del_init(&ps->list);
if (connected(ps->dev)) { if (connected(dev)) {
for (i = 0; ps->ifclaimed && i < 8*sizeof(ps->ifclaimed); i++) for (i = 0; ps->ifclaimed && i < 8*sizeof(ps->ifclaimed); i++)
if (test_bit(i, &ps->ifclaimed)) if (test_bit(i, &ps->ifclaimed))
releaseintf(ps, i); releaseintf(ps, i);
destroy_all_async(ps); destroy_all_async(ps);
} }
unlock_kernel(); up(&dev->serialize);
usb_put_dev(ps->dev); usb_put_dev(dev);
ps->dev = NULL; ps->dev = NULL;
kfree(ps); kfree(ps);
return 0; return 0;
...@@ -1023,18 +1024,19 @@ static int proc_reapurb(struct dev_state *ps, void __user *arg) ...@@ -1023,18 +1024,19 @@ static int proc_reapurb(struct dev_state *ps, void __user *arg)
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
struct async *as = NULL; struct async *as = NULL;
void __user *addr; void __user *addr;
struct usb_device *dev = ps->dev;
int ret; int ret;
add_wait_queue(&ps->wait, &wait); add_wait_queue(&ps->wait, &wait);
while (connected(ps->dev)) { while (connected(dev)) {
__set_current_state(TASK_INTERRUPTIBLE); __set_current_state(TASK_INTERRUPTIBLE);
if ((as = async_getcompleted(ps))) if ((as = async_getcompleted(ps)))
break; break;
if (signal_pending(current)) if (signal_pending(current))
break; break;
up_read(&ps->devsem); up(&dev->serialize);
schedule(); schedule();
down_read(&ps->devsem); down(&dev->serialize);
} }
remove_wait_queue(&ps->wait, &wait); remove_wait_queue(&ps->wait, &wait);
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
...@@ -1201,13 +1203,14 @@ static int proc_ioctl (struct dev_state *ps, void __user *arg) ...@@ -1201,13 +1203,14 @@ static int proc_ioctl (struct dev_state *ps, void __user *arg)
static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{ {
struct dev_state *ps = (struct dev_state *)file->private_data; struct dev_state *ps = (struct dev_state *)file->private_data;
struct usb_device *dev = ps->dev;
int ret = -ENOTTY; int ret = -ENOTTY;
if (!(file->f_mode & FMODE_WRITE)) if (!(file->f_mode & FMODE_WRITE))
return -EPERM; return -EPERM;
down_read(&ps->devsem); down(&dev->serialize);
if (!connected(ps->dev)) { if (!connected(dev)) {
up_read(&ps->devsem); up(&dev->serialize);
return -ENODEV; return -ENODEV;
} }
switch (cmd) { switch (cmd) {
...@@ -1289,7 +1292,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd ...@@ -1289,7 +1292,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
ret = proc_ioctl(ps, (void __user *) arg); ret = proc_ioctl(ps, (void __user *) arg);
break; break;
} }
up_read(&ps->devsem); up(&dev->serialize);
if (ret >= 0) if (ret >= 0)
inode->i_atime = CURRENT_TIME; inode->i_atime = CURRENT_TIME;
return ret; return ret;
......
...@@ -154,7 +154,6 @@ struct usbdevfs_hub_portinfo { ...@@ -154,7 +154,6 @@ struct usbdevfs_hub_portinfo {
struct dev_state { struct dev_state {
struct list_head list; /* state list */ struct list_head list; /* state list */
struct rw_semaphore devsem; /* protects modifications to dev (dev == NULL indicating disconnect) */
struct usb_device *dev; struct usb_device *dev;
struct file *file; struct file *file;
spinlock_t lock; /* protects the async urb lists */ spinlock_t lock; /* protects the async urb lists */
......
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