LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/5] use mutex instead of semaphore in several drivers
@ 2007-04-27  8:38 Matthias Kaehlcke
  2007-04-27  8:43 ` [PATCH 1/5] Power Management: use mutexes instead of semaphores Matthias Kaehlcke
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Matthias Kaehlcke @ 2007-04-27  8:38 UTC (permalink / raw)
  To: linux-kernel, akpm

this patchset converts semaphores that are used as mutexes to the
mutex API in the following drivers/code:

Power Management
Kcopyd
sysdev
pvrusb2
scx200

-- 
Matthias Kaehlcke
Linux Application Developer
Barcelona

               For to be free is not merely to cast off
               one's chains, but to live in a way that
              respects and enhances the freedom of others
                           (Nelson Mandela)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/5] Power Management: use mutexes instead of semaphores
  2007-04-27  8:38 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
@ 2007-04-27  8:43 ` Matthias Kaehlcke
  2007-04-28 10:42   ` Pavel Machek
  2007-05-04  5:54   ` Andrew Morton
  2007-04-27  8:45 ` [PATCH 2/5] Kcopyd: use mutex instead of semaphore Matthias Kaehlcke
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 11+ messages in thread
From: Matthias Kaehlcke @ 2007-04-27  8:43 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, akpm

the Power Management code uses semaphores as mutexes. use the mutex
API instead of the (binary) semaphores

Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>

--
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index bbbb973..297061c 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -26,8 +26,8 @@ LIST_HEAD(dpm_active);
 LIST_HEAD(dpm_off);
 LIST_HEAD(dpm_off_irq);
 
-DECLARE_MUTEX(dpm_sem);
-DECLARE_MUTEX(dpm_list_sem);
+DEFINE_MUTEX(dpm_mtx);
+DEFINE_MUTEX(dpm_list_mtx);
 
 /**
  *	device_pm_set_parent - Specify power dependency.
@@ -56,12 +56,12 @@ int device_pm_add(struct device * dev)
 	pr_debug("PM: Adding info for %s:%s\n",
 		 dev->bus ? dev->bus->name : "No Bus",
 		 kobject_name(&dev->kobj));
-	down(&dpm_list_sem);
+	mutex_lock(&dpm_list_mtx);
 	list_add_tail(&dev->power.entry, &dpm_active);
 	device_pm_set_parent(dev, dev->parent);
 	if ((error = dpm_sysfs_add(dev)))
 		list_del(&dev->power.entry);
-	up(&dpm_list_sem);
+	mutex_unlock(&dpm_list_mtx);
 	return error;
 }
 
@@ -70,11 +70,11 @@ void device_pm_remove(struct device * dev)
 	pr_debug("PM: Removing info for %s:%s\n",
 		 dev->bus ? dev->bus->name : "No Bus",
 		 kobject_name(&dev->kobj));
-	down(&dpm_list_sem);
+	mutex_lock(&dpm_list_mtx);
 	dpm_sysfs_remove(dev);
 	put_device(dev->power.pm_parent);
 	list_del_init(&dev->power.entry);
-	up(&dpm_list_sem);
+	mutex_unlock(&dpm_list_mtx);
 }
 
 
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index fb3d35a..2760f25 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -14,12 +14,12 @@ extern void device_shutdown(void);
 /*
  * Used to synchronize global power management operations.
  */
-extern struct semaphore dpm_sem;
+extern struct mutex dpm_mtx;
 
 /*
  * Used to serialize changes to the dpm_* lists.
  */
-extern struct semaphore dpm_list_sem;
+extern struct mutex dpm_list_mtx;
 
 /*
  * The PM lists.
diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c
index 020be36..fb75760 100644
--- a/drivers/base/power/resume.c
+++ b/drivers/base/power/resume.c
@@ -69,7 +69,7 @@ static int resume_device_early(struct device * dev)
  */
 void dpm_resume(void)
 {
-	down(&dpm_list_sem);
+	mutex_lock(&dpm_list_mtx);
 	while(!list_empty(&dpm_off)) {
 		struct list_head * entry = dpm_off.next;
 		struct device * dev = to_device(entry);
@@ -77,13 +77,13 @@ void dpm_resume(void)
 		get_device(dev);
 		list_move_tail(entry, &dpm_active);
 
-		up(&dpm_list_sem);
+		mutex_unlock(&dpm_list_mtx);
 		if (!dev->power.prev_state.event)
 			resume_device(dev);
-		down(&dpm_list_sem);
+		mutex_lock(&dpm_list_mtx);
 		put_device(dev);
 	}
-	up(&dpm_list_sem);
+	mutex_unlock(&dpm_list_mtx);
 }
 
 
@@ -97,9 +97,9 @@ void dpm_resume(void)
 void device_resume(void)
 {
 	might_sleep();
-	down(&dpm_sem);
+	mutex_lock(&dpm_mtx);
 	dpm_resume();
-	up(&dpm_sem);
+	mutex_unlock(&dpm_mtx);
 }
 
 EXPORT_SYMBOL_GPL(device_resume);
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 96370ec..df6174d 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -32,9 +32,9 @@ static void runtime_resume(struct device * dev)
 
 void dpm_runtime_resume(struct device * dev)
 {
-	down(&dpm_sem);
+	mutex_lock(&dpm_mtx);
 	runtime_resume(dev);
-	up(&dpm_sem);
+	mutex_unlock(&dpm_mtx);
 }
 EXPORT_SYMBOL(dpm_runtime_resume);
 
@@ -49,7 +49,7 @@ int dpm_runtime_suspend(struct device * dev, pm_message_t state)
 {
 	int error = 0;
 
-	down(&dpm_sem);
+	mutex_lock(&dpm_mtx);
 	if (dev->power.power_state.event == state.event)
 		goto Done;
 
@@ -59,7 +59,7 @@ int dpm_runtime_suspend(struct device * dev, pm_message_t state)
 	if (!(error = suspend_device(dev, state)))
 		dev->power.power_state = state;
  Done:
-	up(&dpm_sem);
+	mutex_unlock(&dpm_mtx);
 	return error;
 }
 EXPORT_SYMBOL(dpm_runtime_suspend);
@@ -78,8 +78,8 @@ EXPORT_SYMBOL(dpm_runtime_suspend);
  */
 void dpm_set_power_state(struct device * dev, pm_message_t state)
 {
-	down(&dpm_sem);
+	mutex_lock(&dpm_mtx);
 	dev->power.power_state = state;
-	up(&dpm_sem);
+	mutex_unlock(&dpm_mtx);
 }
 #endif  /*  0  */
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c
index ece136b..0a2fc61 100644
--- a/drivers/base/power/suspend.c
+++ b/drivers/base/power/suspend.c
@@ -96,7 +96,7 @@ int suspend_device(struct device * dev, pm_message_t state)
 
 /*
  * This is called with interrupts off, only a single CPU
- * running. We can't do down() on a semaphore (and we don't
+ * running. We can't acquire a mutex or semaphore (and we don't
  * need the protection)
  */
 static int suspend_device_late(struct device *dev, pm_message_t state)
@@ -141,18 +141,18 @@ int device_suspend(pm_message_t state)
 	int error = 0;
 
 	might_sleep();
-	down(&dpm_sem);
-	down(&dpm_list_sem);
+	mutex_lock(&dpm_mtx);
+	mutex_lock(&dpm_list_mtx);
 	while (!list_empty(&dpm_active) && error == 0) {
 		struct list_head * entry = dpm_active.prev;
 		struct device * dev = to_device(entry);
 
 		get_device(dev);
-		up(&dpm_list_sem);
+		mutex_unlock(&dpm_list_mtx);
 
 		error = suspend_device(dev, state);
 
-		down(&dpm_list_sem);
+		mutex_lock(&dpm_list_mtx);
 
 		/* Check if the device got removed */
 		if (!list_empty(&dev->power.entry)) {
@@ -167,11 +167,11 @@ int device_suspend(pm_message_t state)
 				error == -EAGAIN ? " (please convert to suspend_late)" : "");
 		put_device(dev);
 	}
-	up(&dpm_list_sem);
+	mutex_unlock(&dpm_list_mtx);
 	if (error)
 		dpm_resume();
 
-	up(&dpm_sem);
+	mutex_unlock(&dpm_mtx);
 	return error;
 }
 

-- 
Matthias Kaehlcke
Linux Application Developer
Barcelona

             You must have a plan. If you don't have a plan,
               you'll become part of somebody else's plan
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/5] Kcopyd: use mutex instead of semaphore
  2007-04-27  8:38 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
  2007-04-27  8:43 ` [PATCH 1/5] Power Management: use mutexes instead of semaphores Matthias Kaehlcke
