]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[PATCH] i2c: make better use of IDR in i2c-core
authorMark M. Hoffman <mhoffman@lightlink.com>
Tue, 28 Jun 2005 04:21:30 +0000 (00:21 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 11 Jul 2005 21:10:36 +0000 (14:10 -0700)
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 <mhoffman@lightlink.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/i2c/i2c-core.c

index 51ce268998cd368fa065f048baee0f0f8956c111..4fd4f52c8e9b3632815c8cfeb527db3ec9c26929 100644 (file)
@@ -156,7 +156,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
                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 @@ int i2c_adapter_id(struct i2c_adapter *adap)
 
 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)