diff options
author | Mark M. Hoffman <mhoffman@lightlink.com> | 2005-06-28 00:21:30 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-07-11 17:10:36 -0400 |
commit | a0920e10438e9fe8b22aba607083347c84458ed8 (patch) | |
tree | 8953a2c3c19cab0d4e67fc0e396c23711388403b /drivers | |
parent | 5da69ba42aa42a479c0f5d8cb8351ebb6b51c12e (diff) |
[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')
-rw-r--r-- | drivers/i2c/i2c-core.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 51ce268998cd..4fd4f52c8e9b 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) | |||
156 | goto out_unlock; | 156 | goto out_unlock; |
157 | } | 157 | } |
158 | 158 | ||
159 | res = idr_get_new(&i2c_adapter_idr, NULL, &id); | 159 | res = idr_get_new(&i2c_adapter_idr, adap, &id); |
160 | if (res < 0) { | 160 | if (res < 0) { |
161 | if (res == -EAGAIN) | 161 | if (res == -EAGAIN) |
162 | res = -ENOMEM; | 162 | res = -ENOMEM; |
@@ -765,20 +765,15 @@ int i2c_adapter_id(struct i2c_adapter *adap) | |||
765 | 765 | ||
766 | struct i2c_adapter* i2c_get_adapter(int id) | 766 | struct i2c_adapter* i2c_get_adapter(int id) |
767 | { | 767 | { |
768 | struct list_head *item; | ||
769 | struct i2c_adapter *adapter; | 768 | struct i2c_adapter *adapter; |
770 | 769 | ||
771 | down(&core_lists); | 770 | down(&core_lists); |
772 | list_for_each(item,&adapters) { | 771 | adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); |
773 | adapter = list_entry(item, struct i2c_adapter, list); | 772 | if (adapter && !try_module_get(adapter->owner)) |
774 | if (id == adapter->nr && | 773 | adapter = NULL; |
775 | try_module_get(adapter->owner)) { | 774 | |
776 | up(&core_lists); | ||
777 | return adapter; | ||
778 | } | ||
779 | } | ||
780 | up(&core_lists); | 775 | up(&core_lists); |
781 | return NULL; | 776 | return adapter; |
782 | } | 777 | } |
783 | 778 | ||
784 | void i2c_put_adapter(struct i2c_adapter *adap) | 779 | void i2c_put_adapter(struct i2c_adapter *adap) |