Commit a79df50b authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Greg Kroah-Hartman

usb: gadgetfs: Convert semaphore to mutex

The semaphore data->lock is semantically a mutex. Convert it to a real
mutex.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent b00ce11f
...@@ -194,7 +194,7 @@ enum ep_state { ...@@ -194,7 +194,7 @@ enum ep_state {
}; };
struct ep_data { struct ep_data {
struct semaphore lock; struct mutex lock;
enum ep_state state; enum ep_state state;
atomic_t count; atomic_t count;
struct dev_data *dev; struct dev_data *dev;
...@@ -298,10 +298,10 @@ get_ready_ep (unsigned f_flags, struct ep_data *epdata) ...@@ -298,10 +298,10 @@ get_ready_ep (unsigned f_flags, struct ep_data *epdata)
int val; int val;
if (f_flags & O_NONBLOCK) { if (f_flags & O_NONBLOCK) {
if (down_trylock (&epdata->lock) != 0) if (!mutex_trylock(&epdata->lock))
goto nonblock; goto nonblock;
if (epdata->state != STATE_EP_ENABLED) { if (epdata->state != STATE_EP_ENABLED) {
up (&epdata->lock); mutex_unlock(&epdata->lock);
nonblock: nonblock:
val = -EAGAIN; val = -EAGAIN;
} else } else
...@@ -309,7 +309,8 @@ nonblock: ...@@ -309,7 +309,8 @@ nonblock:
return val; return val;
} }
if ((val = down_interruptible (&epdata->lock)) < 0) val = mutex_lock_interruptible(&epdata->lock);
if (val < 0)
return val; return val;
switch (epdata->state) { switch (epdata->state) {
...@@ -323,7 +324,7 @@ nonblock: ...@@ -323,7 +324,7 @@ nonblock:
// FALLTHROUGH // FALLTHROUGH
case STATE_EP_UNBOUND: /* clean disconnect */ case STATE_EP_UNBOUND: /* clean disconnect */
val = -ENODEV; val = -ENODEV;
up (&epdata->lock); mutex_unlock(&epdata->lock);
} }
return val; return val;
} }
...@@ -393,7 +394,7 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr) ...@@ -393,7 +394,7 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
if (likely (data->ep != NULL)) if (likely (data->ep != NULL))
usb_ep_set_halt (data->ep); usb_ep_set_halt (data->ep);
spin_unlock_irq (&data->dev->lock); spin_unlock_irq (&data->dev->lock);
up (&data->lock); mutex_unlock(&data->lock);
return -EBADMSG; return -EBADMSG;
} }
...@@ -411,7 +412,7 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr) ...@@ -411,7 +412,7 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
value = -EFAULT; value = -EFAULT;
free1: free1:
up (&data->lock); mutex_unlock(&data->lock);
kfree (kbuf); kfree (kbuf);
return value; return value;
} }
...@@ -436,7 +437,7 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) ...@@ -436,7 +437,7 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
if (likely (data->ep != NULL)) if (likely (data->ep != NULL))
usb_ep_set_halt (data->ep); usb_ep_set_halt (data->ep);
spin_unlock_irq (&data->dev->lock); spin_unlock_irq (&data->dev->lock);
up (&data->lock); mutex_unlock(&data->lock);
return -EBADMSG; return -EBADMSG;
} }
...@@ -455,7 +456,7 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) ...@@ -455,7 +456,7 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
VDEBUG (data->dev, "%s write %zu IN, status %d\n", VDEBUG (data->dev, "%s write %zu IN, status %d\n",
data->name, len, (int) value); data->name, len, (int) value);
free1: free1:
up (&data->lock); mutex_unlock(&data->lock);
kfree (kbuf); kfree (kbuf);
return value; return value;
} }
...@@ -466,7 +467,8 @@ ep_release (struct inode *inode, struct file *fd) ...@@ -466,7 +467,8 @@ ep_release (struct inode *inode, struct file *fd)
struct ep_data *data = fd->private_data; struct ep_data *data = fd->private_data;
int value; int value;
if ((value = down_interruptible(&data->lock)) < 0) value = mutex_lock_interruptible(&data->lock);
if (value < 0)
return value; return value;
/* clean up if this can be reopened */ /* clean up if this can be reopened */
...@@ -476,7 +478,7 @@ ep_release (struct inode *inode, struct file *fd) ...@@ -476,7 +478,7 @@ ep_release (struct inode *inode, struct file *fd)
data->hs_desc.bDescriptorType = 0; data->hs_desc.bDescriptorType = 0;
usb_ep_disable(data->ep); usb_ep_disable(data->ep);
} }
up (&data->lock); mutex_unlock(&data->lock);
put_ep (data); put_ep (data);
return 0; return 0;
} }
...@@ -507,7 +509,7 @@ static long ep_ioctl(struct file *fd, unsigned code, unsigned long value) ...@@ -507,7 +509,7 @@ static long ep_ioctl(struct file *fd, unsigned code, unsigned long value)
} else } else
status = -ENODEV; status = -ENODEV;
spin_unlock_irq (&data->dev->lock); spin_unlock_irq (&data->dev->lock);
up (&data->lock); mutex_unlock(&data->lock);
return status; return status;
} }
...@@ -673,7 +675,7 @@ fail: ...@@ -673,7 +675,7 @@ fail:
value = -ENODEV; value = -ENODEV;
spin_unlock_irq(&epdata->dev->lock); spin_unlock_irq(&epdata->dev->lock);
up(&epdata->lock); mutex_unlock(&epdata->lock);
if (unlikely(value)) { if (unlikely(value)) {
kfree(priv); kfree(priv);
...@@ -765,7 +767,8 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) ...@@ -765,7 +767,8 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
u32 tag; u32 tag;
int value, length = len; int value, length = len;
if ((value = down_interruptible (&data->lock)) < 0) value = mutex_lock_interruptible(&data->lock);
if (value < 0)
return value; return value;
if (data->state != STATE_EP_READY) { if (data->state != STATE_EP_READY) {
...@@ -854,7 +857,7 @@ fail: ...@@ -854,7 +857,7 @@ fail:
data->desc.bDescriptorType = 0; data->desc.bDescriptorType = 0;
data->hs_desc.bDescriptorType = 0; data->hs_desc.bDescriptorType = 0;
} }
up (&data->lock); mutex_unlock(&data->lock);
return value; return value;
fail0: fail0:
value = -EINVAL; value = -EINVAL;
...@@ -870,7 +873,7 @@ ep_open (struct inode *inode, struct file *fd) ...@@ -870,7 +873,7 @@ ep_open (struct inode *inode, struct file *fd)
struct ep_data *data = inode->i_private; struct ep_data *data = inode->i_private;
int value = -EBUSY; int value = -EBUSY;
if (down_interruptible (&data->lock) != 0) if (mutex_lock_interruptible(&data->lock) != 0)
return -EINTR; return -EINTR;
spin_lock_irq (&data->dev->lock); spin_lock_irq (&data->dev->lock);
if (data->dev->state == STATE_DEV_UNBOUND) if (data->dev->state == STATE_DEV_UNBOUND)
...@@ -885,7 +888,7 @@ ep_open (struct inode *inode, struct file *fd) ...@@ -885,7 +888,7 @@ ep_open (struct inode *inode, struct file *fd)
DBG (data->dev, "%s state %d\n", DBG (data->dev, "%s state %d\n",
data->name, data->state); data->name, data->state);
spin_unlock_irq (&data->dev->lock); spin_unlock_irq (&data->dev->lock);
up (&data->lock); mutex_unlock(&data->lock);
return value; return value;
} }
...@@ -1631,7 +1634,7 @@ static int activate_ep_files (struct dev_data *dev) ...@@ -1631,7 +1634,7 @@ static int activate_ep_files (struct dev_data *dev)
if (!data) if (!data)
goto enomem0; goto enomem0;
data->state = STATE_EP_DISABLED; data->state = STATE_EP_DISABLED;
init_MUTEX (&data->lock); mutex_init(&data->lock);
init_waitqueue_head (&data->wait); init_waitqueue_head (&data->wait);
strncpy (data->name, ep->name, sizeof (data->name) - 1); strncpy (data->name, ep->name, sizeof (data->name) - 1);
......
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