From: David Brownell Subject: i2c: i2c_register_driver() cleanup Minor cleanup in i2c_register_driver(): use list_for_each_entry(), minimize scope of lock and scratch variable. Signed-off-by: David Brownell Signed-off-by: Jean Delvare --- drivers/i2c/i2c-core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) --- linux-2.6.21-rc3.orig/drivers/i2c/i2c-core.c 2007-03-12 09:56:00.000000000 +0100 +++ linux-2.6.21-rc3/drivers/i2c/i2c-core.c 2007-03-12 09:56:04.000000000 +0100 @@ -305,8 +305,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 */ @@ -317,20 +315,20 @@ int i2c_register_driver(struct module *o if (res) return res; - mutex_lock(&core_lists); - list_add_tail(&driver->list,&drivers); 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);