Re: [PATCH 1/3] i2c : use class_for_each_device

Previous thread: [PATCH] sparsemem vmemmap: initialize memmap. by Heiko Carstens on Thursday, May 8, 2008 - 11:38 pm. (5 messages)

Next thread: [PATCH 2/3] struct class sem to mutex converting by Dave Young on Friday, May 9, 2008 - 12:22 am. (4 messages)
From: Dave Young
Date: Friday, May 9, 2008 - 12:20 am

Use class_for_each_device for iteration.

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

---
 drivers/i2c/i2c-core.c |   96 ++++++++++++++++++++++++++-----------------------
 1 file changed, 52 insertions(+), 44 deletions(-)

diff -upr a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
--- a/drivers/i2c/i2c-core.c	2008-05-09 13:55:41.000000000 +0800
+++ b/drivers/i2c/i2c-core.c	2008-05-09 14:24:07.000000000 +0800
@@ -35,7 +35,6 @@
 #include <linux/completion.h>
 #include <linux/hardirq.h>
 #include <linux/irqflags.h>
-#include <linux/semaphore.h>
 #include <asm/uaccess.h>
 
 #include "i2c-core.h"
@@ -655,6 +654,16 @@ EXPORT_SYMBOL(i2c_del_adapter);
 
 
 /* ------------------------------------------------------------------------- */
+static int __attach_adapter(struct device *dev, void *data)
+{
+	struct i2c_adapter *adapter;
+	struct i2c_driver *driver = data;
+
+	adapter = container_of(dev, struct i2c_adapter, dev);
+	driver->attach_adapter(adapter);
+
+	return 0;
+}
 
 /*
  * An i2c_driver is used with one or more i2c_client (device) nodes to access
@@ -696,21 +705,52 @@ int i2c_register_driver(struct module *o
 	pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
 
 	/* legacy drivers scan i2c busses directly */
-	if (driver->attach_adapter) {
-		struct i2c_adapter *adapter;
+	if (driver->attach_adapter)
+		class_for_each_device(&i2c_adapter_class, driver,
+					__attach_adapter);
+
+	mutex_unlock(&core_lock);
+	return 0;
+}
+EXPORT_SYMBOL(i2c_register_driver);
+
+static int __detach_adapter(struct device *dev, void *data)
+{
+	struct list_head   *item2, *_n;
+	struct i2c_client  *client;
+	struct i2c_adapter *adap;
+	struct i2c_driver *driver = data;
 
-		down(&i2c_adapter_class.sem);
-		list_for_each_entry(adapter, &i2c_adapter_class.devices,
-				    dev.node) {
-			driver->attach_adapter(adapter);
+	/* Have a look at each adapter, if clients of this driver
+	 * are still attached. If so, detach them to be able to
+	 ...
From: Jean Delvare
Date: Tuesday, May 20, 2008 - 10:31 am

Hi Dave,





... but calling another one? Can't be correct. Which raises a question:
you didn't test your patch, did you? I'm also surprised how you managed
to mess this up, given that all you had to do was to move already

The rest looks OK. I'll fix the patch myself and add it to my i2c tree
now.

-- 
Jean Delvare
--

From: Dave Young
Date: Tuesday, May 20, 2008 - 6:29 pm

Thanks for review, It's only boot-tested with i2c part as built-in by

Glad to see that, thanks.

Regards
dave
--

From: Dave Young
Date: Tuesday, May 20, 2008 - 6:30 pm

From: Jean Delvare
Date: Tuesday, May 20, 2008 - 11:00 pm

Too late for this time, but for next time, you can emulate an i2c
device using the i2c-stub driver, that's very convenient when you want
to test a change that affects i2c and don't have any physical device to
test it.

-- 
Jean Delvare
--

Previous thread: [PATCH] sparsemem vmemmap: initialize memmap. by Heiko Carstens on Thursday, May 8, 2008 - 11:38 pm. (5 messages)

Next thread: [PATCH 2/3] struct class sem to mutex converting by Dave Young on Friday, May 9, 2008 - 12:22 am. (4 messages)