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: Michael.Waychison@Sun.COM
Subject: [PATCH] driver core: clean driver unload
Date: Wed, 9 Mar 2005 16:34:44 -0800	[thread overview]
Message-ID: <11104148843411@kroah.com> (raw)
In-Reply-To: <11104148831572@kroah.com>

ChangeSet 1.2045, 2005/03/09 09:52:29-08:00, Michael.Waychison@Sun.COM

[PATCH] driver core: clean driver unload

Get rid of semaphore abuse by converting device_driver->unload_sem
semaphore to device_driver->unloaded completion.

This should get rid of any confusion as well as save a few bytes in the
process.

Signed-off-by: Mike Waychison <michael.waychison@sun.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


 drivers/base/bus.c     |    2 +-
 drivers/base/driver.c  |   13 ++++++-------
 include/linux/device.h |    2 +-
 3 files changed, 8 insertions(+), 9 deletions(-)


diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c	2005-03-09 16:29:14 -08:00
+++ b/drivers/base/bus.c	2005-03-09 16:29:14 -08:00
@@ -65,7 +65,7 @@
 static void driver_release(struct kobject * kobj)
 {
 	struct device_driver * drv = to_driver(kobj);
-	up(&drv->unload_sem);
+	complete(&drv->unloaded);
 }
 
 static struct kobj_type ktype_driver = {
diff -Nru a/drivers/base/driver.c b/drivers/base/driver.c
--- a/drivers/base/driver.c	2005-03-09 16:29:14 -08:00
+++ b/drivers/base/driver.c	2005-03-09 16:29:14 -08:00
@@ -79,14 +79,14 @@
  *	since most of the things we have to do deal with the bus
  *	structures.
  *
- *	The one interesting aspect is that we initialize @drv->unload_sem
- *	to a locked state here. It will be unlocked when the driver
- *	reference count reaches 0.
+ *	The one interesting aspect is that we setup @drv->unloaded
+ *	as a completion that gets complete when the driver reference
+ *	count reaches 0.
  */
 int driver_register(struct device_driver * drv)
 {
 	INIT_LIST_HEAD(&drv->devices);
-	init_MUTEX_LOCKED(&drv->unload_sem);
+	init_completion(&drv->unloaded);
 	return bus_add_driver(drv);
 }
 
@@ -97,7 +97,7 @@
  *
  *	Again, we pass off most of the work to the bus-level call.
  *
- *	Though, once that is done, we attempt to take @drv->unload_sem.
+ *	Though, once that is done, we wait until @drv->unloaded is completed.
  *	This will block until the driver refcount reaches 0, and it is
  *	released. Only modular drivers will call this function, and we
  *	have to guarantee that it won't complete, letting the driver
@@ -107,8 +107,7 @@
 void driver_unregister(struct device_driver * drv)
 {
 	bus_remove_driver(drv);
-	down(&drv->unload_sem);
-	up(&drv->unload_sem);
+	wait_for_completion(&drv->unloaded);
 }
 
 /**
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h	2005-03-09 16:29:14 -08:00
+++ b/include/linux/device.h	2005-03-09 16:29:14 -08:00
@@ -102,7 +102,7 @@
 	char			* name;
 	struct bus_type		* bus;
 
-	struct semaphore	unload_sem;
+	struct completion	unloaded;
 	struct kobject		kobj;
 	struct list_head	devices;
 


  reply	other threads:[~2005-03-10  1:10 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                     ` Greg KH [this message]
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                                         ` [PATCH] class: add a semaphore to struct class, and use that instead of the subsystem rwsem Greg KH
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=11104148843411@kroah.com \
    --to=greg@kroah.com \
    --cc=Michael.Waychison@Sun.COM \
    --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