Commit 4ae42b0f authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

i2c: convert to idr_alloc()

Convert to the much saner new idr interface.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Wolfram Sang <wolfram@the-dreams.de>
Tested-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent cc39a8fa
...@@ -935,25 +935,17 @@ static int i2c_register_adapter(struct i2c_adapter *adap) ...@@ -935,25 +935,17 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
*/ */
int i2c_add_adapter(struct i2c_adapter *adapter) int i2c_add_adapter(struct i2c_adapter *adapter)
{ {
int id, res = 0; int id;
retry:
if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
return -ENOMEM;
mutex_lock(&core_lock); mutex_lock(&core_lock);
/* "above" here means "above or equal to", sigh */ id = idr_alloc(&i2c_adapter_idr, adapter,
res = idr_get_new_above(&i2c_adapter_idr, adapter, __i2c_first_dynamic_bus_num, 0, GFP_KERNEL);
__i2c_first_dynamic_bus_num, &id);
mutex_unlock(&core_lock); mutex_unlock(&core_lock);
if (id < 0)
if (res < 0) { return id;
if (res == -EAGAIN)
goto retry;
return res;
}
adapter->nr = id; adapter->nr = id;
return i2c_register_adapter(adapter); return i2c_register_adapter(adapter);
} }
EXPORT_SYMBOL(i2c_add_adapter); EXPORT_SYMBOL(i2c_add_adapter);
...@@ -984,33 +976,19 @@ EXPORT_SYMBOL(i2c_add_adapter); ...@@ -984,33 +976,19 @@ EXPORT_SYMBOL(i2c_add_adapter);
int i2c_add_numbered_adapter(struct i2c_adapter *adap) int i2c_add_numbered_adapter(struct i2c_adapter *adap)
{ {
int id; int id;
int status;
if (adap->nr == -1) /* -1 means dynamically assign bus id */ if (adap->nr == -1) /* -1 means dynamically assign bus id */
return i2c_add_adapter(adap); return i2c_add_adapter(adap);
if (adap->nr & ~MAX_IDR_MASK) if (adap->nr & ~MAX_IDR_MASK)
return -EINVAL; return -EINVAL;
retry:
if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
return -ENOMEM;
mutex_lock(&core_lock); mutex_lock(&core_lock);
/* "above" here means "above or equal to", sigh; id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1,
* we need the "equal to" result to force the result GFP_KERNEL);
*/
status = idr_get_new_above(&i2c_adapter_idr, adap, adap->nr, &id);
if (status == 0 && id != adap->nr) {
status = -EBUSY;
idr_remove(&i2c_adapter_idr, id);
}
mutex_unlock(&core_lock); mutex_unlock(&core_lock);
if (status == -EAGAIN) if (id < 0)
goto retry; return id == -ENOSPC ? -EBUSY : id;
return i2c_register_adapter(adap);
if (status == 0)
status = i2c_register_adapter(adap);
return status;
} }
EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment