Skip to contentSkip to conversation

Cleanup init_MUTEX[_LOCKED] / DECLARE_MUTEX

RFC PATCH In review Thomas Gleixner 11 participants 60 messages Jul 26, 2009 – Jul 30, 2009

Subsystems (31)
lore
Share & tools
lore
#0 lore raw

cover Cleanup init_MUTEX[_LOCKED] / DECLARE_MUTEX

There are still semaphores left which are used as mutexes. Many of them are not mutexes; they are used as completions and serialization object at the same time. Some others are simple mutexes and nobody bothered to clean them up.

Most of the cases have been identified in the preempt-rt patch. The conversion to mutexes has been tested with both lockdep and mutex debugging for quite a time. The other semaphore style users are simply converted to semaphores and the init_MUTEX[_LOCKED] / DECLARE_MUTEX confusion is removed.

Andrew: it would be great if we could merge the infrastructure patch [1/n] right away. It does not change any code as it just adds DEFINE_SEMAPHORE, semaphore_init() and semaphore_init_locked(). The latter is marked deprecated as well as the locked init usually points to a completion like use case. Merging it now would allow the maintainers to queue up the cleanup patches for .32

Thanks,

tglx

#1 lore raw

RFC PATCH 1/37 semaphore: Add DEFINE_SEMAPHORE, semaphore_init, semaphore_init_locked

The full cleanup of init_MUTEX[_LOCKED] and DECLARE_MUTEX has not been done. Some of the users are real semaphores and we should name them as such instead of confusing everyone with "MUTEX".

Provide the infrastructure to get finally rid of init_MUTEX[_LOCKED] and DECLARE_MUTEX.

---
 include/linux/semaphore.h |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/linux/semaphore.h +17 -0
Index: linux-2.6-tip/include/linux/semaphore.h
===================================================================
@@ -26,6 +26,9 @@ struct semaphore {
 	.wait_list	= LIST_HEAD_INIT((name).wait_list),		\
 }
 
+#define DEFINE_SEMAPHORE(name)	\
+	struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
+
 #define DECLARE_MUTEX(name)	\
 	struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
 
@@ -36,6 +39,20 @@ static inline void sema_init(struct sema
 	lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
 }
 
+static inline void semaphore_init(struct semanphore *sem)
+{
+	sema_init(sem, 1);
+}
+
+/*
+ * semaphore_init_locked() is mostly a sign for a mutex which is
+ * abused as completion.
+ */
+static inline void __deprecated semaphore_init_locked(struct semanphore *sem)
+{
+	sema_init(sem, 0);
+}
+
 #define init_MUTEX(sem)		sema_init(sem, 1)
 #define init_MUTEX_LOCKED(sem)	sema_init(sem, 0)
 
#2 lore raw

Re: [Patch RFC 01/37] semaphore: Add DEFINE_SEMAPHORE, semaphore_init, semaphore_init_locked