@ 2007-04-27  8:45 ` Matthias Kaehlcke
  2007-04-27  8:48 ` [PATCH 3/5] sysdev: " Matthias Kaehlcke
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Matthias Kaehlcke @ 2007-04-27  8:45 UTC (permalink / raw)
  To: gregkh, axboe; +Cc: linux-kernel, akpm

Kcopyd uses a semaphore as mutex. use the mutex API instead of the
(binary) semaphore

Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>

--
diff --git a/drivers/md/kcopyd.c b/drivers/md/kcopyd.c
index b46f6c5..340272a 100644
--- a/drivers/md/kcopyd.c
+++ b/drivers/md/kcopyd.c
@@ -195,7 +195,7 @@ struct kcopyd_job {
 	 * These fields are only used if the job has been split
 	 * into more manageable parts.
 	 */
-	struct semaphore lock;
+	struct mutex lock;
 	atomic_t sub_jobs;
 	sector_t progress;
 };
@@ -452,7 +452,7 @@ static void segment_complete(int read_err,
 	sector_t count = 0;
 	struct kcopyd_job *job = (struct kcopyd_job *) context;
 
-	down(&job->lock);
+	mutex_lock(&job->lock);
 
 	/* update the error */
 	if (read_err)
@@ -476,7 +476,7 @@ static void segment_complete(int read_err,
 			job->progress += count;
 		}
 	}
