summaryrefslogtreecommitdiff
path: root/drivers/i2c
diff options
context:
space:
mode:
authorMark M. Hoffman <mhoffman@lightlink.com>2005-06-28 04:21:30 (GMT)
committerGreg Kroah-Hartman <gregkh@suse.de>2005-07-11 21:10:36 (GMT)
commita0920e10438e9fe8b22aba607083347c84458ed8 (patch)
tree8953a2c3c19cab0d4e67fc0e396c23711388403b /drivers/i2c
parent5da69ba42aa42a479c0f5d8cb8351ebb6b51c12e (diff)
downloadlinux-fsl-qoriq-a0920e10438e9fe8b22aba607083347c84458ed8.tar.xz
[PATCH] i2c: make better use of IDR in i2c-core
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>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/i2c-core.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 51ce268..4fd4f52 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -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)