LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/2] driver-core : convert to use class_find_device api
@ 2008-01-28  8:56 Dave Young
  0 siblings, 0 replies; only message in thread
From: Dave Young @ 2008-01-28  8:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel

Convert to use class_find_device api in drivers/base/core.c

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

---
drivers/base/core.c |   32 +++++++++++---------------------
1 file changed, 11 insertions(+), 21 deletions(-)

diff -upr a/drivers/base/core.c b/drivers/base/core.c
--- a/drivers/base/core.c	2008-01-28 16:30:20.000000000 +0800
+++ b/drivers/base/core.c	2008-01-28 16:30:20.000000000 +0800
@@ -1136,25 +1136,11 @@ error:
 }
 EXPORT_SYMBOL_GPL(device_create);
 
-/**
- * find_device - finds a device that was created with device_create()
- * @class: pointer to the struct class that this device was registered with
- * @devt: the dev_t of the device that was previously registered
- */
-static struct device *find_device(struct class *class, dev_t devt)
+static int __match_devt(struct device *dev, void *data)
 {
-	struct device *dev = NULL;
-	struct device *dev_tmp;
+	dev_t *devt = data;
 
-	down(&class->sem);
-	list_for_each_entry(dev_tmp, &class->devices, node) {
-		if (dev_tmp->devt == devt) {
-			dev = dev_tmp;
-			break;
-		}
-	}
-	up(&class->sem);
-	return dev;
+	return dev->devt == *devt;
 }
 
 /**
@@ -1169,9 +1155,11 @@ void device_destroy(struct class *class,
 {
 	struct device *dev;
 
-	dev = find_device(class, devt);
-	if (dev)
+	dev = class_find_device(class, &devt, __match_devt);
+	if (dev) {
+		put_device(dev);
 		device_unregister(dev);
+	}
 }
 EXPORT_SYMBOL_GPL(device_destroy);
 
@@ -1195,9 +1183,11 @@ void destroy_suspended_device(struct cla
 {
 	struct device *dev;
 
-	dev = find_device(class, devt);
-	if (dev)
+	dev = class_find_device(class, &devt, __match_devt);
+	if (dev) {
 		device_pm_schedule_removal(dev);
+		put_device(dev);
+	}
 }
 EXPORT_SYMBOL_GPL(destroy_suspended_device);
 #endif /* CONFIG_PM_SLEEP */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-01-28  8:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-28  8:56 [PATCH 1/2] driver-core : convert to use class_find_device api Dave Young

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).