include/linux/semaphore.h static inline void sema_init(struct sema · line 57

Quoted 7 lines · Thomas Gleixner
include/linux/semaphore.h +5 -0
+static inline void __deprecated semaphore_init_locked(struct semanphore *sem)
+{
+	sema_init(sem, 0);
+}
+
 #define init_MUTEX(sem)		sema_init(sem, 1)
 #define init_MUTEX_LOCKED(sem)	sema_init(sem, 0)

Maybe you could introduce this _after_ you do the semaphore to completion cleanup .. This init_locked is just adding a bunch of code flux on top of that..

Daniel

#3 lore raw

Re: [Patch RFC 01/37] semaphore: Add DEFINE_SEMAPHORE, semaphore_init, semaphore_init_locked

Quoted 3 lines · Daniel Walker

Maybe you could introduce this _after_ you do the semaphore to completion cleanup .. This init_locked is just adding a bunch of code flux on top of that..

I agree. For these 36 patches we should first check if they can be trivially converted to mutexes or completions and only change them away to the semaphore named initializers.

#4 lore raw

Re: [Patch RFC 01/37] semaphore: Add DEFINE_SEMAPHORE, semaphore_init, semaphore_init_locked

Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Daniel Walker

Maybe you could introduce this _after_ you do the semaphore to completion cleanup .. This init_locked is just adding a bunch of code flux on top of that..

I agree. For these 36 patches we should first check if they can be trivially converted to mutexes or completions and only change them away to the semaphore named initializers.

I have already converted some of the users to mutexes where it was obvious. It's part of the series.

Thanks,

tglx

#5 lore raw

Re: [Patch RFC 01/37] semaphore: Add DEFINE_SEMAPHORE, semaphore_init, semaphore_init_locked

In reply to Thomas Gleixner
Quoted 11 lines · Thomas Gleixner

The full cleanup of init_MUTEX[_LOCKED] and DECLARE_MUTEX has not been done. Some of the users are real semaphores and we should name them as such instead of confusing everyone with "MUTEX".

include/linux/semaphore.h +6 -0
+#define DEFINE_SEMAPHORE(name)	\
+	struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
+
 
+static inline void semaphore_init(struct semanphore *sem)
+{
+	sema_init(sem, 1);

include/linux/semaphore.h static inline void sema_init(struct sema · line 54

Quoted 10 lines
include/linux/semaphore.h +10 -0
+}
+
+/*
+ * semaphore_init_locked() is mostly a sign for a mutex which is
+ * abused as completion.
+ */
+static inline void __deprecated semaphore_init_locked(struct semanphore *sem)
+{
+	sema_init(sem, 0);
+}

The CS literature doesn't really know about a default value for counting semaphores. I think you're better off converting init_MUTEX and init_MUTEX_locked to explicit sema_init use than adding these and introducing another semaphore_* namespace in addition to the sema_* we already have. Adding a DEFINE_SEMAPHORE makes sense, but it should take a second argument for it's initial value.

#6 lore raw

RFC PATCH 2/37 input: keyboard/hil_kbd: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/input/keyboard/hil_kbd.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/keyboard/hil_kbd.c +1 -1
Index: linux-2.6-tip/drivers/input/keyboard/hil_kbd.c
===================================================================
@@ -277,7 +277,7 @@ static int hil_kbd_connect(struct serio 
 	serio_set_drvdata(serio, kbd);
 	kbd->serio = serio;
 
-	init_MUTEX_LOCKED(&kbd->sem);
+	semaphore_init_locked(&kbd->sem);
 
 	/* Get device info.  MLC driver supplies devid/status/etc. */
 	serio->write(serio, 0);
maintainer
#7 lore raw

Re: [Patch RFC 02/37] input: keyboard/hil_kbd: semaphore cleanup

Quoted 14 lines · Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/input/keyboard/hil_kbd.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6-tip/drivers/input/keyboard/hil_kbd.c
===================================================================

drivers/input/keyboard/hil_kbd.c static int hil_kbd_connect(struct serio · line 281

Quoted 6 lines
drivers/input/keyboard/hil_kbd.c +1 -1
@@ -277,7 +277,7 @@ static int hil_kbd_connect(struct serio 
 	serio_set_drvdata(serio, kbd);
 	kbd->serio = serio;
 
-	init_MUTEX_LOCKED(&kbd->sem);
+	semaphore_init_locked(&kbd->sem);
 

I started working on conversion of that into a completion, I'll commit as soon as I get someone to test it.

Signature · 1 line
Dmitry
#8 lore raw

RFC PATCH 3/37 input: misc/hp_sdc_rtc: semaphore cleanup

In reply to Thomas Gleixner

The usage of these "mutex"es is non obvious and probably a completion in some places. Make them semaphores.

---
 drivers/input/misc/hp_sdc_rtc.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/input/misc/hp_sdc_rtc.c +2 -2
Index: linux-2.6-tip/drivers/input/misc/hp_sdc_rtc.c
===================================================================
@@ -104,7 +104,7 @@ static int hp_sdc_rtc_do_read_bbrtc (str
 	t.endidx =		91;
 	t.seq =			tseq;
 	t.act.semaphore =	&tsem;
-	init_MUTEX_LOCKED(&tsem);
+	semaphore_init_locked(&tsem);
 	
 	if (hp_sdc_enqueue_transaction(&t)) return -1;
 	
@@ -686,7 +686,7 @@ static int __init hp_sdc_rtc_init(void)
 		return -ENODEV;
 #endif
 
-	init_MUTEX(&i8042tregs);
+	semaphore_init(&i8042tregs);
 
 	if ((ret = hp_sdc_request_timer_irq(&hp_sdc_rtc_isr)))
 		return ret;
#9 lore raw

RFC PATCH 4/37 input: mouse/hil_ptr: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/input/mouse/hil_ptr.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/mouse/hil_ptr.c +1 -1
Index: linux-2.6-tip/drivers/input/mouse/hil_ptr.c
===================================================================
@@ -270,7 +270,7 @@ static int hil_ptr_connect(struct serio 
 	serio_set_drvdata(serio, ptr);
 	ptr->serio = serio;
 
-	init_MUTEX_LOCKED(&ptr->sem);
+	semaphore_init_locked(&ptr->sem);
 
 	/* Get device info.  MLC driver supplies devid/status/etc. */
 	serio->write(serio, 0);
#10 lore raw

RFC PATCH 5/37 input: serio/hil_mlc: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/input/serio/hil_mlc.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/input/serio/hil_mlc.c +3 -3
Index: linux-2.6-tip/drivers/input/serio/hil_mlc.c
===================================================================
@@ -914,15 +914,15 @@ int hil_mlc_register(hil_mlc *mlc)
 	mlc->ostarted = 0;
 
 	rwlock_init(&mlc->lock);
-	init_MUTEX(&mlc->osem);
+	semaphore_init(&mlc->osem);
 
-	init_MUTEX(&mlc->isem);
+	semaphore_init(&mlc->isem);
 	mlc->icount = -1;
 	mlc->imatch = 0;
 
 	mlc->opercnt = 0;
 
-	init_MUTEX_LOCKED(&(mlc->csem));
+	semaphore_init(&(mlc->csem));
 
 	hil_mlc_clear_di_scratch(mlc);
 	hil_mlc_clear_di_map(mlc, 0);
#11 lore raw

RFC PATCH 6/37 input: serio/hp_sdc: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/input/serio/hp_sdc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/serio/hp_sdc.c +1 -1
Index: linux-2.6-tip/drivers/input/serio/hp_sdc.c
===================================================================
@@ -1039,7 +1039,7 @@ static int __init hp_sdc_register(void)
 		return hp_sdc.dev_err;
 	}
 
-	init_MUTEX_LOCKED(&tq_init_sem);
+	semaphore_init(&tq_init_sem);
 
 	tq_init.actidx		= 0;
 	tq_init.idx		= 1;
#12 lore raw

RFC PATCH 7/37 net: 3c527: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/net/3c527.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/3c527.c +1 -1
Index: linux-2.6-tip/drivers/net/3c527.c
===================================================================
@@ -521,7 +521,7 @@ static int __init mc32_probe1(struct net
 	lp->tx_len 		= lp->exec_box->data[9];   /* Transmit list count */
 	lp->rx_len 		= lp->exec_box->data[11];  /* Receive list count */
 
-	init_MUTEX_LOCKED(&lp->cmd_mutex);
+	semaphore_init_locked(&lp->cmd_mutex);
 	init_completion(&lp->execution_cmd);
 	init_completion(&lp->xceiver_cmd);
 
#13 lore raw

RFC PATCH 8/37 hamradio: 6pack: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/net/hamradio/6pack.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/hamradio/6pack.c +1 -1
Index: linux-2.6-tip/drivers/net/hamradio/6pack.c
===================================================================
@@ -606,7 +606,7 @@ static int sixpack_open(struct tty_struc
 
 	spin_lock_init(&sp->lock);
 	atomic_set(&sp->refcnt, 1);
-	init_MUTEX_LOCKED(&sp->dead_sem);
+	semaphore_init_locked(&sp->dead_sem);
 
 	/* !!! length of the buffers. MTU is IP MTU, not PACLEN!  */
 
#14 lore raw

RFC PATCH 9/37 hamradio: mkiss: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/net/hamradio/mkiss.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/hamradio/mkiss.c +1 -1
Index: linux-2.6-tip/drivers/net/hamradio/mkiss.c
===================================================================
@@ -745,7 +745,7 @@ static int mkiss_open(struct tty_struct 
 
 	spin_lock_init(&ax->buflock);
 	atomic_set(&ax->refcnt, 1);
-	init_MUTEX_LOCKED(&ax->dead_sem);
+	semaphore_init_locked(&ax->dead_sem);
 
 	ax->tty = tty;
 	tty->disc_data = ax;
#15 lore raw

RFC PATCH 10/37 net: ppp_async: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/net/ppp_async.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ppp_async.c +1 -1
Index: linux-2.6-tip/drivers/net/ppp_async.c
===================================================================
@@ -183,7 +183,7 @@ ppp_asynctty_open(struct tty_struct *tty
 	tasklet_init(&ap->tsk, ppp_async_process, (unsigned long) ap);
 
 	atomic_set(&ap->refcnt, 1);
-	init_MUTEX_LOCKED(&ap->dead_sem);
+	semaphore_init_locked(&ap->dead_sem);
 
 	ap->chan.private = ap;
 	ap->chan.ops = &async_ops;
#16 lore raw

RFC PATCH 11/37 parport: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/parport/share.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/parport/share.c +1 -1
Index: linux-2.6-tip/drivers/parport/share.c
===================================================================
@@ -306,7 +306,7 @@ struct parport *parport_register_port(un
 	spin_lock_init(&tmp->pardevice_lock);
 	tmp->ieee1284.mode = IEEE1284_MODE_COMPAT;
 	tmp->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
-	init_MUTEX_LOCKED (&tmp->ieee1284.irq); /* actually a semaphore at 0 */
+	semaphore_init_locked(&tmp->ieee1284.irq);
 	tmp->spintime = parport_default_spintime;
 	atomic_set (&tmp->ref_count, 1);
 	INIT_LIST_HEAD(&tmp->full_list);
#17 lore raw

RFC PATCH 12/37 ibmphp-hpc: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex"es is non obvious and probably a completion in some places. Make them semaphores.

Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/pci/hotplug/ibmphp_hpc.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/hotplug/ibmphp_hpc.c +2 -2
Index: linux-2.6-tip/drivers/pci/hotplug/ibmphp_hpc.c
===================================================================
@@ -132,8 +132,8 @@ void __init ibmphp_hpc_initvars (void)
 	debug ("%s - Entry\n", __func__);
 
 	mutex_init(&sem_hpcaccess);
-	init_MUTEX (&semOperations);
-	init_MUTEX_LOCKED (&sem_exit);
+	semaphore_init(&semOperations);
+	semaphore_init_locked(&sem_exit);
 	to_debug = 0;
 
 	debug ("%s - Exit\n", __func__);
#18 lore raw

RFC PATCH 13/37 s390: cio/crw: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

Cc Martin Schwidefsky <[email protected]>
---
 drivers/s390/cio/crw.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/cio/crw.c +1 -1
Index: linux-2.6-tip/drivers/s390/cio/crw.c
===================================================================
@@ -137,7 +137,7 @@ void crw_handle_channel_report(void)
  */
 static int __init crw_init_semaphore(void)
 {
-	init_MUTEX_LOCKED(&crw_semaphore);
+	semaphore_init_locked(&crw_semaphore);
 	return 0;
 }
 pure_initcall(crw_init_semaphore);
Acked-by on v1 13/37
#19 lore raw

Re: [Patch RFC 13/37] s390: cio/crw: semaphore cleanup

Quoted 16 lines · On Sun, 26 Jul 2009 08:18:10 -0000 Thomas Gleixner <[email protected]> wrote:

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

Cc Martin Schwidefsky <[email protected]>
---
 drivers/s390/cio/crw.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6-tip/drivers/s390/cio/crw.c
===================================================================

drivers/s390/cio/crw.c void crw_handle_channel_report(void) · line 143

Quoted 8 lines
drivers/s390/cio/crw.c +1 -1
@@ -137,7 +137,7 @@ void crw_handle_channel_report(void)
  */
 static int __init crw_init_semaphore(void)
 {
-	init_MUTEX_LOCKED(&crw_semaphore);
+	semaphore_init_locked(&crw_semaphore);
 	return 0;
 }
 pure_initcall(crw_init_semaphore);

The crw_semaphore is a real semaphore and the init_MUTEX_LOCKED is indeed confusing. semaphore_init_locked is a more sensible name even if the end result is in both cases just a sema_init(sem, 0). Anyway, fine with me:

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#20 lore raw

RFC PATCH 14/37 scsi: aacraid semaphore cleanup

In reply to Thomas Gleixner

The usage of these "mutex"es is non obvious and probably completions in some places. Make it them semaphores.

---
 drivers/scsi/aacraid/commctrl.c |    2 +-
 drivers/scsi/aacraid/commsup.c  |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/aacraid/commctrl.c +1 -1
Index: linux-2.6-tip/drivers/scsi/aacraid/commctrl.c
===================================================================
@@ -190,7 +190,7 @@ static int open_getadapter_fib(struct aa
 		/*
 		 *	Initialize the mutex used to wait for the next AIF.
 		 */
-		init_MUTEX_LOCKED(&fibctx->wait_sem);
+		semaphore_init_locked(&fibctx->wait_sem);
 		fibctx->wait = 0;
 		/*
 		 *	Initialize the fibs and set the count of fibs on
drivers/scsi/aacraid/commsup.c +1 -1
Index: linux-2.6-tip/drivers/scsi/aacraid/commsup.c
===================================================================
@@ -124,7 +124,7 @@ int aac_fib_setup(struct aac_dev * dev)
 		fibptr->hw_fib_va = hw_fib;
 		fibptr->data = (void *) fibptr->hw_fib_va->data;
 		fibptr->next = fibptr+1;	/* Forward chain the fibs */
-		init_MUTEX_LOCKED(&fibptr->event_wait);
+		semaphore_init_locked(&fibptr->event_wait);
 		spin_lock_init(&fibptr->event_lock);
 		hw_fib->header.XferState = cpu_to_le32(0xffffffff);
 		hw_fib->header.SenderSize = cpu_to_le16(dev->max_fib_size);
maintainer
#21 lore raw

Re: [Patch RFC 14/37] scsi: aacraid semaphore cleanup

cc linux-scsi added

Quoted 4 lines · Thomas Gleixner

plain text document attachment (driver-scsi-aacraid-sema-cleanup.patch)
The usage of these "mutex"es is non obvious and probably completions in some places. Make it them semaphores.

-ENOCONTEXT on this ... I assume this is just a global s/init_MUTEX/semaphore_init/?

I think both are really just mutexes; no need for a counting semaphore. There's no stack declaration issues (the fibs are long lived entities) that would necessitate a completion.

James

Quoted 34 lines
---
 drivers/scsi/aacraid/commctrl.c |    2 +-
 drivers/scsi/aacraid/commsup.c  |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Index: linux-2.6-tip/drivers/scsi/aacraid/commctrl.c
===================================================================

drivers/scsi/aacraid/commctrl.c +1 -1
@@ -190,7 +190,7 @@ static int open_getadapter_fib(struct aa
 		/*
 		 *	Initialize the mutex used to wait for the next AIF.
 		 */
-		init_MUTEX_LOCKED(&fibctx->wait_sem);
+		semaphore_init_locked(&fibctx->wait_sem);
 		fibctx->wait = 0;
 		/*
 		 *	Initialize the fibs and set the count of fibs on

Index: linux-2.6-tip/drivers/scsi/aacraid/commsup.c
===================================================================

drivers/scsi/aacraid/commsup.c +1 -1
@@ -124,7 +124,7 @@ int aac_fib_setup(struct aac_dev * dev)
 		fibptr->hw_fib_va = hw_fib;
 		fibptr->data = (void *) fibptr->hw_fib_va->data;
 		fibptr->next = fibptr+1;	/* Forward chain the fibs */
-		init_MUTEX_LOCKED(&fibptr->event_wait);
+		semaphore_init_locked(&fibptr->event_wait);
 		spin_lock_init(&fibptr->event_lock);
 		hw_fib->header.XferState = cpu_to_le32(0xffffffff);
 		hw_fib->header.SenderSize = cpu_to_le16(dev->max_fib_size);
#22 lore raw

Re: [Patch RFC 14/37] scsi: aacraid semaphore cleanup

Quoted 10 lines · James Bottomley

cc linux-scsi added

Quoted 4 lines · Thomas Gleixner

plain text document attachment (driver-scsi-aacraid-sema-cleanup.patch)
The usage of these "mutex"es is non obvious and probably completions in some places. Make it them semaphores.

-ENOCONTEXT on this ... I assume this is just a global s/init_MUTEX/semaphore_init/?

Well, in cases where the mutex use case is obvious it's a semaphore to mutex conversion. But this one is definitly not.

Quoted 3 lines

I think both are really just mutexes; no need for a counting semaphore. There's no stack declaration issues (the fibs are long lived entities) that would necessitate a completion.

It's not about stack declaration. These semaphores can not be converted to mutexes for following reasons:

1) there is no mutex_init_locked() and there never will be one

2) the sem is taken from context A and released from context B. That violates the mutex semantics where the lock/unlock has to happen in the same thread context.

i.e. wait_sem is taken from

     aac_do_ioctl()
	next_getadapter_fib()

but release from

aac_check_health() or aac_command_thread()

I have no idea how that hell of code works, but wait_sem is definitely not a mutex and neither is event_wait. The beasts might serialize stuff as well, but they are also (ab)used as a completion to wait for whatever.

Thanks,

tglx

#23 lore raw

RFC PATCH 15/37 bluetooth: Convert hdev->req_lock to mutex

In reply to Thomas Gleixner

hdev->req_lock is used as mutex so make it a mutex.

---
 include/net/bluetooth/hci_core.h |    6 +++---
 net/bluetooth/hci_core.c         |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
include/net/bluetooth/hci_core.h +3 -3
Index: linux-2.6-tip/include/net/bluetooth/hci_core.h
===================================================================
@@ -117,7 +117,7 @@ struct hci_dev {
 	struct sk_buff		*sent_cmd;
 	struct sk_buff		*reassembly[3];
 
-	struct semaphore	req_lock;
+	struct mutex		req_lock;
 	wait_queue_head_t	req_wait_q;
 	__u32			req_status;
 	__u32			req_result;
@@ -700,8 +700,8 @@ struct hci_sec_filter {
 #define HCI_REQ_PEND	  1
 #define HCI_REQ_CANCELED  2
 
-#define hci_req_lock(d)		down(&d->req_lock)
-#define hci_req_unlock(d)	up(&d->req_lock)
+#define hci_req_lock(d)		mutex_lock(&d->req_lock)
+#define hci_req_unlock(d)	mutex_unlock(&d->req_lock)
 
 void hci_req_complete(struct hci_dev *hdev, int result);
 
net/bluetooth/hci_core.c +1 -1
Index: linux-2.6-tip/net/bluetooth/hci_core.c
===================================================================
@@ -911,7 +911,7 @@ int hci_register_dev(struct hci_dev *hde
 		hdev->reassembly[i] = NULL;
 
 	init_waitqueue_head(&hdev->req_wait_q);
-	init_MUTEX(&hdev->req_lock);
+	mutex_init(&hdev->req_lock);
 
 	inquiry_cache_init(hdev);
 
maintainer Acked-by on v1 15/37
#24 lore raw

Re: [Patch RFC 15/37] bluetooth: Convert hdev->req_lock to mutex

Hi Thomas,

Quoted 1 line

hdev->req_lock is used as mutex so make it a mutex.

no idea why we never changed this before.

Quoted 2 lines

In case this one is going via someone else's tree. Do you have any preference how this gets merged. I can also take it via my tree.

Regards

Marcel

#25 lore raw

Re: [Patch RFC 15/37] bluetooth: Convert hdev->req_lock to mutex

Quoted 5 lines · Marcel Holtmann

Hi Thomas,

Quoted 1 line

hdev->req_lock is used as mutex so make it a mutex.

no idea why we never changed this before.

:)

Quoted 7 lines
Quoted 2 lines

In case this one is going via someone else's tree. Do you have any preference how this gets merged. I can also take it via my tree.

Please take it. It does not depend on anything else. It's a straight forward conversion to existing infrastructore.

Thanks,

tglx

#26 lore raw

RFC PATCH 16/37 smbfs: Convert server->sem to mutex

In reply to Thomas Gleixner

server->sem is used as mutex so make it a mutex.

---
 fs/smbfs/inode.c          |    2 +-
 include/linux/smb_fs_sb.h |    8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
fs/smbfs/inode.c +1 -1
Index: linux-2.6-tip/fs/smbfs/inode.c
===================================================================
@@ -536,7 +536,7 @@ static int smb_fill_super(struct super_b
 	server->mnt = NULL;
 	server->sock_file = NULL;
 	init_waitqueue_head(&server->conn_wq);
-	init_MUTEX(&server->sem);
+	mutex_init(&server->mutex);
 	INIT_LIST_HEAD(&server->entry);
 	INIT_LIST_HEAD(&server->xmitq);
 	INIT_LIST_HEAD(&server->recvq);
include/linux/smb_fs_sb.h +4 -4
Index: linux-2.6-tip/include/linux/smb_fs_sb.h
===================================================================
@@ -57,7 +57,7 @@ struct smb_sb_info {
 	struct smb_conn_opt opt;
 	wait_queue_head_t conn_wq;
 	int conn_complete;
-	struct semaphore sem;
+	struct mutex mutex;
 
 	unsigned char      header[SMB_HEADER_LEN + 20*2 + 2];
 	u32                header_len;
@@ -79,19 +79,19 @@ struct smb_sb_info {
 static inline int
 smb_lock_server_interruptible(struct smb_sb_info *server)
 {
-	return down_interruptible(&(server->sem));
+	return mutex_lock_interruptible(&server->mutex);
 }
 
 static inline void
 smb_lock_server(struct smb_sb_info *server)
 {
-	down(&(server->sem));
+	mutex_lock(&server->mutex);
 }
 
 static inline void
 smb_unlock_server(struct smb_sb_info *server)
 {
-	up(&(server->sem));
+	mutex_unlock(&server->mutex);
 }
 
 #endif
#27 lore raw

RFC PATCH 17/37 hpfs: Convert sbi->hpfs_creation_de to mutex

In reply to Thomas Gleixner

sbi->hpfs_creation_de is used as mutex so make it a mutex.

---
 fs/hpfs/buffer.c  |    4 ++--
 fs/hpfs/hpfs_fn.h |    2 +-
 fs/hpfs/super.c   |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
fs/hpfs/buffer.c +2 -2
Index: linux-2.6-tip/fs/hpfs/buffer.c
===================================================================
@@ -13,7 +13,7 @@ void hpfs_lock_creation(struct super_blo
 #ifdef DEBUG_LOCKS
 	printk("lock creation\n");
 #endif
-	down(&hpfs_sb(s)->hpfs_creation_de);
+	mutex_lock(&hpfs_sb(s)->hpfs_creation_de);
 }
 
 void hpfs_unlock_creation(struct super_block *s)
@@ -21,7 +21,7 @@ void hpfs_unlock_creation(struct super_b
 #ifdef DEBUG_LOCKS
 	printk("unlock creation\n");
 #endif
-	up(&hpfs_sb(s)->hpfs_creation_de);
+	mutex_unlock(&hpfs_sb(s)->hpfs_creation_de);
 }
 
 /* Map a sector into a buffer and return pointers to it and to the buffer. */
fs/hpfs/hpfs_fn.h +1 -1
Index: linux-2.6-tip/fs/hpfs/hpfs_fn.h
===================================================================
@@ -87,7 +87,7 @@ struct hpfs_sb_info {
 	unsigned *sb_bmp_dir;		/* main bitmap directory */
 	unsigned sb_c_bitmap;		/* current bitmap */
 	unsigned sb_max_fwd_alloc;	/* max forwad allocation */
-	struct semaphore hpfs_creation_de; /* when creating dirents, nobody else
+	struct mutex hpfs_creation_de;	/* when creating dirents, nobody else
 					   can alloc blocks */
 	/*unsigned sb_mounting : 1;*/
 	int sb_timeshift;
fs/hpfs/super.c +1 -1
Index: linux-2.6-tip/fs/hpfs/super.c
===================================================================
@@ -487,7 +487,7 @@ static int hpfs_fill_super(struct super_
 	sbi->sb_bmp_dir = NULL;
 	sbi->sb_cp_table = NULL;
 
-	init_MUTEX(&sbi->hpfs_creation_de);
+	mutex_init(&sbi->hpfs_creation_de);
 
 	uid = current_uid();
 	gid = current_gid();
#28 lore raw

RFC PATCH 18/37 hpfsplus: Convert tree_lock to mutex

In reply to Thomas Gleixner

tree_lock is used as mutex so make it a mutex.

---
 fs/hfsplus/bfind.c      |    4 ++--
 fs/hfsplus/btree.c      |    2 +-
 fs/hfsplus/hfsplus_fs.h |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
fs/hfsplus/bfind.c +2 -2
Index: linux-2.6-tip/fs/hfsplus/bfind.c
===================================================================
@@ -23,7 +23,7 @@ int hfs_find_init(struct hfs_btree *tree
 	fd->search_key = ptr;
 	fd->key = ptr + tree->max_key_len + 2;
 	dprint(DBG_BNODE_REFS, "find_init: %d (%p)\n", tree->cnid, __builtin_return_address(0));
-	down(&tree->tree_lock);
+	mutex_lock(&tree->tree_lock);
 	return 0;
 }
 
@@ -32,7 +32,7 @@ void hfs_find_exit(struct hfs_find_data 
 	hfs_bnode_put(fd->bnode);
 	kfree(fd->search_key);
 	dprint(DBG_BNODE_REFS, "find_exit: %d (%p)\n", fd->tree->cnid, __builtin_return_address(0));
-	up(&fd->tree->tree_lock);
+	mutex_unlock(&fd->tree->tree_lock);
 	fd->tree = NULL;
 }
 
fs/hfsplus/btree.c +1 -1
Index: linux-2.6-tip/fs/hfsplus/btree.c
===================================================================
@@ -30,7 +30,7 @@ struct hfs_btree *hfs_btree_open(struct 
 	if (!tree)
 		return NULL;
 
-	init_MUTEX(&tree->tree_lock);
+	mutex_init(&tree->tree_lock);
 	spin_lock_init(&tree->hash_lock);
 	tree->sb = sb;
 	tree->cnid = id;
fs/hfsplus/hfsplus_fs.h +1 -1
Index: linux-2.6-tip/fs/hfsplus/hfsplus_fs.h
===================================================================
@@ -62,7 +62,7 @@ struct hfs_btree {
 	unsigned int depth;
 
 	//unsigned int map1_size, map_size;
-	struct semaphore tree_lock;
+	struct mutex tree_lock;
 
 	unsigned int pages_per_bnode;
 	spinlock_t hash_lock;
#29 lore raw

RFC PATCH 19/37 hfs: Convert tree_lock to mutex

In reply to Thomas Gleixner

tree_lock is used as mutex so make it a mutex.

---
 fs/hfs/bfind.c |    4 ++--
 fs/hfs/btree.c |    2 +-
 fs/hfs/btree.h |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
fs/hfs/bfind.c +2 -2
Index: linux-2.6-tip/fs/hfs/bfind.c
===================================================================
@@ -23,7 +23,7 @@ int hfs_find_init(struct hfs_btree *tree
 	fd->search_key = ptr;
 	fd->key = ptr + tree->max_key_len + 2;
 	dprint(DBG_BNODE_REFS, "find_init: %d (%p)\n", tree->cnid, __builtin_return_address(0));
-	down(&tree->tree_lock);
+	mutex_lock(&tree->tree_lock);
 	return 0;
 }
 
@@ -32,7 +32,7 @@ void hfs_find_exit(struct hfs_find_data 
 	hfs_bnode_put(fd->bnode);
 	kfree(fd->search_key);
 	dprint(DBG_BNODE_REFS, "find_exit: %d (%p)\n", fd->tree->cnid, __builtin_return_address(0));
-	up(&fd->tree->tree_lock);
+	mutex_unlock(&fd->tree->tree_lock);
 	fd->tree = NULL;
 }
 
fs/hfs/btree.c +1 -1
Index: linux-2.6-tip/fs/hfs/btree.c
===================================================================
@@ -26,7 +26,7 @@ struct hfs_btree *hfs_btree_open(struct 
 	if (!tree)
 		return NULL;
 
-	init_MUTEX(&tree->tree_lock);
+	mutex_init(&tree->tree_lock);
 	spin_lock_init(&tree->hash_lock);
 	/* Set the correct compare function */
 	tree->sb = sb;
fs/hfs/btree.h +1 -1
Index: linux-2.6-tip/fs/hfs/btree.h
===================================================================
@@ -33,7 +33,7 @@ struct hfs_btree {
 	unsigned int depth;
 
 	//unsigned int map1_size, map_size;
-	struct semaphore tree_lock;
+	struct mutex tree_lock;
 
 	unsigned int pages_per_bnode;
 	spinlock_t hash_lock;
#30 lore raw

RFC PATCH 20/37 cifs: convert semaphore to mutex

In reply to Thomas Gleixner

pSesInfo->sesSem is used as mutex so make it a mutex.

---
 fs/cifs/cifsglob.h |    2 +-
 fs/cifs/cifssmb.c  |   18 +++++++++---------
 fs/cifs/connect.c  |    8 ++++----
 fs/cifs/misc.c     |    2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)
fs/cifs/cifsglob.h +1 -1
Index: linux-2.6-tip/fs/cifs/cifsglob.h
===================================================================
@@ -203,7 +203,7 @@ struct cifsUidInfo {
 struct cifsSesInfo {
 	struct list_head smb_ses_list;
 	struct list_head tcon_list;
-	struct semaphore sesSem;
+	struct mutex sesSem;
 #if 0
 	struct cifsUidInfo *uidInfo;	/* pointer to user info */
 #endif
fs/cifs/cifssmb.c +9 -9
Index: linux-2.6-tip/fs/cifs/cifssmb.c
===================================================================
@@ -154,7 +154,7 @@ small_smb_init(int smb_command, int wct,
 			nls_codepage = load_nls_default();
 		/* need to prevent multiple threads trying to
 		simultaneously reconnect the same SMB session */
-			down(&tcon->ses->sesSem);
+			mutex_lock(&tcon->ses->sesSem);
 			if (tcon->ses->need_reconnect)
 				rc = cifs_setup_session(0, tcon->ses,
 							nls_codepage);
@@ -162,7 +162,7 @@ small_smb_init(int smb_command, int wct,
 				mark_open_files_invalid(tcon);
 				rc = CIFSTCon(0, tcon->ses, tcon->treeName,
 					      tcon, nls_codepage);
-				up(&tcon->ses->sesSem);
+				mutex_unlock(&tcon->ses->sesSem);
 				/* BB FIXME add code to check if wsize needs
 				   update due to negotiated smb buffer size
 				   shrinking */
@@ -196,7 +196,7 @@ small_smb_init(int smb_command, int wct,
 					}
 				}
 			} else {
-				up(&tcon->ses->sesSem);
+				mutex_unlock(&tcon->ses->sesSem);
 			}
 			unload_nls(nls_codepage);
 
@@ -301,7 +301,7 @@ smb_init(int smb_command, int wct, struc
 			nls_codepage = load_nls_default();
 		/* need to prevent multiple threads trying to
 		simultaneously reconnect the same SMB session */
-			down(&tcon->ses->sesSem);
+			mutex_lock(&tcon->ses->sesSem);
 			if (tcon->ses->need_reconnect)
 				rc = cifs_setup_session(0, tcon->ses,
 							nls_codepage);
@@ -309,7 +309,7 @@ smb_init(int smb_command, int wct, struc
 				mark_open_files_invalid(tcon);
 				rc = CIFSTCon(0, tcon->ses, tcon->treeName,
 					      tcon, nls_codepage);
-				up(&tcon->ses->sesSem);
+				mutex_unlock(&tcon->ses->sesSem);
 				/* BB FIXME add code to check if wsize needs
 				update due to negotiated smb buffer size
 				shrinking */
@@ -343,7 +343,7 @@ smb_init(int smb_command, int wct, struc
 					}
 				}
 			} else {
-				up(&tcon->ses->sesSem);
+				mutex_unlock(&tcon->ses->sesSem);
 			}
 			unload_nls(nls_codepage);
 
@@ -765,13 +765,13 @@ CIFSSMBLogoff(const int xid, struct cifs
 	if (!ses || !ses->server)
 		return -EIO;
 
-	down(&ses->sesSem);
+	mutex_lock(&ses->sesSem);
 	if (ses->need_reconnect)
 		goto session_already_dead; /* no need to send SMBlogoff if uid
 					      already closed due to reconnect */
 	rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB);
 	if (rc) {
-		up(&ses->sesSem);
+		mutex_unlock(&ses->sesSem);
 		return rc;
 	}
 
@@ -786,7 +786,7 @@ CIFSSMBLogoff(const int xid, struct cifs
 	pSMB->AndXCommand = 0xFF;
 	rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0);
 session_already_dead:
-	up(&ses->sesSem);
+	mutex_unlock(&ses->sesSem);
 
 	/* if session dead then we do not need to do ulogoff,
 		since server closed smb session, no sense reporting
fs/cifs/connect.c +4 -4
Index: linux-2.6-tip/fs/cifs/connect.c
===================================================================
@@ -2331,13 +2331,13 @@ try_mount_again:
 		 */
 		cifs_put_tcp_session(srvTcp);
 
-		down(&pSesInfo->sesSem);
+		mutex_lock(&pSesInfo->sesSem);
 		if (pSesInfo->need_reconnect) {
 			cFYI(1, ("Session needs reconnect"));
 			rc = cifs_setup_session(xid, pSesInfo,
 						cifs_sb->local_nls);
 		}
-		up(&pSesInfo->sesSem);
+		mutex_unlock(&pSesInfo->sesSem);
 	} else if (!rc) {
 		cFYI(1, ("Existing smb sess not found"));
 		pSesInfo = sesInfoAlloc();
@@ -2380,12 +2380,12 @@ try_mount_again:
 		}
 		pSesInfo->linux_uid = volume_info->linux_uid;
 		pSesInfo->overrideSecFlg = volume_info->secFlg;
-		down(&pSesInfo->sesSem);
+		mutex_lock(&pSesInfo->sesSem);
 
 		/* BB FIXME need to pass vol->secFlgs BB */
 		rc = cifs_setup_session(xid, pSesInfo,
 					cifs_sb->local_nls);
-		up(&pSesInfo->sesSem);
+		mutex_unlock(&pSesInfo->sesSem);
 	}
 
 	/* search for existing tcon to this server share */
fs/cifs/misc.c +1 -1
Index: linux-2.6-tip/fs/cifs/misc.c
===================================================================
@@ -80,7 +80,7 @@ sesInfoAlloc(void)
 		++ret_buf->ses_count;
 		INIT_LIST_HEAD(&ret_buf->smb_ses_list);
 		INIT_LIST_HEAD(&ret_buf->tcon_list);
-		init_MUTEX(&ret_buf->sesSem);
+		mutex_init(&ret_buf->sesSem);
 	}
 	return ret_buf;
 }
#32 lore raw

Re: [Patch RFC 20/37] cifs: convert semaphore to mutex

In reply to Thomas Gleixner

fs/cifs/cifsglob.h struct cifsUidInfo { · line 206

Quoted 2 lines · Thomas Gleixner
fs/cifs/cifsglob.h +1 -1
-	struct semaphore sesSem;
+	struct mutex sesSem;

If we touch every user of this anyway any chance we could give it a sane name, e.g. session_mutex?

#33 lore raw

Re: [Patch RFC 20/37] cifs: convert semaphore to mutex

Christoph Hellwig <[email protected]> wrote on 07/30/2009 04:09:46 PM:

Quoted 7 lines · Thomas Gleixner

fs/cifs/cifsglob.h struct cifsUidInfo { · line 206

Quoted 2 lines
fs/cifs/cifsglob.h +1 -1
-   struct semaphore sesSem;
+   struct mutex sesSem;

If we touch every user of this anyway any chance we could give it a sane name, e.g. session_mutex?

Sounds like a good idea. Might as well make the name change - since it is easier to read.

Steve French
Senior Software Engineer
Linux Technology Center - IBM Austin
phone: 512-838-2294
email: sfrench at-sign us dot ibm dot com

#34 lore raw

RFC PATCH 21/37 affs: use semaphore_init instead of init_MUTEX

In reply to Thomas Gleixner

The usage of these "mutex" is non obvious and probably a completion in some places. Make it them semaphores.

---
 fs/affs/super.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/affs/super.c +2 -2
Index: linux-2.6-tip/fs/affs/super.c
===================================================================
@@ -113,8 +113,8 @@ static void init_once(void *foo)
 {
 	struct affs_inode_info *ei = (struct affs_inode_info *) foo;
 
-	init_MUTEX(&ei->i_link_lock);
-	init_MUTEX(&ei->i_ext_lock);
+	semaphore_init(&ei->i_link_lock);
+	semaphore_init(&ei->i_ext_lock);
 	inode_init_once(&ei->vfs_inode);
 }
 
#35 lore raw

Re: [Patch RFC 21/37] affs: use semaphore_init instead of init_MUTEX

Quoted 2 lines · Thomas Gleixner

The usage of these "mutex" is non obvious and probably a completion in some places. Make it them semaphores.

Except for the obsfucation by the wrappers it's clearly obvious that these are plain binary mutexes, so they should be converted. Note that this will trigger some lockdep warnings as we sometimes hold the same lock for parent and child. Maybe we can use this as a check if any users of affs are left :)

#36 lore raw

RFC PATCH 22/37 usb: ftdi-elan: Convert "mutex" to semaphore

In reply to Thomas Gleixner

The "mutex" ftdi->sw_lock is used as a lock and a completion. Convert it to a real semaphore which allows both.

Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/usb/misc/ftdi-elan.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/ftdi-elan.c +1 -1
Index: linux-2.6-tip/drivers/usb/misc/ftdi-elan.c
===================================================================
@@ -2766,7 +2766,7 @@ static int ftdi_elan_probe(struct usb_in
         ftdi->sequence_num = ++ftdi_instances;
         mutex_unlock(&ftdi_module_lock);
         ftdi_elan_init_kref(ftdi);
-        init_MUTEX(&ftdi->sw_lock);
+	semaphore_init(&ftdi->sw_lock);
         ftdi->udev = usb_get_dev(interface_to_usbdev(interface));
         ftdi->interface = interface;
         mutex_init(&ftdi->u132_lock);
#37 lore raw

RFC PATCH 23/37 usb: gadgetfs: Convert semaphore to mutex

In reply to Thomas Gleixner

The semaphore is used as mutex so make it a mutex.

Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/usb/gadget/inode.c |   39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
drivers/usb/gadget/inode.c +21 -18
Index: 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);
#38 lore raw

Re: [Patch RFC 23/37] usb: gadgetfs: Convert semaphore to mutex

drivers/usb/gadget/inode.c get_ready_ep (unsigned f_flags, struct e · line 300

Quoted 2 lines · Thomas Gleixner
drivers/usb/gadget/inode.c +1 -1
-               if (down_trylock (&epdata->lock) != 0)
+               if (mutex_trylock(&epdata->lock) != 0)

You forget the mutex_trylock has an inverted return value..

Daniel

#39 lore raw

RFC PATCH 24/37 xfs: semaphore cleanup

In reply to Thomas Gleixner

bp->b_sema claims to be a mutex, but it is a semaphore with non obvious semantics. Make it a real semaphore.

Cc Christoph Hellwig <[email protected]>
---
 fs/xfs/linux-2.6/xfs_buf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/linux-2.6/xfs_buf.c +1 -1
Index: linux-2.6-tip/fs/xfs/linux-2.6/xfs_buf.c
===================================================================
@@ -263,7 +263,7 @@ _xfs_buf_initialize(
 	init_completion(&bp->b_iowait);
 	INIT_LIST_HEAD(&bp->b_list);
 	INIT_LIST_HEAD(&bp->b_hash_list);
-	init_MUTEX_LOCKED(&bp->b_sema); /* held, no waiters */
+	semaphore_init_locked(&bp->b_sema); /* held, no waiters */
 	XB_SET_OWNER(bp);
 	bp->b_target = target;
 	bp->b_file_offset = range_base;
#40 lore raw

Re: [Patch RFC 24/37] xfs: semaphore cleanup

Quoted 2 lines · Thomas Gleixner

bp->b_sema claims to be a mutex, but it is a semaphore with non obvious semantics. Make it a real semaphore.

It is a binary mutex in the classical CS sense, just not unlocked by the same thread as expected by the Linux mutexes..

#41 lore raw

RFC PATCH 25/37 net: wan/cosa.c: Convert "mutex" to semaphore

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completions in some places. Make it a semaphore.

---
 drivers/net/wan/cosa.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wan/cosa.c +1 -1
Index: linux-2.6-tip/drivers/net/wan/cosa.c
===================================================================
@@ -574,7 +574,7 @@ static int cosa_probe(int base, int irq,
 
 		/* Initialize the chardev data structures */
 		mutex_init(&chan->rlock);
-		init_MUTEX(&chan->wsem);
+		semaphore_init(&chan->wsem);
 
 		/* Register the network interface */
 		if (!(chan->netdev = alloc_hdlcdev(chan))) {
#42 lore raw

RFC PATCH 26/37 irda: semaphore cleanup

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completion in some places. Make it a semaphore.

---
 drivers/net/irda/sir_dev.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/irda/sir_dev.c +1 -1
Index: linux-2.6-tip/drivers/net/irda/sir_dev.c
===================================================================
@@ -908,7 +908,7 @@ struct sir_dev * sirdev_get_instance(con
 	dev->tx_skb = NULL;
 
 	spin_lock_init(&dev->tx_lock);
-	init_MUTEX(&dev->fsm.sem);
+	semaphore_init(&dev->fsm.sem);
 
 	dev->drv = drv;
 	dev->netdev = ndev;
#43 lore raw

RFC PATCH 27/37 mmc: Convert "mutex" to semaphore

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completions in some places. Make it a semaphore.

---
 drivers/mmc/card/queue.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/card/queue.c +1 -1
Index: linux-2.6-tip/drivers/mmc/card/queue.c
===================================================================
@@ -194,7 +194,7 @@ int mmc_init_queue(struct mmc_queue *mq,
 		sg_init_table(mq->sg, host->max_phys_segs);
 	}
 
-	init_MUTEX(&mq->thread_sem);
+	semaphore_init(&mq->thread_sem);
 
 	mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd");
 	if (IS_ERR(mq->thread)) {
#44 lore raw

RFC PATCH 28/37 dvb: Convert "mutex" to semaphore

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and probably a completions in some places. Make it a semaphore.

Cc Mauro Carvalho Chehab <[email protected]>
---
 drivers/media/dvb/dvb-core/dvb_frontend.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/dvb/dvb-core/dvb_frontend.c +2 -2
Index: linux-2.6-tip/drivers/media/dvb/dvb-core/dvb_frontend.c
===================================================================
@@ -678,7 +678,7 @@ static void dvb_frontend_stop(struct dvb
 
 	kthread_stop(fepriv->thread);
 
-	init_MUTEX (&fepriv->sem);
+	semaphore_init(&fepriv->sem);
 	fepriv->state = FESTATE_IDLE;
 
 	/* paranoia check in case a signal arrived */
@@ -1909,7 +1909,7 @@ int dvb_register_frontend(struct dvb_ada
 	}
 	fepriv = fe->frontend_priv;
 
-	init_MUTEX (&fepriv->sem);
+	semaphore_init(&fepriv->sem);
 	init_waitqueue_head (&fepriv->wait_queue);
 	init_waitqueue_head (&fepriv->events.wait_queue);
 	mutex_init(&fepriv->events.mtx);
#45 lore raw

RFC PATCH 29/37 infiniband: Make user_mad semaphore a real one

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious. Make it a semaphore.

---
 drivers/infiniband/core/user_mad.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/user_mad.c +1 -1
Index: linux-2.6-tip/drivers/infiniband/core/user_mad.c
===================================================================
@@ -1003,7 +1003,7 @@ static int ib_umad_init_port(struct ib_d
 
 	port->ib_dev   = device;
 	port->port_num = port_num;
-	init_MUTEX(&port->sm_sem);
+	semaphore_init(&port->sm_sem);
 	mutex_init(&port->file_mutex);
 	INIT_LIST_HEAD(&port->file_list);
 
#46 lore raw

Re: [Patch RFC 29/37] infiniband: Make user_mad semaphore a real one

drivers/infiniband/core/user_mad.c static int ib_umad_init_port(struct ib_d · line 1006

Quoted 3 lines
drivers/infiniband/core/user_mad.c +1 -1
-	init_MUTEX(&port->sm_sem);
+	semaphore_init(&port->sm_sem);

OK by me -- although I'm not clear what's wrong with using existing sema_init().

#47 lore raw

Re: [Patch RFC 29/37] infiniband: Make user_mad semaphore a real one

Quoted 6 lines · Roland Dreier

drivers/infiniband/core/user_mad.c static int ib_umad_init_port(struct ib_d · line 1006

Quoted 3 lines
drivers/infiniband/core/user_mad.c +1 -1
-	init_MUTEX(&port->sm_sem);
+	semaphore_init(&port->sm_sem);

OK by me -- although I'm not clear what's wrong with using existing sema_init().

I'm happy do redo the series with sema_init(sem, x) :)

tglx

#48 lore raw

RFC PATCH 30/37 drivers/base: Convert dev->sem to mutex

In reply to Thomas Gleixner

The semaphore is used as mutex so make it a mutex. Clean up all users outside of drivers/base as well.

---
 drivers/base/bus.c             |   20 ++++++++++----------
 drivers/base/core.c            |    3 +--
 drivers/base/dd.c              |   38 +++++++++++++++++++-------------------
 drivers/base/power/main.c      |   20 ++++++++++----------
 drivers/firewire/core-device.c |    4 ++--
 drivers/ieee1394/nodemgr.c     |    4 ++--
 drivers/net/mlx4/mlx4.h        |    1 +
 drivers/pci/bus.c              |    4 ++--
 drivers/pci/pci.c              |    4 ++--
 drivers/pcmcia/ds.c            |    8 ++++----
 drivers/usb/core/driver.c      |    4 ++--
 drivers/uwb/umc-bus.c          |    4 ++--
 drivers/uwb/uwb-internal.h     |    4 ++--
 include/linux/device.h         |    5 ++---
 include/linux/usb.h            |    6 +++---
 15 files changed, 64 insertions(+), 65 deletions(-)
drivers/base/bus.c +10 -10
Index: linux-2.6-tip/drivers/base/bus.c
===================================================================
@@ -173,10 +173,10 @@ static ssize_t driver_unbind(struct devi
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == drv) {
 		if (dev->parent)	/* Needed for USB */
-			down(&dev->parent->sem);
+			mutex_lock(&dev->parent->mutex);
 		device_release_driver(dev);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 		err = count;
 	}
 	put_device(dev);
@@ -200,12 +200,12 @@ static ssize_t driver_bind(struct device
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == NULL && driver_match_device(drv, dev)) {
 		if (dev->parent)	/* Needed for USB */
-			down(&dev->parent->sem);
-		down(&dev->sem);
+			mutex_lock(&dev->parent->mutex);
+		mutex_lock(&dev->mutex);
 		err = driver_probe_device(drv, dev);
-		up(&dev->sem);
+		mutex_unlock(&dev->mutex);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 
 		if (err > 0) {
 			/* success */
@@ -742,10 +742,10 @@ static int __must_check bus_rescan_devic
 
 	if (!dev->driver) {
 		if (dev->parent)	/* Needed for USB */
-			down(&dev->parent->sem);
+			mutex_lock(&dev->parent->mutex);
 		ret = device_attach(dev);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 	}
 	return ret < 0 ? ret : 0;
 }
@@ -777,10 +777,10 @@ int device_reprobe(struct device *dev)
 {
 	if (dev->driver) {
 		if (dev->parent)        /* Needed for USB */
-			down(&dev->parent->sem);
+			mutex_lock(&dev->parent->mutex);
 		device_release_driver(dev);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 	}
 	return bus_rescan_devices_helper(dev, NULL);
 }
drivers/base/core.c +1 -2
Index: linux-2.6-tip/drivers/base/core.c
===================================================================
@@ -20,7 +20,6 @@
 #include <linux/notifier.h>
 #include <linux/genhd.h>
 #include <linux/kallsyms.h>
-#include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/async.h>
 
@@ -550,7 +549,7 @@ void device_initialize(struct device *de
 	dev->kobj.kset = devices_kset;
 	kobject_init(&dev->kobj, &device_ktype);
 	INIT_LIST_HEAD(&dev->dma_pools);
-	init_MUTEX(&dev->sem);
+	mutex_init(&dev->mutex);
 	spin_lock_init(&dev->devres_lock);
 	INIT_LIST_HEAD(&dev->devres_head);
 	device_init_wakeup(dev, 0);
drivers/base/dd.c +19 -19
Index: linux-2.6-tip/drivers/base/dd.c
===================================================================
@@ -84,7 +84,7 @@ static void driver_sysfs_remove(struct d
  * for before calling this. (It is ok to call with no other effort
  * from a driver's probe() method.)
  *
- * This function must be called with @dev->sem held.
+ * This function must be called with @dev->mutex held.
  */
 int device_bind_driver(struct device *dev)
 {
@@ -189,8 +189,8 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe)
  * This function returns -ENODEV if the device is not registered,
  * 1 if the device is bound sucessfully and 0 otherwise.
  *
- * This function must be called with @dev->sem held.  When called for a
- * USB interface, @dev->parent->sem must be held as well.
+ * This function must be called with @dev->mutex held.  When called for a
+ * USB interface, @dev->parent->mutex must be held as well.
  */
 int driver_probe_device(struct device_driver *drv, struct device *dev)
 {
@@ -229,13 +229,13 @@ static int __device_attach(struct device
  * 0 if no matching driver was found;
  * -ENODEV if the device is not registered.
  *
- * When called for a USB interface, @dev->parent->sem must be held.
+ * When called for a USB interface, @dev->parent->mutex must be held.
  */
 int device_attach(struct device *dev)
 {
 	int ret = 0;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 	if (dev->driver) {
 		ret = device_bind_driver(dev);
 		if (ret == 0)
@@ -247,7 +247,7 @@ int device_attach(struct device *dev)
 	} else {
 		ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
 	}
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(device_attach);
@@ -270,13 +270,13 @@ static int __driver_attach(struct device
 		return 0;
 
 	if (dev->parent)	/* Needed for USB */
-		down(&dev->parent->sem);
-	down(&dev->sem);
+		mutex_lock(&dev->parent->mutex);
+	mutex_lock(&dev->mutex);
 	if (!dev->driver)
 		driver_probe_device(drv, dev);
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 	if (dev->parent)
-		up(&dev->parent->sem);
+		mutex_unlock(&dev->parent->mutex);
 
 	return 0;
 }
@@ -297,8 +297,8 @@ int driver_attach(struct device_driver *
 EXPORT_SYMBOL_GPL(driver_attach);
 
 /*
- * __device_release_driver() must be called with @dev->sem held.
- * When called for a USB interface, @dev->parent->sem must be held as well.
+ * __device_release_driver() must be called with @dev->mutex held.
+ * When called for a USB interface, @dev->parent->mutex must be held as well.
  */
 static void __device_release_driver(struct device *dev)
 {
@@ -332,7 +332,7 @@ static void __device_release_driver(stru
  * @dev: device.
  *
  * Manually detach device from driver.
- * When called for a USB interface, @dev->parent->sem must be held.
+ * When called for a USB interface, @dev->parent->mutex must be held.
  */
 void device_release_driver(struct device *dev)
 {
@@ -341,9 +341,9 @@ void device_release_driver(struct device
 	 * within their ->remove callback for the same device, they
 	 * will deadlock right here.
 	 */
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 	__device_release_driver(dev);
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 }
 EXPORT_SYMBOL_GPL(device_release_driver);
 
@@ -370,13 +370,13 @@ void driver_detach(struct device_driver 
 		spin_unlock(&drv->p->klist_devices.k_lock);
 
 		if (dev->parent)	/* Needed for USB */
-			down(&dev->parent->sem);
-		down(&dev->sem);
+			mutex_lock(&dev->parent->mutex);
+		mutex_lock(&dev->mutex);
 		if (dev->driver == drv)
 			__device_release_driver(dev);
-		up(&dev->sem);
+		mutex_unlock(&dev->mutex);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 		put_device(dev);
 	}
 }
drivers/base/power/main.c +10 -10
Index: linux-2.6-tip/drivers/base/power/main.c
===================================================================
@@ -33,8 +33,8 @@
  * because children are guaranteed to be discovered after parents, and
  * are inserted at the back of the list on discovery.
  *
- * Since device_pm_add() may be called with a device semaphore held,
- * we must never try to acquire a device semaphore while holding
+ * Since device_pm_add() may be called with a device mutex held,
+ * we must never try to acquire a device mutex while holding
  * dpm_list_mutex.
  */
 
@@ -381,7 +381,7 @@ static int device_resume(struct device *
 	TRACE_DEVICE(dev);
 	TRACE_RESUME(0);
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 
 	if (dev->bus) {
 		if (dev->bus->pm) {
@@ -414,7 +414,7 @@ static int device_resume(struct device *
 		}
 	}
  End:
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 
 	TRACE_RESUME(error);
 	return error;
@@ -468,7 +468,7 @@ static void dpm_resume(pm_message_t stat
  */
 static void device_complete(struct device *dev, pm_message_t state)
 {
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 
 	if (dev->class && dev->class->pm && dev->class->pm->complete) {
 		pm_dev_dbg(dev, state, "completing class ");
@@ -485,7 +485,7 @@ static void device_complete(struct devic
 		dev->bus->pm->complete(dev);
 	}
 
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 }
 
 /**
@@ -619,7 +619,7 @@ static int device_suspend(struct device 
 {
 	int error = 0;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 
 	if (dev->class) {
 		if (dev->class->pm) {
@@ -654,7 +654,7 @@ static int device_suspend(struct device 
 		}
 	}
  End:
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 
 	return error;
 }
@@ -705,7 +705,7 @@ static int device_prepare(struct device 
 {
 	int error = 0;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 
 	if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) {
 		pm_dev_dbg(dev, state, "preparing ");
@@ -729,7 +729,7 @@ static int device_prepare(struct device 
 		suspend_report_result(dev->class->pm->prepare, error);
 	}
  End:
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 
 	return error;
 }
drivers/firewire/core-device.c +2 -2
Index: linux-2.6-tip/drivers/firewire/core-device.c
===================================================================
@@ -762,9 +762,9 @@ static int update_unit(struct device *de
 	struct fw_driver *driver = (struct fw_driver *)dev->driver;
 
 	if (is_fw_unit(dev) && driver != NULL && driver->update != NULL) {
-		down(&dev->sem);
+		mutex_lock(&dev->mutex);
 		driver->update(unit);
-		up(&dev->sem);
+		mutex_unlock(&dev->mutex);
 	}
 
 	return 0;
drivers/ieee1394/nodemgr.c +2 -2
Index: linux-2.6-tip/drivers/ieee1394/nodemgr.c
===================================================================
@@ -1397,9 +1397,9 @@ static int update_pdrv(struct device *de
 			pdrv = container_of(drv, struct hpsb_protocol_driver,
 					    driver);
 			if (pdrv->update) {
-				down(&ud->device.sem);
+				mutex_lock(&ud->device.mutex);
 				error = pdrv->update(ud);
-				up(&ud->device.sem);
+				mutex_unlock(&ud->device.mutex);
 			}
 			if (error)
 				device_release_driver(&ud->device);
drivers/net/mlx4/mlx4.h +1 -0
Index: linux-2.6-tip/drivers/net/mlx4/mlx4.h
===================================================================
@@ -40,6 +40,7 @@
 #include <linux/mutex.h>
 #include <linux/radix-tree.h>
 #include <linux/timer.h>
+#include <linux/semaphore.h>
 #include <linux/workqueue.h>
 
 #include <linux/mlx4/device.h>
drivers/pci/bus.c +2 -2
Index: linux-2.6-tip/drivers/pci/bus.c
===================================================================
@@ -240,9 +240,9 @@ void pci_walk_bus(struct pci_bus *top, i
 			next = dev->bus_list.next;
 
 		/* Run device routines with the device locked */
-		down(&dev->dev.sem);
+		mutex_lock(&dev->dev.mutex);
 		retval = cb(dev, userdata);
-		up(&dev->dev.sem);
+		mutex_unlock(&dev->dev.mutex);
 		if (retval)
 			break;
 	}
drivers/pci/pci.c +2 -2
Index: linux-2.6-tip/drivers/pci/pci.c
===================================================================
@@ -2211,7 +2211,7 @@ static int pci_dev_reset(struct pci_dev 
 	if (!probe) {
 		pci_block_user_cfg_access(dev);
 		/* block PM suspend, driver probe, etc. */
-		down(&dev->dev.sem);
+		mutex_lock(&dev->dev.mutex);
 	}
 
 	rc = pcie_flr(dev, probe);
@@ -2229,7 +2229,7 @@ static int pci_dev_reset(struct pci_dev 
 	rc = pci_parent_bus_reset(dev, probe);
 done:
 	if (!probe) {
-		up(&dev->dev.sem);
+		mutex_unlock(&dev->dev.mutex);
 		pci_unblock_user_cfg_access(dev);
 	}
 
drivers/pcmcia/ds.c +4 -4
Index: linux-2.6-tip/drivers/pcmcia/ds.c
===================================================================
@@ -1082,9 +1082,9 @@ static int runtime_suspend(struct device
 {
 	int rc;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 	rc = pcmcia_dev_suspend(dev, PMSG_SUSPEND);
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 	return rc;
 }
 
@@ -1092,9 +1092,9 @@ static void runtime_resume(struct device
 {
 	int rc;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 	rc = pcmcia_dev_resume(dev);
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 }
 
 /************************ per-device sysfs output ***************************/
drivers/usb/core/driver.c +2 -2
Index: linux-2.6-tip/drivers/usb/core/driver.c
===================================================================
@@ -391,10 +391,10 @@ void usb_driver_release_interface(struct
 	if (device_is_registered(dev)) {
 		device_release_driver(dev);
 	} else {
-		down(&dev->sem);
+		mutex_lock(&dev->mutex);
 		usb_unbind_interface(dev);
 		dev->driver = NULL;
-		up(&dev->sem);
+		mutex_unlock(&dev->mutex);
 	}
 }
 EXPORT_SYMBOL_GPL(usb_driver_release_interface);
drivers/uwb/umc-bus.c +2 -2
Index: linux-2.6-tip/drivers/uwb/umc-bus.c
===================================================================
@@ -62,12 +62,12 @@ int umc_controller_reset(struct umc_dev 
 	struct device *parent = umc->dev.parent;
 	int ret = 0;
 
-	if(down_trylock(&parent->sem))
+	if (mutex_trylock(&parent->mutex))
 		return -EAGAIN;
 	ret = device_for_each_child(parent, parent, umc_bus_pre_reset_helper);
 	if (ret >= 0)
 		device_for_each_child(parent, parent, umc_bus_post_reset_helper);
-	up(&parent->sem);
+	mutex_unlock(&parent->mutex);
 
 	return ret;
 }
drivers/uwb/uwb-internal.h +2 -2
Index: linux-2.6-tip/drivers/uwb/uwb-internal.h
===================================================================
@@ -366,12 +366,12 @@ struct dentry *uwb_dbg_create_pal_dir(st
 
 static inline void uwb_dev_lock(struct uwb_dev *uwb_dev)
 {
-	down(&uwb_dev->dev.sem);
+	mutex_lock(&uwb_dev->dev.mutex);
 }
 
 static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev)
 {
-	up(&uwb_dev->dev.sem);
+	mutex_unlock(&uwb_dev->dev.mutex);
 }
 
 #endif /* #ifndef __UWB_INTERNAL_H__ */
include/linux/device.h +2 -3
Index: linux-2.6-tip/include/linux/device.h
===================================================================
@@ -21,7 +21,6 @@
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pm.h>
-#include <linux/semaphore.h>
 #include <asm/atomic.h>
 #include <asm/device.h>
 
@@ -105,7 +104,7 @@ extern int bus_unregister_notifier(struc
 
 /* All 4 notifers below get called with the target struct device *
  * as an argument. Note that those functions are likely to be called
- * with the device semaphore held in the core, so be careful.
+ * with the device mutex held in the core, so be careful.
  */
 #define BUS_NOTIFY_ADD_DEVICE		0x00000001 /* device added */
 #define BUS_NOTIFY_DEL_DEVICE		0x00000002 /* device removed */
@@ -373,7 +372,7 @@ struct device {
 	const char		*init_name; /* initial name of the device */
 	struct device_type	*type;
 
-	struct semaphore	sem;	/* semaphore to synchronize calls to
+	struct mutex		mutex;	/* mutex to synchronize calls to
 					 * its driver.
 					 */
 
include/linux/usb.h +3 -3
Index: linux-2.6-tip/include/linux/usb.h
===================================================================
@@ -529,9 +529,9 @@ extern struct usb_device *usb_get_dev(st
 extern void usb_put_dev(struct usb_device *dev);
 
 /* USB device locking */
-#define usb_lock_device(udev)		down(&(udev)->dev.sem)
-#define usb_unlock_device(udev)		up(&(udev)->dev.sem)
-#define usb_trylock_device(udev)	down_trylock(&(udev)->dev.sem)
+#define usb_lock_device(udev)		mutex_lock(&(udev)->dev.mutex)
+#define usb_unlock_device(udev)		mutex_unlock(&(udev)->dev.mutex)
+#define usb_trylock_device(udev)	mutex_trylock(&(udev)->dev.mutex)
 extern int usb_lock_device_for_reset(struct usb_device *udev,
 				     const struct usb_interface *iface);
 
#49 lore raw

RFC PATCH 31/37 ia64: salinfo: semaphore_init instead of init_MUTEX

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and used as completion in some places. Make it a semaphore.

---
 arch/ia64/kernel/salinfo.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/kernel/salinfo.c +1 -1
Index: linux-2.6-tip/arch/ia64/kernel/salinfo.c
===================================================================
@@ -643,7 +643,7 @@ salinfo_init(void)
 	for (i = 0; i < ARRAY_SIZE(salinfo_log_name); i++) {
 		data = salinfo_data + i;
 		data->type = i;
-		init_MUTEX(&data->mutex);
+		semaphore_init(&data->mutex);
 		dir = proc_mkdir(salinfo_log_name[i], salinfo_dir);
 		if (!dir)
 			continue;
#50 lore raw

RFC PATCH 32/37 drivers/macintosh/adb: Do not claim that the semaphore is a mutex

In reply to Thomas Gleixner

The usage of this "mutex" is non obvious and used as completion in some places. Make it a semaphore.

Cc Benjamin Herrenschmidt <[email protected]>
---
 drivers/macintosh/adb.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/macintosh/adb.c +1 -1
Index: linux-2.6-tip/drivers/macintosh/adb.c
===================================================================
@@ -83,7 +83,7 @@ static struct adb_driver *adb_controller
 BLOCKING_NOTIFIER_HEAD(adb_client_list);
 static int adb_got_sleep;
 static int adb_inited;
-static DECLARE_MUTEX(adb_probe_mutex);
+static DEFINE_SEMAPHORE(adb_probe_mutex);
 static int sleepy_trackpad;
 static int autopoll_devs;
 int __adb_probe_sync;
#51 lore raw

RFC PATCH 33/37 arm: w90x900: convert semaphore to mutex

In reply to Thomas Gleixner

The semaphore is used as mutex so make it a mutex.

---
 arch/arm/mach-w90x900/mfp-w90p910.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
arch/arm/mach-w90x900/mfp-w90p910.c +7 -7
Index: linux-2.6-tip/arch/arm/mach-w90x900/mfp-w90p910.c
===================================================================
@@ -34,7 +34,7 @@
 #define GPSELEI0	(0x01 << 26)
 #define GPSELEI1	(0x01 << 27)
 
-static DECLARE_MUTEX(mfp_sem);
+static DEFINE_MUTEX(mfp_sem);
 
 void mfp_set_groupf(struct device *dev)
 {
@@ -43,7 +43,7 @@ void mfp_set_groupf(struct device *dev)
 
 	BUG_ON(!dev);
 
-	down(&mfp_sem);
+	mutex_lock(&mfp_sem);
 
 	dev_id = dev_name(dev);
 
@@ -56,7 +56,7 @@ void mfp_set_groupf(struct device *dev)
 
 	__raw_writel(mfpen, REG_MFSEL);
 
-	up(&mfp_sem);
+	mutex_unlock(&mfp_sem);
 }
 EXPORT_SYMBOL(mfp_set_groupf);
 
@@ -67,7 +67,7 @@ void mfp_set_groupc(struct device *dev)
 
 	BUG_ON(!dev);
 
-	down(&mfp_sem);
+	mutex_lock(&mfp_sem);
 
 	dev_id = dev_name(dev);
 
@@ -86,7 +86,7 @@ void mfp_set_groupc(struct device *dev)
 
 	__raw_writel(mfpen, REG_MFSEL);
 
-	up(&mfp_sem);
+	mutex_unlock(&mfp_sem);
 }
 EXPORT_SYMBOL(mfp_set_groupc);
 
@@ -97,7 +97,7 @@ void mfp_set_groupi(struct device *dev, 
 
 	BUG_ON(!dev);
 
-	down(&mfp_sem);
+	mutex_lock(&mfp_sem);
 
 	dev_id = dev_name(dev);
 
@@ -110,7 +110,7 @@ void mfp_set_groupi(struct device *dev, 
 
 	__raw_writel(mfpen, REG_MFSEL);
 
-	up(&mfp_sem);
+	mutex_unlock(&mfp_sem);
 }
 EXPORT_SYMBOL(mfp_set_groupi);
 
#53 lore raw

RFC PATCH 34/37 printk: Make console_sem a semaphore not a pseudo mutex

In reply to Thomas Gleixner

It needs to be investigated whether it can be replaced by a real mutex, but that needs more thought and investigation.

---
 kernel/printk.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/printk.c +2 -2
Index: linux-2.6-tip/kernel/printk.c
===================================================================
@@ -73,7 +73,7 @@ EXPORT_SYMBOL(oops_in_progress);
  * provides serialisation for access to the entire console
  * driver system.
  */
-static DECLARE_MUTEX(console_sem);
+static DEFINE_SEMAPHORE(console_sem);
 struct console *console_drivers;
 EXPORT_SYMBOL_GPL(console_drivers);
 
@@ -529,7 +529,7 @@ static void zap_locks(void)
 	/* If a crash is occurring, make sure we can't deadlock */
 	spin_lock_init(&logbuf_lock);
 	/* And make sure that we print immediately */
-	init_MUTEX(&console_sem);
+	semaphore_init(&console_sem);
 }
 
 #if defined(CONFIG_PRINTK_TIME)
#54 lore raw

RFC PATCH 35/37 staging: Bulk convert the semaphore mess

In reply to Thomas Gleixner

init_MUTEX(_LOCKED) and DECLARE_MUTEX are going away. Bulk convert staging users.

Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/staging/comedi/drivers/dt9812.c        |    4 ++--
 drivers/staging/comedi/drivers/usbdux.c        |    4 ++--
 drivers/staging/comedi/drivers/usbduxfast.c    |    4 ++--
 drivers/staging/cpc-usb/cpc-usb_drv.c          |    4 ++--
 drivers/staging/frontier/alphatrack.c          |    2 +-
 drivers/staging/frontier/tranzport.c           |    2 +-
 drivers/staging/go7007/go7007-driver.c         |    2 +-
 drivers/staging/go7007/go7007-i2c.c            |    2 +-
 drivers/staging/go7007/go7007-usb.c            |    2 +-
 drivers/staging/go7007/go7007-v4l2.c           |    2 +-
 drivers/staging/go7007/s2250-loader.c          |    2 +-
 drivers/staging/mimio/mimio.c                  |    2 +-
 drivers/staging/octeon/ethernet-mdio.c         |    2 +-
 drivers/staging/otus/wwrap.c                   |    2 +-
 drivers/staging/p9auth/p9auth.c                |    2 +-
 drivers/staging/rspiusb/rspiusb.c              |    2 +-
 drivers/staging/rt2870/common/2870_rtmp_init.c |    6 +++---
 17 files changed, 23 insertions(+), 23 deletions(-)
drivers/staging/comedi/drivers/dt9812.c +2 -2
Index: linux-2.6-tip/drivers/staging/comedi/drivers/dt9812.c
===================================================================
@@ -262,7 +262,7 @@ struct dt9812_usb_cmd {
 
 #define DT9812_NUM_SLOTS	16
 
-static DECLARE_MUTEX(dt9812_mutex);
+static DEFINE_SEMAPHORE(dt9812_mutex);
 
 static struct usb_device_id dt9812_table[] = {
 	{USB_DEVICE(0x0867, 0x9812)},
@@ -1121,7 +1121,7 @@ static int __init usb_dt9812_init(void)
 
 	/* Initialize all driver slots */
 	for (i = 0; i < DT9812_NUM_SLOTS; i++) {
-		init_MUTEX(&dt9812[i].mutex);
+		semaphore_init(&dt9812[i].mutex);
 		dt9812[i].serial = 0;
 		dt9812[i].usb = NULL;
 		dt9812[i].comedi = NULL;
drivers/staging/comedi/drivers/usbdux.c +2 -2
Index: linux-2.6-tip/drivers/staging/comedi/drivers/usbdux.c
===================================================================
@@ -307,7 +307,7 @@ struct usbduxsub {
  */
 static struct usbduxsub usbduxsub[NUMUSBDUX];
 
-static DECLARE_MUTEX(start_stop_sem);
+static DEFINE_SEMAPHORE(start_stop_sem);
 
 /*
  * Stops the data acquision
@@ -2349,7 +2349,7 @@ static int usbduxsub_probe(struct usb_in
 	dev_dbg(dev, "comedi_: usbdux: "
 		"usbduxsub[%d] is ready to connect to comedi.\n", index);
 
-	init_MUTEX(&(usbduxsub[index].sem));
+	semaphore_init(&(usbduxsub[index].sem));
 	/* save a pointer to the usb device */
 	usbduxsub[index].usbdev = udev;
 
drivers/staging/comedi/drivers/usbduxfast.c +2 -2
Index: linux-2.6-tip/drivers/staging/comedi/drivers/usbduxfast.c
===================================================================
@@ -201,7 +201,7 @@ struct usbduxfastsub_s {
  */
 static struct usbduxfastsub_s usbduxfastsub[NUMUSBDUXFAST];
 
-static DECLARE_MUTEX(start_stop_sem);
+static DEFINE_SEMAPHORE(start_stop_sem);
 
 /*
  * bulk transfers to usbduxfast
@@ -1500,7 +1500,7 @@ static int usbduxfastsub_probe(struct us
 	       "connect to comedi.\n", index);
 #endif
 
-	init_MUTEX(&(usbduxfastsub[index].sem));
+	semaphore_init(&(usbduxfastsub[index].sem));
 	/* save a pointer to the usb device */
 	usbduxfastsub[index].usbdev = udev;
 
drivers/staging/cpc-usb/cpc-usb_drv.c +2 -2
Index: linux-2.6-tip/drivers/staging/cpc-usb/cpc-usb_drv.c
===================================================================
@@ -83,7 +83,7 @@ static CPC_USB_T *CPCUSB_Table[CPC_USB_C
 static unsigned int CPCUsbCnt;
 
 /* prevent races between open() and disconnect() */
-static DECLARE_MUTEX(disconnect_sem);
+static DEFINE_SEMAPHORE(disconnect_sem);
 
 /* local function prototypes */
 static ssize_t cpcusb_read(struct file *file, char *buffer, size_t count,
@@ -903,7 +903,7 @@ static int cpcusb_probe(struct usb_inter
 	memset(chan, 0, sizeof(CPC_CHAN_T));
 	ResetBuffer(chan);
 
-	init_MUTEX(&card->sem);
+	semaphore_init(&card->sem);
 	spin_lock_init(&card->slock);
 
 	card->udev = udev;
drivers/staging/frontier/alphatrack.c +1 -1
Index: linux-2.6-tip/drivers/staging/frontier/alphatrack.c
===================================================================
@@ -678,7 +678,7 @@ static int usb_alphatrack_probe(struct u
 		dev_err(&intf->dev, "Out of memory\n");
 		goto exit;
 	}
-	init_MUTEX(&dev->sem);
+	semaphore_init(&dev->sem);
 	dev->intf = intf;
 	init_waitqueue_head(&dev->read_wait);
 	init_waitqueue_head(&dev->write_wait);
drivers/staging/frontier/tranzport.c +1 -1
Index: linux-2.6-tip/drivers/staging/frontier/tranzport.c
===================================================================
@@ -800,7 +800,7 @@ static int usb_tranzport_probe(struct us
 		dev_err(&intf->dev, "Out of memory\n");
 		goto exit;
 	}
-	init_MUTEX(&dev->sem);
+	semaphore_init(&dev->sem);
 	dev->intf = intf;
 	init_waitqueue_head(&dev->read_wait);
 	init_waitqueue_head(&dev->write_wait);
drivers/staging/go7007/go7007-driver.c +1 -1
Index: linux-2.6-tip/drivers/staging/go7007/go7007-driver.c
===================================================================
@@ -604,7 +604,7 @@ struct go7007 *go7007_alloc(struct go700
 	go->tuner_type = -1;
 	go->channel_number = 0;
 	go->name[0] = 0;
-	init_MUTEX(&go->hw_lock);
+	semaphore_init(&go->hw_lock);
 	init_waitqueue_head(&go->frame_waitq);
 	spin_lock_init(&go->spinlock);
 	go->video_dev = NULL;
drivers/staging/go7007/go7007-i2c.c +1 -1
Index: linux-2.6-tip/drivers/staging/go7007/go7007-i2c.c
===================================================================
@@ -48,7 +48,7 @@
 
 /* There is only one I2C port on the TW2804 that feeds all four GO7007 VIPs
  * on the Adlink PCI-MPG24, so access is shared between all of them. */
-static DECLARE_MUTEX(adlink_mpg24_i2c_lock);
+static DEFINE_SEMAPHORE(adlink_mpg24_i2c_lock);
 
 static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read,
 		u16 command, int flags, u8 *data)
drivers/staging/go7007/go7007-usb.c +1 -1
Index: linux-2.6-tip/drivers/staging/go7007/go7007-usb.c
===================================================================
@@ -1065,7 +1065,7 @@ static int go7007_usb_probe(struct usb_i
 	if (board->flags & GO7007_USB_EZUSB_I2C) {
 		memcpy(&go->i2c_adapter, &go7007_usb_adap_templ,
 				sizeof(go7007_usb_adap_templ));
-		init_MUTEX(&usb->i2c_lock);
+		semaphore_init(&usb->i2c_lock);
 		go->i2c_adapter.dev.parent = go->dev;
 		i2c_set_adapdata(&go->i2c_adapter, go);
 		if (i2c_add_adapter(&go->i2c_adapter) < 0) {
drivers/staging/go7007/go7007-v4l2.c +1 -1
Index: linux-2.6-tip/drivers/staging/go7007/go7007-v4l2.c
===================================================================
@@ -101,7 +101,7 @@ static int go7007_open(struct file *file
 		return -ENOMEM;
 	++go->ref_count;
 	gofh->go = go;
-	init_MUTEX(&gofh->lock);
+	semaphore_init(&gofh->lock);
 	gofh->buf_count = 0;
 	file->private_data = gofh;
 	return 0;
drivers/staging/go7007/s2250-loader.c +1 -1
Index: linux-2.6-tip/drivers/staging/go7007/s2250-loader.c
===================================================================
@@ -35,7 +35,7 @@ typedef struct device_extension_s {
 #define MAX_DEVICES 256
 
 static pdevice_extension_t s2250_dev_table[MAX_DEVICES];
-static DECLARE_MUTEX(s2250_dev_table_mutex);
+static DEFINE_SEMAPHORE(s2250_dev_table_mutex);
 
 #define to_s2250loader_dev_common(d) container_of(d, device_extension_t, kref)
 static void s2250loader_delete(struct kref *kref)
drivers/staging/mimio/mimio.c +1 -1
Index: linux-2.6-tip/drivers/staging/mimio/mimio.c
===================================================================
@@ -160,7 +160,7 @@ static struct usb_driver mimio_driver = 
 	.id_table = mimio_table,
 };
 
-static DECLARE_MUTEX(disconnect_sem);
+static DEFINE_SEMAPHORE(disconnect_sem);
 
 static void mimio_close(struct input_dev *idev)
 {
drivers/staging/octeon/ethernet-mdio.c +1 -1
Index: linux-2.6-tip/drivers/staging/octeon/ethernet-mdio.c
===================================================================
@@ -39,7 +39,7 @@
 
 #include "cvmx-smix-defs.h"
 
-DECLARE_MUTEX(mdio_sem);
+DEFINE_SEMAPHORE(mdio_sem);
 
 /**
  * Perform an MII read. Called by the generic MII routines
drivers/staging/otus/wwrap.c +1 -1
Index: linux-2.6-tip/drivers/staging/otus/wwrap.c
===================================================================
@@ -1066,7 +1066,7 @@ u8_t zfLnxCreateThread(zdev_t *dev)
 
     /* Create Mutex and keventd */
     INIT_WORK(&macp->kevent, kevent);
-    init_MUTEX(&macp->ioctl_sem);
+    semaphore_init(&macp->ioctl_sem);
 
     return 0;
 }
drivers/staging/p9auth/p9auth.c +1 -1
Index: linux-2.6-tip/drivers/staging/p9auth/p9auth.c
===================================================================
@@ -388,7 +388,7 @@ static int cap_init_module(void)
 	/* Initialize each device. */
 	for (i = 0; i < cap_nr_devs; i++) {
 		cap_devices[i].node_size = cap_node_size;
-		init_MUTEX(&cap_devices[i].sem);
+		semaphore_init(&cap_devices[i].sem);
 		cap_setup_cdev(&cap_devices[i], i);
 	}
 
drivers/staging/rspiusb/rspiusb.c +1 -1
Index: linux-2.6-tip/drivers/staging/rspiusb/rspiusb.c
===================================================================
@@ -63,7 +63,7 @@ static int debug;
 #endif
 
 /* prevent races between open() and disconnect() */
-static DECLARE_MUTEX(disconnect_sem);
+static DEFINE_SEMAPHORE(disconnect_sem);
 
 /* Structure to hold all of our device specific stuff */
 struct device_extension {
drivers/staging/rt2870/common/2870_rtmp_init.c +3 -3
Index: linux-2.6-tip/drivers/staging/rt2870/common/2870_rtmp_init.c
===================================================================
@@ -751,13 +751,13 @@ NDIS_STATUS	 CreateThreads(
 
 	//init_MUTEX(&(pAd->usbdev_semaphore));
 
-	init_MUTEX_LOCKED(&(pAd->mlme_semaphore));
+	semaphore_init_locked(&(pAd->mlme_semaphore));
 	init_completion (&pAd->mlmeComplete);
 
-	init_MUTEX_LOCKED(&(pAd->RTUSBCmd_semaphore));
+	semaphore_init_locked(&(pAd->RTUSBCmd_semaphore));
 	init_completion (&pAd->CmdQComplete);
 
-	init_MUTEX_LOCKED(&(pAd->RTUSBTimer_semaphore));
+	semaphore_init_locked(&(pAd->RTUSBTimer_semaphore));
 	init_completion (&pAd->TimerQComplete);
 
 	// Creat MLME Thread
#55 lore raw

RFC PATCH 36/37 fs: Convert bd_mount_sem to mutex

In reply to Thomas Gleixner

bd_mount_sem is used as mutex so make it a mutex.

---
 fs/block_dev.c     |    8 ++++----
 fs/super.c         |    4 ++--
 include/linux/fs.h |    2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
fs/block_dev.c +4 -4
Index: linux-2.6-tip/fs/block_dev.c
===================================================================
@@ -240,7 +240,7 @@ struct super_block *freeze_bdev(struct b
 	}
 	bdev->bd_fsfreeze_count++;
 
-	down(&bdev->bd_mount_sem);
+	mutex_lock(&bdev->bd_mount_sem);
 	sb = get_super(bdev);
 	if (sb && !(sb->s_flags & MS_RDONLY)) {
 		sb->s_frozen = SB_FREEZE_WRITE;
@@ -260,7 +260,7 @@ struct super_block *freeze_bdev(struct b
 					"VFS:Filesystem freeze failed\n");
 				sb->s_frozen = SB_UNFROZEN;
 				drop_super(sb);
-				up(&bdev->bd_mount_sem);
+				mutex_unlock(&bdev->bd_mount_sem);
 				bdev->bd_fsfreeze_count--;
 				mutex_unlock(&bdev->bd_fsfreeze_mutex);
 				return ERR_PTR(error);
@@ -321,7 +321,7 @@ int thaw_bdev(struct block_device *bdev,
 		drop_super(sb);
 	}
 
-	up(&bdev->bd_mount_sem);
+	mutex_unlock(&bdev->bd_mount_sem);
 	mutex_unlock(&bdev->bd_fsfreeze_mutex);
 	return 0;
 }
@@ -431,7 +431,7 @@ static void init_once(void *foo)
 
 	memset(bdev, 0, sizeof(*bdev));
 	mutex_init(&bdev->bd_mutex);
-	sema_init(&bdev->bd_mount_sem, 1);
+	mutex_init(&bdev->bd_mount_sem);
 	INIT_LIST_HEAD(&bdev->bd_inodes);
 	INIT_LIST_HEAD(&bdev->bd_list);
 #ifdef CONFIG_SYSFS
fs/super.c +2 -2
Index: linux-2.6-tip/fs/super.c
===================================================================
@@ -740,9 +740,9 @@ int get_sb_bdev(struct file_system_type 
 	 * will protect the lockfs code from trying to start a snapshot
 	 * while we are mounting
 	 */
-	down(&bdev->bd_mount_sem);
+	mutex_lock(&bdev->bd_mount_sem);
 	s = sget(fs_type, test_bdev_super, set_bdev_super, bdev);
-	up(&bdev->bd_mount_sem);
+	mutex_unlock(&bdev->bd_mount_sem);
 	if (IS_ERR(s))
 		goto error_s;
 
include/linux/fs.h +1 -1
Index: linux-2.6-tip/include/linux/fs.h
===================================================================
@@ -640,7 +640,7 @@ struct block_device {
 	struct super_block *	bd_super;
 	int			bd_openers;
 	struct mutex		bd_mutex;	/* open/close mutex */
-	struct semaphore	bd_mount_sem;
+	struct mutex		bd_mount_sem;
 	struct list_head	bd_inodes;
 	void *			bd_holder;
 	int			bd_holders;
#56 lore raw

Re: [Patch RFC 36/37] fs: Convert bd_mount_sem to mutex

Quoted 1 line · Thomas Gleixner

bd_mount_sem is used as mutex so make it a mutex.

Actually we may return to userspace with it held, so the conversion is a bad idea. But I have a patch I need to post to completely get rid of it.

#57 lore raw

Re: [Patch RFC 36/37] fs: Convert bd_mount_sem to mutex

Quoted 6 lines · Christoph Hellwig
Quoted 1 line · Thomas Gleixner

bd_mount_sem is used as mutex so make it a mutex.

Actually we may return to userspace with it held, so the conversion is a bad idea. But I have a patch I need to post to completely get rid of it.

That's why it's RFC :)

#58 lore raw

Re: [Patch RFC 36/37] fs: Convert bd_mount_sem to mutex

Quoted 10 lines · Thomas Gleixner
Quoted 6 lines · Christoph Hellwig
Quoted 1 line · Thomas Gleixner

bd_mount_sem is used as mutex so make it a mutex.

Actually we may return to userspace with it held, so the conversion is a bad idea. But I have a patch I need to post to completely get rid of it.

That's why it's RFC :)

You better inspect these at much greater detail.. Matthias (added to the CC) , and I did a great number of semaphore to mutex changes and I don't recall there being too many clear easy ones remaining .. So unless the semaphore was added in the past 12 months or so , I'd treat it as likely unsafe for converting to a mutex..

Daniel

#59 lore raw

RFC PATCH 37/37 semaphore: Remove mutex emulation

In reply to Thomas Gleixner

Semaphores used as mutexes have been deprecated for years. Now that all users are either converted to real semaphores or to mutexes remove the cruft.

---
 include/linux/semaphore.h |    6 ------
 scripts/checkpatch.pl     |    9 +++------
 2 files changed, 3 insertions(+), 12 deletions(-)
include/linux/semaphore.h +0 -6
Index: linux-2.6-tip/include/linux/semaphore.h
===================================================================
@@ -29,9 +29,6 @@ struct semaphore {
 #define DEFINE_SEMAPHORE(name)	\
 	struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
 
-#define DECLARE_MUTEX(name)	\
-	struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
-
 static inline void sema_init(struct semaphore *sem, int val)
 {
 	static struct lock_class_key __key;
@@ -53,9 +50,6 @@ static inline void __deprecated semaphor
 	sema_init(sem, 0);
 }
 
-#define init_MUTEX(sem)		sema_init(sem, 1)
-#define init_MUTEX_LOCKED(sem)	sema_init(sem, 0)
-
 extern void down(struct semaphore *sem);
 extern int __must_check down_interruptible(struct semaphore *sem);
 extern int __must_check down_killable(struct semaphore *sem);
scripts/checkpatch.pl +3 -6
Index: linux-2.6-tip/scripts/checkpatch.pl
===================================================================
@@ -2512,14 +2512,11 @@ sub process {
 			WARN("__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr);
 		}
 
-# check for semaphores used as mutexes
-		if ($line =~ /^.\s*(DECLARE_MUTEX|init_MUTEX)\s*\(/) {
-			WARN("mutexes are preferred for single holder semaphores\n" . $herecurr);
-		}
-# check for semaphores used as mutexes
-		if ($line =~ /^.\s*init_MUTEX_LOCKED\s*\(/) {
+# check for semaphores initialized locked
+		if ($line =~ /^.\s*semaphore_init_locked\s*\(/) {
 			WARN("consider using a completion\n" . $herecurr);
 		}
+
 # recommend strict_strto* over simple_strto*
 		if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
 			WARN("consider using strict_$1 in preference to simple_$1\n" . $herecurr);