public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Cc: gregkh@suse.de
Subject: [PATCH] class: add a semaphore to struct class, and use that instead of the subsystem rwsem.
Date: Wed, 9 Mar 2005 16:34:46 -0800	[thread overview]
Message-ID: <11104148861716@kroah.com> (raw)
In-Reply-To: <11104148863516@kroah.com>

ChangeSet 1.2055, 2005/03/09 15:41:29-08:00, gregkh@suse.de

[PATCH] class: add a semaphore to struct class, and use that instead of the subsystem rwsem.

This moves us away from using the rwsem, although recursive adds and removes of class devices
is not yet possible (nor is it really known if it even is needed.)  So this simple change is
done instead.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


 drivers/base/class.c   |   23 +++++++++++------------
 include/linux/device.h |    2 +-
 2 files changed, 12 insertions(+), 13 deletions(-)


diff -Nru a/drivers/base/class.c b/drivers/base/class.c
--- a/drivers/base/class.c	2005-03-09 16:28:04 -08:00
+++ b/drivers/base/class.c	2005-03-09 16:28:04 -08:00
@@ -140,6 +140,7 @@
 
 	INIT_LIST_HEAD(&cls->children);
 	INIT_LIST_HEAD(&cls->interfaces);
+	init_MUTEX(&cls->sem);
 	error = kobject_set_name(&cls->subsys.kset.kobj, "%s", cls->name);
 	if (error)
 		return error;
@@ -413,12 +414,12 @@
 
 	/* now take care of our own registration */
 	if (parent) {
-		down_write(&parent->subsys.rwsem);
+		down(&parent->sem);
 		list_add_tail(&class_dev->node, &parent->children);
 		list_for_each_entry(class_intf, &parent->interfaces, node)
 			if (class_intf->add)
 				class_intf->add(class_dev);
-		up_write(&parent->subsys.rwsem);
+		up(&parent->sem);
 	}
 
 	if (MAJOR(class_dev->devt))
@@ -448,12 +449,12 @@
 	struct class_interface * class_intf;
 
 	if (parent) {
-		down_write(&parent->subsys.rwsem);
+		down(&parent->sem);
 		list_del_init(&class_dev->node);
 		list_for_each_entry(class_intf, &parent->interfaces, node)
 			if (class_intf->remove)
 				class_intf->remove(class_dev);
-		up_write(&parent->subsys.rwsem);
+		up(&parent->sem);
 	}
 
 	if (class_dev->dev)
@@ -509,8 +510,8 @@
 
 int class_interface_register(struct class_interface *class_intf)
 {
-	struct class * parent;
-	struct class_device * class_dev;
+	struct class *parent;
+	struct class_device *class_dev;
 
 	if (!class_intf || !class_intf->class)
 		return -ENODEV;
@@ -519,14 +520,13 @@
 	if (!parent)
 		return -EINVAL;
 
-	down_write(&parent->subsys.rwsem);
+	down(&parent->sem);
 	list_add_tail(&class_intf->node, &parent->interfaces);
-
 	if (class_intf->add) {
 		list_for_each_entry(class_dev, &parent->children, node)
 			class_intf->add(class_dev);
 	}
-	up_write(&parent->subsys.rwsem);
+	up(&parent->sem);
 
 	return 0;
 }
@@ -539,14 +539,13 @@
 	if (!parent)
 		return;
 
-	down_write(&parent->subsys.rwsem);
+	down(&parent->sem);
 	list_del_init(&class_intf->node);
-
 	if (class_intf->remove) {
 		list_for_each_entry(class_dev, &parent->children, node)
 			class_intf->remove(class_dev);
 	}
-	up_write(&parent->subsys.rwsem);
+	up(&parent->sem);
 
 	class_put(parent);
 }
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h	2005-03-09 16:28:04 -08:00
+++ b/include/linux/device.h	2005-03-09 16:28:04 -08:00
@@ -15,7 +15,6 @@
 #include <linux/ioport.h>
 #include <linux/kobject.h>
 #include <linux/list.h>
-#include <linux/spinlock.h>
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pm.h>
@@ -148,6 +147,7 @@
 	struct subsystem	subsys;
 	struct list_head	children;
 	struct list_head	interfaces;
+	struct semaphore	sem;	/* locks both the children and interfaces lists */
 
 	struct class_attribute		* class_attrs;
 	struct class_device_attribute	* class_dev_attrs;


  reply	other threads:[~2005-03-10  0:55 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-10  0:34 [BK PATCH] Driver core and kobject updates for 2.6.11 Greg KH
2005-03-10  0:34 ` [PATCH] Kobject: remove some unneeded exports Greg KH
2005-03-10  0:34   ` [PATCH] Add 2.4.x cpufreq /proc and sysctl interface removal feature-removal-schedule Greg KH
2005-03-10  0:34     ` [PATCH] cpufreq 2.4 interface removal schedule Greg KH
2005-03-10  0:34       ` [PATCH] driver core: Separate platform device name from platform device number Greg KH
2005-03-10  0:34         ` [PATCH] class core: export MAJOR/MINOR to the hotplug env Greg KH
2005-03-10  0:34           ` [PATCH] block " Greg KH
2005-03-10  0:34             ` [PATCH] class_simple: pass dev_t to the class core Greg KH
2005-03-10  0:34               ` [PATCH] usb: class driver " Greg KH
2005-03-10  0:34                 ` [PATCH] i2c: " Greg KH
2005-03-10  0:34                   ` [PATCH] videodev: " Greg KH
2005-03-10  0:34                     ` [PATCH] driver core: clean driver unload Greg KH
2005-03-10  0:34                       ` [PATCH] Driver core: add "bus" symlink to class/block devices Greg KH
2005-03-10  0:34                         ` [PATCH] floppy.c: pass physical device to device registration Greg KH
2005-03-10  0:34                           ` [PATCH] kset: make ksets have a spinlock, and use that to lock their lists Greg KH
2005-03-10  0:34                             ` [PATCH] sysdev: make system_subsys static as no one else needs access to it Greg KH
2005-03-10  0:34                               ` [PATCH] kref: make kref_put return if this was the last put call Greg KH
2005-03-10  0:34                                 ` [PATCH] USB: move usb core to use class_simple instead of it's own class functions Greg KH
2005-03-10  0:34                                   ` [PATCH] kmap: remove usage of rwsem from kobj_map Greg KH
2005-03-10  0:34                                     ` [PATCH] sysdev: fix the name of the list of drivers to be a sane name Greg KH
2005-03-10  0:34                                       ` [PATCH] sysdev: remove the rwsem usage from this subsystem Greg KH
2005-03-10  0:34                                         ` Greg KH [this message]
2005-03-25 18:01         ` [PATCH] driver core: Separate platform device name from platform device number Paul Mundt
2005-03-25 18:10           ` Greg KH
2005-03-25 18:35             ` Paul Mundt
2005-03-25 19:38               ` Kyle Moffett
2005-03-25 19:58                 ` Paul Mundt
2005-03-25 20:17                   ` Kyle Moffett
2005-03-25 20:25                   ` Russell King
2005-03-25 20:56                     ` Paul Mundt
2005-03-25 21:03                       ` Russell King
2005-03-25 22:15                         ` Paul Mundt
2005-03-10  2:23     ` [PATCH] Add 2.4.x cpufreq /proc and sysctl interface removal feature-removal-schedule Dave Jones
2005-03-10  4:56     ` Dominik Brodowski

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=11104148861716@kroah.com \
    --to=greg@kroah.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

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

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