From mhoffman@lightlink.com Mon Jun 27 21:22:52 2005 Date: Tue, 28 Jun 2005 00:21:30 -0400 From: "Mark M. Hoffman" To: Greg KH Subject: i2c: make better use of IDR in i2c-core Message-ID: <20050628042130.GB32087@jupiter.solarsys.private> This patch uses the already existing IDR mechanism to simplify and improve the i2c_get_adapter function in i2c-core. Signed-off-by: Mark M. Hoffman Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core.c | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-) --- gregkh-2.6.orig/drivers/i2c/i2c-core.c 2005-06-29 07:55:18.000000000 -0700 +++ gregkh-2.6/drivers/i2c/i2c-core.c 2005-07-01 14:44:10.000000000 -0700 @@ -156,7 +156,7 @@ goto out_unlock; } - res = idr_get_new(&i2c_adapter_idr, NULL, &id); + res = idr_get_new(&i2c_adapter_idr, adap, &id); if (res < 0) { if (res == -EAGAIN) res = -ENOMEM; @@ -765,20 +765,15 @@ struct i2c_adapter* i2c_get_adapter(int id) { - struct list_head *item; struct i2c_adapter *adapter; down(&core_lists); - list_for_each(item,&adapters) { - adapter = list_entry(item, struct i2c_adapter, list); - if (id == adapter->nr && - try_module_get(adapter->owner)) { - up(&core_lists); - return adapter; - } - } + adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); + if (adapter && !try_module_get(adapter->owner)) + adapter = NULL; + up(&core_lists); - return NULL; + return adapter; } void i2c_put_adapter(struct i2c_adapter *adap)