-	up(&job->lock);
+	mutex_unlock(&job->lock);
 
 	if (count) {
 		int i;
@@ -558,7 +558,7 @@ int kcopyd_copy(struct kcopyd_client *kc, struct io_region *from,
 		dispatch_job(job);
 
 	else {
-		init_MUTEX(&job->lock);
+		mutex_init(&job->lock);
 		job->progress = 0;
 		split_job(job);
 	}

-- 
Matthias Kaehlcke
Linux Application Developer
Barcelona

      El trabajo es el refugio de los que no tienen nada que hacer
                            (Oscar Wilde)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/5] sysdev: use mutex instead of semaphore
  2007-04-27  8:38 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
  2007-04-27  8:43 ` [PATCH 1/5] Power Management: use mutexes instead of semaphores Matthias Kaehlcke
  2007-04-27  8:45 ` [PATCH 2/5] Kcopyd: use mutex instead of semaphore Matthias Kaehlcke
@ 2007-04-27  8:48 ` Matthias Kaehlcke
  2007-04-27  8:50 ` [PATCH 4/5] pvrusb2: " Matthias Kaehlcke
  2007-04-27  8:52 ` [PATCH 5/5] scx200: " Matthias Kaehlcke
  4 siblings, 0 replies; 11+ messages in thread
From: Matthias Kaehlcke @ 2007-04-27  8:48 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, akpm

the sysdev code use a semaphore as mutex. use the mutex API instead
of the (binary) semaphore

Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>

--
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 04e5db4..82c41d1 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -155,7 +155,7 @@ EXPORT_SYMBOL_GPL(sysdev_class_unregister);
 
 
 static LIST_HEAD(sysdev_drivers);
-static DECLARE_MUTEX(sysdev_drivers_lock);
+static DEFINE_MUTEX(sysdev_drivers_lock);
 
 /**
  *	sysdev_driver_register - Register auxillary driver
@@ -172,7 +172,7 @@ static DECLARE_MUTEX(sysdev_drivers_lock);
 int sysdev_driver_register(struct sysdev_class * cls,
 			   struct sysdev_driver * drv)
 {
-	down(&sysdev_drivers_lock);
+	mutex_lock(&sysdev_drivers_lock);
 	if (cls && kset_get(&cls->kset)) {
 		list_add_tail(&drv->entry, &cls->drivers);
 
@@ -184,7 +184,7 @@ int sysdev_driver_register(struct sysdev_class * cls,
 		}
 	} else
 		list_add_tail(&drv->entry, &sysdev_drivers);
-	up(&sysdev_drivers_lock);
+	mutex_unlock(&sysdev_drivers_lock);
 	return 0;
 }
 
@@ -197,7 +197,7 @@ int sysdev_driver_register(struct sysdev_class * cls,
 void sysdev_driver_unregister(struct sysdev_class * cls,
 			      struct sysdev_driver * drv)
 {
-	down(&sysdev_drivers_lock);
+	mutex_lock(&sysdev_drivers_lock);
 	list_del_init(&drv->entry);
 	if (cls) {
 		if (drv->remove) {
@@ -207,7 +207,7 @@ void sysdev_driver_unregister(struct sysdev_class * cls,
 		}
 		kset_put(&cls->kset);
 	}
-	up(&sysdev_drivers_lock);
+	mutex_unlock(&sysdev_drivers_lock);
 }
 
 EXPORT_SYMBOL_GPL(sysdev_driver_register);
@@ -246,7 +246,7 @@ int sysdev_register(struct sys_device * sysdev)
 	if (!error) {
 		struct sysdev_driver * drv;
 
-		down(&sysdev_drivers_lock);
+		mutex_lock(&sysdev_drivers_lock);
 		/* Generic notification is implicit, because it's that
 		 * code that should have called us.
 		 */
@@ -262,7 +262,7 @@ int sysdev_register(struct sys_device * sysdev)
 			if (drv->add)
 				drv->add(sysdev);
 		}
-		up(&sysdev_drivers_lock);
+		mutex_unlock(&sysdev_drivers_lock);
 	}
 	return error;
 }
@@ -271,7 +271,7 @@ void sysdev_unregister(struct sys_device * sysdev)
 {
 	struct sysdev_driver * drv;
 
-	down(&sysdev_drivers_lock);
+	mutex_lock(&sysdev_drivers_lock);
 	list_for_each_entry(drv, &sysdev_drivers, entry) {
 		if (drv->remove)
 			drv->remove(sysdev);
@@ -281,7 +281,7 @@ void sysdev_unregister(struct sys_device * sysdev)
 		if (drv->remove)
 			drv->remove(sysdev);
 	}
-	up(&sysdev_drivers_lock);
+	mutex_unlock(&sysdev_drivers_lock);
 
 	kobject_unregister(&sysdev->kobj);
 }
@@ -308,7 +308,7 @@ void sysdev_shutdown(void)
 
 	pr_debug("Shutting Down System Devices\n");
 
-	down(&sysdev_drivers_lock);
+	mutex_lock(&sysdev_drivers_lock);
 	list_for_each_entry_reverse(cls, &system_subsys.kset.list,
 				    kset.kobj.entry) {
 		struct sys_device * sysdev;
@@ -337,7 +337,7 @@ void sysdev_shutdown(void)
 				cls->shutdown(sysdev);
 		}
 	}
-	up(&sysdev_drivers_lock);
+	mutex_unlock(&sysdev_drivers_lock);
 }
 
 static void __sysdev_resume(struct sys_device *dev)

-- 
Matthias Kaehlcke
Linux Application Developer
Barcelona

     La libertad es como la mañana. Hay quienes esperan dormidos a que
   llegue, pero hay quienes desvelan y caminan la noche para alcanzarla
                        (Subcomandante Marcos)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/5] pvrusb2: use mutex instead of semaphore
  2007-04-27  8:38 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
                   ` (2 preceding siblings ...)
  2007-04-27  8:48 ` [PATCH 3/5] sysdev: " Matthias Kaehlcke
@ 2007-04-27  8:50 ` Matthias Kaehlcke
  2007-04-27 13:55   ` Mike Isely
  2007-04-27  8:52 ` [PATCH 5/5] scx200: " Matthias Kaehlcke
  4 siblings, 1 reply; 11+ messages in thread
From: Matthias Kaehlcke @ 2007-04-27  8:50 UTC (permalink / raw)
  To: isely, video4linux-list; +Cc: linux-kernel, akpm

the pvrusb2 driver use a semaphore as mutex. use the mutex API instead
of the (binary) semaphore

Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>

--
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index 9916cf3..ea450b0 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -83,7 +83,7 @@ static struct pvr2_string_table pvr2_client_lists[] = {
 };
 
 static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL};
-static DECLARE_MUTEX(pvr2_unit_sem);
+static DEFINE_MUTEX(pvr2_unit_mtx);
 
 static int ctlchg = 0;
 static int initusbreset = 1;
@@ -2069,14 +2069,14 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
 	hdw->ctl_read_urb = usb_alloc_urb(0,GFP_KERNEL);
 	if (!hdw->ctl_read_urb) goto fail;
 
-	down(&pvr2_unit_sem); do {
+	mutex_lock(&pvr2_unit_mtx); do {
 		for (idx = 0; idx < PVR_NUM; idx++) {
 			if (unit_pointers[idx]) continue;
 			hdw->unit_number = idx;
 			unit_pointers[idx] = hdw;
 			break;
 		}
-	} while (0); up(&pvr2_unit_sem);
+	} while (0); mutex_unlock(&pvr2_unit_mtx);
 
 	cnt1 = 0;
 	cnt2 = scnprintf(hdw->name+cnt1,sizeof(hdw->name)-cnt1,"pvrusb2");
@@ -2174,13 +2174,13 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
 	}
 	pvr2_i2c_core_done(hdw);
 	pvr2_hdw_remove_usb_stuff(hdw);
-	down(&pvr2_unit_sem); do {
+	mutex_lock(&pvr2_unit_mtx); do {
 		if ((hdw->unit_number >= 0) &&
 		    (hdw->unit_number < PVR_NUM) &&
 		    (unit_pointers[hdw->unit_number] == hdw)) {
 			unit_pointers[hdw->unit_number] = NULL;
 		}
-	} while (0); up(&pvr2_unit_sem);
+	} while (0); mutex_unlock(&pvr2_unit_mtx);
 	kfree(hdw->controls);
 	kfree(hdw->mpeg_ctrl_info);
 	kfree(hdw->std_defs);

