From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
Greg Kroah-Hartman <gregkh@suse.de>
Subject: [Patch RFC 23/37] usb: gadgetfs: Convert semaphore to mutex
Date: Sun, 26 Jul 2009 08:18:56 -0000 [thread overview]
Message-ID: <20090726081556.264284945@linutronix.de> (raw)
In-Reply-To: 20090726081459.455111897@linutronix.de
[-- Attachment #1: usb-gadget-inode-convert-semaphore-to-mutex.patch --]
[-- Type: text/plain, Size: 4544 bytes --]
The semaphore is used as mutex so make it a 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
@@ -193,7 +193,7 @@ enum ep_state {
};
struct ep_data {
- struct semaphore lock;
+ struct mutex lock;
enum ep_state state;
atomic_t count;
struct dev_data *dev;
@@ -297,10 +297,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) != 0)
goto nonblock;
if (epdata->state != STATE_EP_ENABLED) {
- up (&epdata->lock);
+ mutex_unlock(&epdata->lock);
nonblock:
val = -EAGAIN;
} else
@@ -308,7 +308,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) {
@@ -322,7 +323,7 @@ nonblock:
// FALLTHROUGH
case STATE_EP_UNBOUND: /* clean disconnect */
val = -ENODEV;
- up (&epdata->lock);
+ mutex_unlock(&epdata->lock);
}
return val;
}
@@ -392,7 +393,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;
}
@@ -410,7 +411,7 @@ ep_read (struct file *fd, char __user *b
value = -EFAULT;
free1:
- up (&data->lock);
+ mutex_unlock(&data->lock);
kfree (kbuf);
return value;
}
@@ -435,7 +436,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;
}
@@ -454,7 +455,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;
}
@@ -465,7 +466,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 */
@@ -475,7 +477,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;
}
@@ -506,7 +508,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;
}
@@ -672,7 +674,7 @@ fail:
value = -ENODEV;
spin_unlock_irq(&epdata->dev->lock);
- up(&epdata->lock);
+ mutex_unlock(&epdata->lock);
if (unlikely(value)) {
kfree(priv);
@@ -764,7 +766,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) {
@@ -853,7 +856,7 @@ fail:
data->desc.bDescriptorType = 0;
data->hs_desc.bDescriptorType = 0;
}
- up (&data->lock);
+ mutex_unlock(&data->lock);
return value;
fail0:
value = -EINVAL;
@@ -869,7 +872,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)
@@ -884,7 +887,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;
}
@@ -1630,7 +1633,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:[~2009-07-26 8:20 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-26 8:17 [Patch RFC 00/37] Cleanup init_MUTEX[_LOCKED] / DECLARE_MUTEX Thomas Gleixner
2009-07-26 8:17 ` [Patch RFC 01/37] semaphore: Add DEFINE_SEMAPHORE, semaphore_init, semaphore_init_locked Thomas Gleixner
2009-07-26 23:04 ` Daniel Walker
2009-07-27 15:25 ` Christoph Hellwig
2009-07-27 15:32 ` Thomas Gleixner
2009-07-27 15:24 ` Christoph Hellwig
2009-07-26 8:17 ` [Patch RFC 02/37] input: keyboard/hil_kbd: semaphore cleanup Thomas Gleixner
2009-07-28 7:36 ` Dmitry Torokhov
2009-07-26 8:17 ` [Patch RFC 03/37] input: misc/hp_sdc_rtc: " Thomas Gleixner
2009-07-26 8:17 ` [Patch RFC 04/37] input: mouse/hil_ptr: " Thomas Gleixner
2009-07-26 8:17 ` [Patch RFC 05/37] input: serio/hil_mlc: " Thomas Gleixner
2009-07-26 8:17 ` [Patch RFC 06/37] input: serio/hp_sdc: " Thomas Gleixner
2009-07-26 8:17 ` [Patch RFC 07/37] net: 3c527: " Thomas Gleixner
2009-07-26 8:17 ` [Patch RFC 08/37] hamradio: 6pack: " Thomas Gleixner
2009-07-26 8:17 ` [Patch RFC 09/37] hamradio: mkiss: " Thomas Gleixner
2009-07-26 8:17 ` [Patch RFC 10/37] net: ppp_async: " Thomas Gleixner
2009-07-26 8:18 ` [Patch RFC 11/37] parport: " Thomas Gleixner
2009-07-26 8:18 ` [Patch RFC 12/37] ibmphp-hpc: " Thomas Gleixner
2009-07-26 8:18 ` [Patch RFC 13/37] s390: cio/crw: " Thomas Gleixner
2009-07-27 11:45 ` Martin Schwidefsky
2009-07-26 8:18 ` [Patch RFC 14/37] scsi: aacraid " Thomas Gleixner
2009-07-26 20:11 ` James Bottomley
2009-07-26 22:21 ` Thomas Gleixner
2009-07-26 8:18 ` [Patch RFC 15/37] bluetooth: Convert hdev->req_lock to mutex Thomas Gleixner
2009-07-26 21:36 ` Marcel Holtmann
2009-07-26 22:04 ` Thomas Gleixner
2009-07-26 8:18 ` [Patch RFC 16/37] smbfs: Convert server->sem " Thomas Gleixner
2009-07-26 8:18 ` [Patch RFC 17/37] hpfs: Convert sbi->hpfs_creation_de " Thomas Gleixner
2009-07-26 8:18 ` [Patch RFC 18/37] hpfsplus: Convert tree_lock " Thomas Gleixner
2009-07-26 8:18 ` [Patch RFC 19/37] hfs: " Thomas Gleixner
2009-07-26 8:18 ` [Patch RFC 20/37] cifs: convert semaphore " Thomas Gleixner
2009-07-27 1:14 ` Jeff Layton
2009-07-30 21:09 ` Christoph Hellwig
2009-07-30 22:43 ` Steven French
2009-07-26 8:18 ` [Patch RFC 21/37] affs: use semaphore_init instead of init_MUTEX Thomas Gleixner
2009-07-30 21:14 ` Christoph Hellwig
2009-07-26 8:18 ` [Patch RFC 22/37] usb: ftdi-elan: Convert "mutex" to semaphore Thomas Gleixner
2009-07-26 8:18 ` Thomas Gleixner [this message]
2009-07-26 22:56 ` [Patch RFC 23/37] usb: gadgetfs: Convert semaphore to mutex Daniel Walker
2009-07-26 8:19 ` [Patch RFC 24/37] xfs: semaphore cleanup Thomas Gleixner
2009-07-27 15:25 ` Christoph Hellwig
2009-07-26 8:19 ` [Patch RFC 25/37] net: wan/cosa.c: Convert "mutex" to semaphore Thomas Gleixner
2009-07-26 8:19 ` [Patch RFC 26/37] irda: semaphore cleanup Thomas Gleixner
2009-07-26 8:19 ` [Patch RFC 27/37] mmc: Convert "mutex" to semaphore Thomas Gleixner
2009-07-26 8:19 ` [Patch RFC 28/37] dvb: " Thomas Gleixner
2009-07-26 8:19 ` [Patch RFC 29/37] infiniband: Make user_mad semaphore a real one Thomas Gleixner
2009-07-27 16:26 ` Roland Dreier
2009-07-27 16:28 ` Thomas Gleixner
2009-07-26 8:19 ` [Patch RFC 30/37] drivers/base: Convert dev->sem to mutex Thomas Gleixner
2009-07-26 8:19 ` [Patch RFC 31/37] ia64: salinfo: semaphore_init instead of init_MUTEX Thomas Gleixner
2009-07-26 8:19 ` [Patch RFC 32/37] drivers/macintosh/adb: Do not claim that the semaphore is a mutex Thomas Gleixner
2009-07-26 8:20 ` [Patch RFC 33/37] arm: w90x900: convert semaphore to mutex Thomas Gleixner
2009-07-27 3:11 ` Wan ZongShun
2009-07-26 8:20 ` [Patch RFC 34/37] printk: Make console_sem a semaphore not a pseudo mutex Thomas Gleixner
2009-07-26 8:20 ` [Patch RFC 35/37] staging: Bulk convert the semaphore mess Thomas Gleixner
2009-07-26 8:20 ` [Patch RFC 36/37] fs: Convert bd_mount_sem to mutex Thomas Gleixner
2009-07-27 15:26 ` Christoph Hellwig
2009-07-27 15:30 ` Thomas Gleixner
2009-07-27 16:42 ` Daniel Walker
2009-07-26 8:20 ` [Patch RFC 37/37] semaphore: Remove mutex emulation 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=20090726081556.264284945@linutronix.de \
--to=tglx@linutronix.de \
--cc=akpm@linux-foundation.org \
--cc=gregkh@suse.de \
--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