aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-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 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
766struct i2c_adapter* i2c_get_adapter(int id) 766struct 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
784void i2c_put_adapter(struct i2c_adapter *adap) 779void i2c_put_adapter(struct i2c_adapter *adap)