From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@elte.hu>, Greg Kroah-Hartman <gregkh@suse.de>
Subject: [patch 07/10] usb: gadgetfs: Convert semaphore to mutex
Date: Fri, 29 Jan 2010 20:38:59 -0000 [thread overview]
Message-ID: <20100129203613.628793121@linutronix.de> (raw)
In-Reply-To: 20100129203549.526478432@linutronix.de
[-- Attachment #1: usb-gadgetfs-convert-sema.patch --]
[-- Type: text/plain, Size: 4568 bytes --]
The semaphore data->lock is semantically a mutex. Convert it to a real
mutex.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
---
drivers/usb/gadget/inode.c | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
Index: linux-2.6-tip/drivers/usb/gadget/inode.c
===================================================================
--- linux-2.6-tip.orig/drivers/usb/gadget/inode.c
+++ linux-2.6-tip/drivers/usb/gadget/inode.c
@@ -194,7 +194,7 @@ enum ep_state {
};
struct ep_data {
- struct semaphore lock;
+ struct mutex lock;
enum ep_state state;
atomic_t count;
struct dev_data *dev;
@@ -298,10 +298,10 @@ get_ready_ep (unsigned f_flags, struct e
int val;
if (f_flags & O_NONBLOCK) {
- if (down_trylock (&epdata->lock) != 0)
+ if (!mutex_trylock(&epdata->lock))
goto nonblock;
if (epdata->state != STATE_EP_ENABLED) {
- up (&epdata->lock);
+ mutex_unlock(&epdata->lock);
nonblock:
val = -EAGAIN;
} else
@@ -309,7 +309,8 @@ nonblock:
return val;
}
- if ((val = down_interruptible (&epdata->lock)) < 0)
+ val = mutex_lock_interruptible(&epdata->lock);
+ if (val < 0)
return val;
switch (epdata->state) {
@@ -323,7 +324,7 @@ nonblock:
// FALLTHROUGH
case STATE_EP_UNBOUND: /* clean disconnect */
val = -ENODEV;
- up (&epdata->lock);
+ mutex_unlock(&epdata->lock);
}
return val;
}
@@ -393,7 +394,7 @@ ep_read (struct file *fd, char __user *b
if (likely (data->ep != NULL))
usb_ep_set_halt (data->ep);
spin_unlock_irq (&data->dev->lock);
- up (&data->lock);
+ mutex_unlock(&data->lock);
return -EBADMSG;
}
@@ -411,7 +412,7 @@ ep_read (struct file *fd, char __user *b
value = -EFAULT;
free1:
- up (&data->lock);
+ mutex_unlock(&data->lock);
kfree (kbuf);
return value;
}
@@ -436,7 +437,7 @@ ep_write (struct file *fd, const char __
if (likely (data->ep != NULL))
usb_ep_set_halt (data->ep);
spin_unlock_irq (&data->dev->lock);
- up (&data->lock);
+ mutex_unlock(&data->lock);
return -EBADMSG;
}
@@ -455,7 +456,7 @@ ep_write (struct file *fd, const char __
VDEBUG (data->dev, "%s write %zu IN, status %d\n",
data->name, len, (int) value);
free1:
- up (&data->lock);
+ mutex_unlock(&data->lock);
kfree (kbuf);
return value;
}
@@ -466,7 +467,8 @@ ep_release (struct inode *inode, struct
struct ep_data *data = fd->private_data;
int value;
- if ((value = down_interruptible(&data->lock)) < 0)
+ value = mutex_lock_interruptible(&data->lock);
+ if (value < 0)
return value;
/* clean up if this can be reopened */
@@ -476,7 +478,7 @@ ep_release (struct inode *inode, struct
data->hs_desc.bDescriptorType = 0;
usb_ep_disable(data->ep);
}
- up (&data->lock);
+ mutex_unlock(&data->lock);
put_ep (data);
return 0;
}
@@ -507,7 +509,7 @@ static long ep_ioctl(struct file *fd, un
} else
status = -ENODEV;
spin_unlock_irq (&data->dev->lock);
- up (&data->lock);
+ mutex_unlock(&data->lock);
return status;
}
@@ -673,7 +675,7 @@ fail:
value = -ENODEV;
spin_unlock_irq(&epdata->dev->lock);
- up(&epdata->lock);
+ mutex_unlock(&epdata->lock);
if (unlikely(value)) {
kfree(priv);
@@ -765,7 +767,8 @@ ep_config (struct file *fd, const char _
u32 tag;
int value, length = len;
- if ((value = down_interruptible (&data->lock)) < 0)
+ value = mutex_lock_interruptible(&data->lock);
+ if (value < 0)
return value;
if (data->state != STATE_EP_READY) {
@@ -854,7 +857,7 @@ fail:
data->desc.bDescriptorType = 0;
data->hs_desc.bDescriptorType = 0;
}
- up (&data->lock);
+ mutex_unlock(&data->lock);
return value;
fail0:
value = -EINVAL;
@@ -870,7 +873,7 @@ ep_open (struct inode *inode, struct fil
struct ep_data *data = inode->i_private;
int value = -EBUSY;
- if (down_interruptible (&data->lock) != 0)
+ if (mutex_lock_interruptible(&data->lock) != 0)
return -EINTR;
spin_lock_irq (&data->dev->lock);
if (data->dev->state == STATE_DEV_UNBOUND)
@@ -885,7 +888,7 @@ ep_open (struct inode *inode, struct fil
DBG (data->dev, "%s state %d\n",
data->name, data->state);
spin_unlock_irq (&data->dev->lock);
- up (&data->lock);
+ mutex_unlock(&data->lock);
return value;
}
@@ -1631,7 +1634,7 @@ static int activate_ep_files (struct dev
if (!data)
goto enomem0;
data->state = STATE_EP_DISABLED;
- init_MUTEX (&data->lock);
+ mutex_init(&data->lock);
init_waitqueue_head (&data->wait);
strncpy (data->name, ep->name, sizeof (data->name) - 1);
next prev parent reply other threads:[~2010-01-29 20:40 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
2010-01-29 20:38 ` [patch 01/10] smbfs: Convert server->sem to mutex Thomas Gleixner
2010-01-29 22:14 ` Christoph Hellwig
2010-01-29 20:38 ` [patch 02/10] hpfs: Convert sbi->hpfs_creation_de " Thomas Gleixner
2010-01-29 22:20 ` Christoph Hellwig
2010-01-29 20:38 ` [patch 03/10] hpfsplus: Convert tree_lock " Thomas Gleixner
2010-01-29 22:23 ` Christoph Hellwig
2010-01-29 20:38 ` [patch 04/10] hfs: " Thomas Gleixner
2010-01-29 22:26 ` Christoph Hellwig
2010-01-29 20:38 ` [patch 05/10] cifs: convert semaphore " Thomas Gleixner
2010-01-29 22:29 ` Christoph Hellwig
2010-01-29 20:38 ` [patch 06/10] affs: Convert semaphores to mutexes Thomas Gleixner
2010-01-29 22:25 ` Al Viro
2010-01-29 22:36 ` Christoph Hellwig
2010-01-29 23:03 ` Thomas Gleixner
2010-01-29 23:41 ` Al Viro
2010-01-29 20:38 ` Thomas Gleixner [this message]
2010-01-29 21:14 ` [patch 07/10] usb: gadgetfs: Convert semaphore to mutex Greg KH
2010-01-29 21:48 ` Thomas Gleixner
2010-01-29 22:07 ` Greg KH
2010-01-29 23:04 ` Thomas Gleixner
2010-01-30 5:27 ` Greg KH
2010-01-29 20:39 ` [patch 08/10] drivers/base: Convert dev->sem " Thomas Gleixner
2010-01-29 21:13 ` Greg KH
2010-01-29 21:48 ` Thomas Gleixner
2010-01-30 5:26 ` Greg KH
2010-01-29 20:39 ` [patch 09/10] block: drbd: Convert semaphore " Thomas Gleixner
2010-01-29 20:39 ` [patch 10/10] hwmon: s3c-hwmon: " Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100129203613.628793121@linutronix.de \
--to=tglx@linutronix.de \
--cc=gregkh@suse.de \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox