mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Young <hidave.darkstar@gmail.com>
To: Jarek Poplawski <jarkao2@gmail.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>,
	Alan Stern <stern@rowland.harvard.edu>, Greg KH <gregkh@suse.de>,
	stefanr@s5r6.in-berlin.de, David Brownell <david-b@pacbell.net>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 7/7] driver-core : convert semaphore to mutex in struct class
Date: Mon, 21 Jan 2008 09:43:35 +0800	[thread overview]
Message-ID: <20080121014335.GA3219@darkstar.te-china.tietoenator.com> (raw)
In-Reply-To: <20080121013021.GB2832@darkstar.te-china.tietoenator.com>

On Mon, Jan 21, 2008 at 09:30:21AM +0800, Dave Young wrote:
> On Sat, Jan 19, 2008 at 10:39:33AM +0100, Jarek Poplawski wrote:
> > Dave Young wrote, On 01/18/2008 10:07 AM:
> > 
> > > On Jan 18, 2008 4:23 PM, Jarek Poplawski <jarkao2@gmail.com> wrote:
> > 
> > >> On Fri, Jan 18, 2008 at 03:48:02PM +0800, Dave Young wrote:
> > 
> > ...
> > 
> > >>> 1) Using CLASS_NORMAL/CLASS_PARENT/CLASS_CHILD will be enough.
> > >>> or
> > >>> 2) Simply add SINGLE_LEVEL_NESTING in class_device_add and other
> > >>> class_device functions because it is the only possible nest-lock place
> > >>> as I know.
> > 
> > 
> Althoug the class_device will be away soon, the patch is updated as following because the problem is clear and only several lines are changed. At least, it could be used for test.
> 
> 
> Convert the class semaphore to mutex.
> class_interface_register/unregister use class_device_* functions, so SINGLE_DEPTH_NESTING added for lockdep please in these functions. 
> 
> Signed-off-by: Dave Young <hidave.darkstar@gmail.com> 
> 
Sorry for the dirty patch, please don't test the previous one.
I should have drink a cup of coffe before posting.
post the right one again.
---

Convert the class semaphore to mutex.
class_interface_register/unregister use class_device_* functions, so SINGLE_DEPTH_NESTING added for lockdep please in these functions. 

Signed-off-by: Dave Young <hidave.darkstar@gmail.com> 

---
 drivers/base/class.c   |   38 +++++++++++++++++++-------------------
 drivers/base/core.c    |   18 ++++++++----------
 include/linux/device.h |    3 ++-
 3 files changed, 29 insertions(+), 30 deletions(-)

Index: linux-2.6.23/drivers/base/class.c
===================================================================
--- linux-2.6.23.orig/drivers/base/class.c	2008-01-21 09:36:43.000000000 +0800
+++ linux-2.6.23/drivers/base/class.c	2008-01-21 09:38:14.000000000 +0800
@@ -144,7 +144,7 @@
 	INIT_LIST_HEAD(&cls->devices);
 	INIT_LIST_HEAD(&cls->interfaces);
 	kset_init(&cls->class_dirs);
-	init_MUTEX(&cls->sem);
+	mutex_init(&cls->mutex);
 	error = kobject_set_name(&cls->subsys.kobj, "%s", cls->name);
 	if (error)
 		return error;
@@ -617,13 +617,13 @@
 	kobject_uevent(&class_dev->kobj, KOBJ_ADD);
 
 	/* notify any interfaces this device is now here */
-	down(&parent_class->sem);
+	mutex_lock_nested(&parent_class->mutex, SINGLE_DEPTH_NESTING);
 	list_add_tail(&class_dev->node, &parent_class->children);
 	list_for_each_entry(class_intf, &parent_class->interfaces, node) {
 		if (class_intf->add)
 			class_intf->add(class_dev, class_intf);
 	}
-	up(&parent_class->sem);
+	mutex_unlock(&parent_class->mutex);
 
 	goto out1;
 
@@ -725,12 +725,12 @@
 	struct class_interface *class_intf;
 
 	if (parent_class) {
-		down(&parent_class->sem);
+		mutex_lock_nested(&parent_class->mutex, SINGLE_DEPTH_NESTING);
 		list_del_init(&class_dev->node);
 		list_for_each_entry(class_intf, &parent_class->interfaces, node)
 			if (class_intf->remove)
 				class_intf->remove(class_dev, class_intf);
-		up(&parent_class->sem);
+		mutex_unlock(&parent_class->mutex);
 	}
 
 	if (class_dev->dev) {
@@ -772,14 +772,14 @@
 	struct class_device *class_dev = NULL;
 	struct class_device *class_dev_tmp;
 
-	down(&cls->sem);
+	mutex_lock_nested(&cls->mutex, SINGLE_DEPTH_NESTING);
 	list_for_each_entry(class_dev_tmp, &cls->children, node) {
 		if (class_dev_tmp->devt == devt) {
 			class_dev = class_dev_tmp;
 			break;
 		}
 	}
-	up(&cls->sem);
+	mutex_unlock(&cls->mutex);
 
 	if (class_dev)
 		class_device_unregister(class_dev);
@@ -818,7 +818,7 @@
 
 	if (!class)
 		return -EINVAL;
-	down(&class->sem);
+	mutex_lock(&class->mutex);
 	list_for_each_entry(dev, &class->devices, node) {
 		dev = get_device(dev);
 		if (dev) {
@@ -829,7 +829,7 @@
 		if (error)
 			break;
 	}
-	up(&class->sem);
+	mutex_unlock(&class->mutex);
 
 	return error;
 }
@@ -860,7 +860,7 @@
 	if (!class)
 		return NULL;
 
-	down(&class->sem);
+	mutex_lock(&class->mutex);
 	list_for_each_entry(dev, &class->devices, node) {
 		dev = get_device(dev);
 		if (dev) {
@@ -872,7 +872,7 @@
 		} else
 			break;
 	}
-	up(&class->sem);
+	mutex_unlock(&class->mutex);
 
 	return found ? dev : NULL;
 }
@@ -898,7 +898,7 @@
 
 	if (!class)
 		return -EINVAL;
-	down(&class->sem);
+	mutex_lock(&class->mutex);
 	list_for_each_entry(dev, &class->children, node) {
 		dev = class_device_get(dev);
 		if (dev) {
@@ -909,7 +909,7 @@
 		if (error)
 			break;
 	}
-	up(&class->sem);
+	mutex_unlock(&class->mutex);
 
 	return error;
 }
@@ -940,7 +940,7 @@
 	if (!class)
 		return NULL;
 
-	down(&class->sem);
+	mutex_lock(&class->mutex);
 	list_for_each_entry(dev, &class->children, node) {
 		dev = class_device_get(dev);
 		if (dev) {
@@ -952,7 +952,7 @@
 		} else
 			break;
 	}
-	up(&class->sem);
+	mutex_unlock(&class->mutex);
 
 	return found ? dev : NULL;
 }
@@ -971,7 +971,7 @@
 	if (!parent)
 		return -EINVAL;
 
-	down(&parent->sem);
+	mutex_lock(&parent->mutex);
 	list_add_tail(&class_intf->node, &parent->interfaces);
 	if (class_intf->add) {
 		list_for_each_entry(class_dev, &parent->children, node)
@@ -981,7 +981,7 @@
 		list_for_each_entry(dev, &parent->devices, node)
 			class_intf->add_dev(dev, class_intf);
 	}
-	up(&parent->sem);
+	mutex_unlock(&parent->mutex);
 
 	return 0;
 }
@@ -995,7 +995,7 @@
 	if (!parent)
 		return;
 
-	down(&parent->sem);
+	mutex_lock(&parent->mutex);
 	list_del_init(&class_intf->node);
 	if (class_intf->remove) {
 		list_for_each_entry(class_dev, &parent->children, node)
@@ -1005,7 +1005,7 @@
 		list_for_each_entry(dev, &parent->devices, node)
 			class_intf->remove_dev(dev, class_intf);
 	}
-	up(&parent->sem);
+	mutex_unlock(&parent->mutex);
 
 	class_put(parent);
 }
Index: linux-2.6.23/drivers/base/core.c
===================================================================
--- linux-2.6.23.orig/drivers/base/core.c	2008-01-21 09:35:37.000000000 +0800
+++ linux-2.6.23/drivers/base/core.c	2008-01-21 09:36:47.000000000 +0800
@@ -19,8 +19,6 @@
 #include <linux/kdev_t.h>
 #include <linux/notifier.h>
 
-#include <asm/semaphore.h>
-
 #include "base.h"
 #include "power/power.h"
 
@@ -783,7 +781,7 @@
 		klist_add_tail(&dev->knode_parent, &parent->klist_children);
 
 	if (dev->class) {
-		down(&dev->class->sem);
+		mutex_lock(&dev->class->mutex);
 		/* tie the class to the device */
 		list_add_tail(&dev->node, &dev->class->devices);
 
@@ -791,7 +789,7 @@
 		list_for_each_entry(class_intf, &dev->class->interfaces, node)
 			if (class_intf->add_dev)
 				class_intf->add_dev(dev, class_intf);
-		up(&dev->class->sem);
+		mutex_unlock(&dev->class->mutex);
 	}
  Done:
 	put_device(dev);
@@ -928,14 +926,14 @@
 			sysfs_remove_link(&dev->kobj, "device");
 		}
 
-		down(&dev->class->sem);
+		mutex_lock(&dev->class->mutex);
 		/* notify any interfaces that the device is now gone */
 		list_for_each_entry(class_intf, &dev->class->interfaces, node)
 			if (class_intf->remove_dev)
 				class_intf->remove_dev(dev, class_intf);
 		/* remove the device from the class list */
 		list_del_init(&dev->node);
-		up(&dev->class->sem);
+		mutex_unlock(&dev->class->mutex);
 
 		/* If we live in a parent class-directory, unreference it */
 		if (dev->kobj.parent->kset == &dev->class->class_dirs) {
@@ -946,7 +944,7 @@
 			 * if we are the last child of our class, delete
 			 * our class-directory at this parent
 			 */
-			down(&dev->class->sem);
+			mutex_lock(&dev->class->mutex);
 			list_for_each_entry(d, &dev->class->devices, node) {
 				if (d == dev)
 					continue;
@@ -959,7 +957,7 @@
 				kobject_del(dev->kobj.parent);
 
 			kobject_put(dev->kobj.parent);
-			up(&dev->class->sem);
+			mutex_unlock(&dev->class->mutex);
 		}
 	}
 	device_remove_file(dev, &uevent_attr);
@@ -1168,14 +1166,14 @@
 	struct device *dev = NULL;
 	struct device *dev_tmp;
 
-	down(&class->sem);
+	mutex_lock(&class->mutex);
 	list_for_each_entry(dev_tmp, &class->devices, node) {
 		if (dev_tmp->devt == devt) {
 			dev = dev_tmp;
 			break;
 		}
 	}
-	up(&class->sem);
+	mutex_unlock(&class->mutex);
 
 	if (dev)
 		device_unregister(dev);
Index: linux-2.6.23/include/linux/device.h
===================================================================
--- linux-2.6.23.orig/include/linux/device.h	2008-01-21 09:36:43.000000000 +0800
+++ linux-2.6.23/include/linux/device.h	2008-01-21 09:36:47.000000000 +0800
@@ -20,6 +20,7 @@
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pm.h>
+ #include <linux/mutex.h>
 #include <asm/semaphore.h>
 #include <asm/atomic.h>
 #include <asm/device.h>
@@ -180,7 +181,7 @@
 	struct list_head	devices;
 	struct list_head	interfaces;
 	struct kset		class_dirs;
-	struct semaphore	sem; /* locks children, devices, interfaces */
+	struct mutex		mutex; /* locks children, devices, interfaces */
 	struct class_attribute		* class_attrs;
 	struct class_device_attribute	* class_dev_attrs;
 	struct device_attribute		* dev_attrs;

  reply	other threads:[~2008-01-21  1:42 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-12 10:05 Dave Young
2008-01-15  9:15 ` Dave Young
2008-01-15 13:56   ` Jarek Poplawski
2008-01-16  1:03     ` Dave Young
2008-01-16  8:34       ` Jarek Poplawski
2008-01-17  1:17         ` Dave Young
2008-01-17  8:38           ` Jarek Poplawski
2008-01-17  8:56             ` Dave Young
2008-01-16 15:27       ` Alan Stern
2008-01-17  0:01         ` Jarek Poplawski
2008-01-17  1:18         ` Dave Young
2008-01-17 15:16           ` Alan Stern
2008-01-17 19:47             ` Jarek Poplawski
2008-01-17 19:57               ` Alan Stern
2008-01-17 20:31                 ` Jarek Poplawski
2008-01-17 22:02                   ` Jarek Poplawski
2008-01-17 23:26                   ` Jarek Poplawski
2008-01-18  1:42                     ` Dave Young
2008-01-18  1:55                       ` Kay Sievers
2008-01-18  2:28                         ` Dave Young
2008-01-18  3:18                           ` Kay Sievers
2008-01-18  6:25                             ` Greg KH
     [not found]                             ` <a8e1da0801172131h57097622h6d111133b6a0773d@mail.gmail.com>
2008-01-18  7:38                               ` Jarek Poplawski
2008-01-18  7:48                                 ` Dave Young
2008-01-18  8:23                                   ` Jarek Poplawski
2008-01-18  9:07                                     ` Dave Young
2008-01-19  9:39                                       ` Jarek Poplawski
2008-01-21  1:19                                         ` Dave Young
2008-01-21  1:30                                         ` Dave Young
2008-01-21  1:43                                           ` Dave Young [this message]
2008-01-21  8:36                                             ` Jarek Poplawski
2008-01-21  8:44                                               ` Dave Young
2008-01-21  9:03                                                 ` Jarek Poplawski
2008-01-21 21:16                                                 ` Jarek Poplawski
2008-01-22  0:55                                                   ` Dave Young
2008-01-22  5:15                                                     ` Greg KH
2008-01-22  6:13                                                       ` Dave Young
2008-01-22  7:45                                                     ` Jarek Poplawski
2008-01-18 10:45                                 ` Kay Sievers
2008-01-18 11:40                                   ` Jarek Poplawski
2008-01-18  8:00                       ` Jarek Poplawski
2008-01-18  8:39                         ` Jarek Poplawski
2008-01-17 21:11                 ` Greg KH
2008-01-17 21:55                   ` Jarek Poplawski
2008-01-18  1:45             ` Dave Young

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080121014335.GA3219@darkstar.te-china.tietoenator.com \
    --to=hidave.darkstar@gmail.com \
    --cc=david-b@pacbell.net \
    --cc=gregkh@suse.de \
    --cc=jarkao2@gmail.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stefanr@s5r6.in-berlin.de \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®