-- 
Matthias Kaehlcke
Linux Application Developer
Barcelona

      The assumption that what currently exists must necessarily
        exist is the acid that corrodes all visionary thinking
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 5/5] scx200: use mutex instead of semaphore
  2007-04-27  8:38 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
                   ` (3 preceding siblings ...)
  2007-04-27  8:50 ` [PATCH 4/5] pvrusb2: " Matthias Kaehlcke
@ 2007-04-27  8:52 ` Matthias Kaehlcke
  4 siblings, 0 replies; 11+ messages in thread
From: Matthias Kaehlcke @ 2007-04-27  8:52 UTC (permalink / raw)
  To: jim.cromie; +Cc: linux-kernel, akpm

the scx200 driver use a semaphore as mutex. use the mutex API instead
of the (binary) semaphore

Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com

--
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 0b082c5..669d2ac 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -389,7 +389,7 @@ static const struct i2c_algorithm scx200_acb_algorithm = {
 };
 
 static struct scx200_acb_iface *scx200_acb_list;
-static DECLARE_MUTEX(scx200_acb_list_mutex);
+static DEFINE_MUTEX(scx200_acb_list_mutex);
 
 static __init int scx200_acb_probe(struct scx200_acb_iface *iface)
 {
@@ -473,10 +473,10 @@ static int __init scx200_acb_create(struct scx200_acb_iface *iface)
 		return -ENODEV;
 	}
 
-	down(&scx200_acb_list_mutex);
+	mutex_lock(&scx200_acb_list_mutex);
 	iface->next = scx200_acb_list;
 	scx200_acb_list = iface;
-	up(&scx200_acb_list_mutex);
+	mutex_unlock(&scx200_acb_list_mutex);
 
 	return 0;
 }
@@ -633,10 +633,10 @@ static void __exit scx200_acb_cleanup(void)
 {
 	struct scx200_acb_iface *iface;
 
-	down(&scx200_acb_list_mutex);
+	mutex_lock(&scx200_acb_list_mutex);
 	while ((iface = scx200_acb_list) != NULL) {
 		scx200_acb_list = iface->next;
-		up(&scx200_acb_list_mutex);
+		mutex_unlock(&scx200_acb_list_mutex);
 
 		i2c_del_adapter(&iface->adapter);
 
@@ -648,9 +648,9 @@ static void __exit scx200_acb_cleanup(void)
 			release_region(iface->base, 8);
 
 		kfree(iface);
-		down(&scx200_acb_list_mutex);
+		mutex_lock(&scx200_acb_list_mutex);
 	}
-	up(&scx200_acb_list_mutex);
+	mutex_unlock(&scx200_acb_list_mutex);
 }
 
 module_init(scx200_acb_init);

-- 
Matthias Kaehlcke
Linux Application Developer
Barcelona

              We build too many walls and not enough bridges
                             (Isaac Newton)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/5] pvrusb2: use mutex instead of semaphore
  2007-04-27  8:50 ` [PATCH 4/5] pvrusb2: " Matthias Kaehlcke
@ 2007-04-27 13:55   ` Mike Isely
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Isely @ 2007-04-27 13:55 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: video4linux-list, Linux Kernel Mailing List, akpm, Mike Isely at pobox


Whoops.  A straggler.

Signed-off-by: Mike Isely <isely@pobox.com>

On Fri, 27 Apr 2007, Matthias Kaehlcke wrote:

> the pvrusb2 driver use a semaphore as mutex. use the mutex API instead
> of the (binary) semaphore
> 
> Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
> 
> --
> diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
> index 9916cf3..ea450b0 100644
> --- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
> +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
> @@ -83,7 +83,7 @@ static struct pvr2_string_table pvr2_client_lists[] = {
>  };
>  
>  static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL};
> -static DECLARE_MUTEX(pvr2_unit_sem);
> +static DEFINE_MUTEX(pvr2_unit_mtx);
>  
>  static int ctlchg = 0;
>  static int initusbreset = 1;
> @@ -2069,14 +2069,14 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
>  	hdw->ctl_read_urb = usb_alloc_urb(0,GFP_KERNEL);
>  	if (!hdw->ctl_read_urb) goto fail;
>  
> -	down(&pvr2_unit_sem); do {
> +	mutex_lock(&pvr2_unit_mtx); do {
>  		for (idx = 0; idx < PVR_NUM; idx++) {
>  			if (unit_pointers[idx]) continue;
>  			hdw->unit_number = idx;
>  			unit_pointers[idx] = hdw;
>  			break;
>  		}
> -	} while (0); up(&pvr2_unit_sem);
> +	} while (0); mutex_unlock(&pvr2_unit_mtx);
>  
>  	cnt1 = 0;
>  	cnt2 = scnprintf(hdw->name+cnt1,sizeof(hdw->name)-cnt1,"pvrusb2");
> @@ -2174,13 +2174,13 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
>  	}
>  	pvr2_i2c_core_done(hdw);
>  	pvr2_hdw_remove_usb_stuff(hdw);
> -	down(&pvr2_unit_sem); do {
> +	mutex_lock(&pvr2_unit_mtx); do {
>  		if ((hdw->unit_number >= 0) &&
>  		    (hdw->unit_number < PVR_NUM) &&
>  		    (unit_pointers[hdw->unit_number] == hdw)) {
>  			unit_pointers[hdw->unit_number] = NULL;
>  		}
> -	} while (0); up(&pvr2_unit_sem);
> +	} while (0); mutex_unlock(&pvr2_unit_mtx);
>  	kfree(hdw->controls);
>  	kfree(hdw->mpeg_ctrl_info);
>  	kfree(hdw->std_defs);
> 
> 

-- 
                        |         Mike Isely          |     PGP fingerprint
     Spammers Die!!     |                             | 03 54 43 4D 75 E5 CC 92
                        |   isely @ pobox (dot) com   | 71 16 01 E2 B5 F5 C1 E8
                        |                             |

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] Power Management: use mutexes instead of semaphores
  2007-04-27  8:43 ` [PATCH 1/5] Power Management: use mutexes instead of semaphores Matthias Kaehlcke
@ 2007-04-28 10:42   ` Pavel Machek
  2007-05-04  5:54   ` Andrew Morton
  1 sibling, 0 replies; 11+ messages in thread
From: Pavel Machek @ 2007-04-28 10:42 UTC (permalink / raw)
  To: Matthias Kaehlcke, gregkh, linux-kernel, akpm

Hi!

> the Power Management code uses semaphores as mutexes. use the mutex
> API instead of the (binary) semaphores
> 
> Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>

Looks okay at a quick scan.

							Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] Power Management: use mutexes instead of semaphores
  2007-04-27  8:43 ` [PATCH 1/5] Power Management: use mutexes instead of semaphores Matthias Kaehlcke
  2007-04-28 10:42   ` Pavel Machek
@ 2007-05-04  5:54   ` Andrew Morton
  2007-05-04  7:08     ` Matthias Kaehlcke
  1 sibling, 1 reply; 11+ messages in thread
From: Andrew Morton @ 2007-05-04  5:54 UTC (permalink / raw)
  To: Matthias Kaehlcke; +Cc: gregkh, linux-kernel

On Fri, 27 Apr 2007 10:43:22 +0200 Matthias Kaehlcke <matthias.kaehlcke@gmail.com> wrote:

> the Power Management code uses semaphores as mutexes. use the mutex
> API instead of the (binary) semaphores

I know it's a little thing, but given a choice between

a) changelogs which use capital letters and fullstops and

b) changelogs which do not,

I think a) gives a better result.

I note that none of these patches added a #include <linux/mutex.h>.  Each C
file which uses mutexes should do that, rather than relying upon accidental
nested includes.  I hope you're checking for that.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] Power Management: use mutexes instead of semaphores
  2007-05-04  5:54   ` Andrew Morton
@ 2007-05-04  7:08     ` Matthias Kaehlcke
  2007-05-04  7:18       ` Andrew Morton
  0 siblings, 1 reply; 11+ messages in thread
From: Matthias Kaehlcke @ 2007-05-04  7:08 UTC (permalink / raw)
  To: Andrew Morton; +Cc: gregkh, linux-kernel

El Thu, May 03, 2007 at 10:54:32PM -0700 Andrew Morton ha dit:

> On Fri, 27 Apr 2007 10:43:22 +0200 Matthias Kaehlcke <matthias.kaehlcke@gmail.com> wrote:
> 
> > the Power Management code uses semaphores as mutexes. use the mutex
> > API instead of the (binary) semaphores
> 
> I know it's a little thing, but given a choice between
> 
> a) changelogs which use capital letters and fullstops and
> 
> b) changelogs which do not,
> 
> I think a) gives a better result.

thanks for your suggestion, i'll take it into account for future patches
 
> I note that none of these patches added a #include <linux/mutex.h>.  Each C
> file which uses mutexes should do that, rather than relying upon accidental
> nested includes.  I hope you're checking for that.

initially i added the include line (i think at least one patch still
contains it), but then i realized that in most cases the original code
doesn't include semaphore.h and i (mis-)interpreted that it should be
handled the same way (relying upon nested includes) for mutexes. 

do you want me to send you a version of the patches containing the
include?

regards

-- 
Matthias Kaehlcke
Linux Application Developer
Barcelona

      The assumption that what currently exists must necessarily
        exist is the acid that corrodes all visionary thinking
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] Power Management: use mutexes instead of semaphores
  2007-05-04  7:08     ` Matthias Kaehlcke
@ 2007-05-04  7:18       ` Andrew Morton
  0 siblings, 0 replies; 11+ messages in thread
From: Andrew Morton @ 2007-05-04  7:18 UTC (permalink / raw)
  To: Matthias Kaehlcke; +Cc: gregkh, linux-kernel

On Fri, 4 May 2007 09:08:40 +0200 Matthias Kaehlcke <matthias.kaehlcke@gmail.com> wrote:

> > I note that none of these patches added a #include <linux/mutex.h>.  Each C
> > file which uses mutexes should do that, rather than relying upon accidental
> > nested includes.  I hope you're checking for that.
> 
> initially i added the include line (i think at least one patch still
> contains it), but then i realized that in most cases the original code
> doesn't include semaphore.h and i (mis-)interpreted that it should be
> handled the same way (relying upon nested includes) for mutexes. 
> 
> do you want me to send you a version of the patches containing the
> include?

erm, is OK, I'll make the changes.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-05-04  7:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-27  8:38 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
2007-04-27  8:43 ` [PATCH 1/5] Power Management: use mutexes instead of semaphores Matthias Kaehlcke
2007-04-28 10:42   ` Pavel Machek
2007-05-04  5:54   ` Andrew Morton
2007-05-04  7:08     ` Matthias Kaehlcke
2007-05-04  7:18       ` Andrew Morton
2007-04-27  8:45 ` [PATCH 2/5] Kcopyd: use mutex instead of semaphore Matthias Kaehlcke
2007-04-27  8:48 ` [PATCH 3/5] sysdev: " Matthias Kaehlcke
2007-04-27  8:50 ` [PATCH 4/5] pvrusb2: " Matthias Kaehlcke
2007-04-27 13:55   ` Mike Isely
2007-04-27  8:52 ` [PATCH 5/5] scx200: " Matthias Kaehlcke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).