[i2c] [patch 2.6.21-rc2-git +i2c-patches] i2c_register_driver() cleanup

David Brownell david-b at pacbell.net
Tue Mar 6 07:41:52 CET 2007


Minor cleanup in i2c_register_driver():  use list_for_each_entry(),
minimize scope of lock and scratch variable.

Signed-off-by: David Brownell <dbrownell at users.sourceforge.net>

---
As previously discussed.  Goes on top of various patches now in Jean's
I2C queue (#4-6 of a group posted recently).


Index: at91/drivers/i2c/i2c-core.c
===================================================================
--- at91.orig/drivers/i2c/i2c-core.c	2007-03-02 12:30:30.000000000 -0800
+++ at91/drivers/i2c/i2c-core.c	2007-03-02 18:08:18.000000000 -0800
@@ -320,8 +320,6 @@ int i2c_del_adapter(struct i2c_adapter *
 
 int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
 {
-	struct list_head   *item;
-	struct i2c_adapter *adapter;
 	int res;
 
 	/* add the driver to the list of i2c drivers in the driver core */
@@ -332,19 +330,19 @@ int i2c_register_driver(struct module *o
 	if (res)
 		return res;
 
-	mutex_lock(&core_lists);
-
 	pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
 
 	/* now look for instances of driver on our adapters */
 	if (driver->attach_adapter) {
-		list_for_each(item,&adapters) {
-			adapter = list_entry(item, struct i2c_adapter, list);
+		struct i2c_adapter *adapter;
+
+		mutex_lock(&core_lists);
+		list_for_each_entry(adapter, &adapters, list) {
 			driver->attach_adapter(adapter);
 		}
+		mutex_unlock(&core_lists);
 	}
 
-	mutex_unlock(&core_lists);
 	return 0;
 }
 EXPORT_SYMBOL(i2c_register_driver);



More information about the i2c mailing list