diff options
author | Tejun Heo <tj@kernel.org> | 2013-02-27 20:04:15 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-27 22:10:16 -0500 |
commit | 4ae42b0ff0f9993c79d7282218b98d8a8a4263f5 (patch) | |
tree | b97a130e605c6eacd187b80d78e9090027b526f2 /drivers/i2c/i2c-core.c | |
parent | cc39a8faedc936df90cac077b2da6f420a777259 (diff) |
i2c: convert to idr_alloc()
Convert to the much saner new idr interface.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Wolfram Sang <wolfram@the-dreams.de>
Tested-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 44 |
1 files changed, 11 insertions, 33 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 66a30f7ac882..8d1f644a7fdc 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -935,25 +935,17 @@ out_list: | |||
935 | */ | 935 | */ |
936 | int i2c_add_adapter(struct i2c_adapter *adapter) | 936 | int i2c_add_adapter(struct i2c_adapter *adapter) |
937 | { | 937 | { |
938 | int id, res = 0; | 938 | int id; |
939 | |||
940 | retry: | ||
941 | if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) | ||
942 | return -ENOMEM; | ||
943 | 939 | ||
944 | mutex_lock(&core_lock); | 940 | mutex_lock(&core_lock); |
945 | /* "above" here means "above or equal to", sigh */ | 941 | id = idr_alloc(&i2c_adapter_idr, adapter, |
946 | res = idr_get_new_above(&i2c_adapter_idr, adapter, | 942 | __i2c_first_dynamic_bus_num, 0, GFP_KERNEL); |
947 | __i2c_first_dynamic_bus_num, &id); | ||
948 | mutex_unlock(&core_lock); | 943 | mutex_unlock(&core_lock); |
949 | 944 | if (id < 0) | |
950 | if (res < 0) { | 945 | return id; |
951 | if (res == -EAGAIN) | ||
952 | goto retry; | ||
953 | return res; | ||
954 | } | ||
955 | 946 | ||
956 | adapter->nr = id; | 947 | adapter->nr = id; |
948 | |||
957 | return i2c_register_adapter(adapter); | 949 | return i2c_register_adapter(adapter); |
958 | } | 950 | } |
959 | EXPORT_SYMBOL(i2c_add_adapter); | 951 | EXPORT_SYMBOL(i2c_add_adapter); |
@@ -984,33 +976,19 @@ EXPORT_SYMBOL(i2c_add_adapter); | |||
984 | int i2c_add_numbered_adapter(struct i2c_adapter *adap) | 976 | int i2c_add_numbered_adapter(struct i2c_adapter *adap) |
985 | { | 977 | { |
986 | int id; | 978 | int id; |
987 | int status; | ||
988 | 979 | ||
989 | if (adap->nr == -1) /* -1 means dynamically assign bus id */ | 980 | if (adap->nr == -1) /* -1 means dynamically assign bus id */ |
990 | return i2c_add_adapter(adap); | 981 | return i2c_add_adapter(adap); |
991 | if (adap->nr & ~MAX_IDR_MASK) | 982 | if (adap->nr & ~MAX_IDR_MASK) |
992 | return -EINVAL; | 983 | return -EINVAL; |
993 | 984 | ||
994 | retry: | ||
995 | if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) | ||
996 | return -ENOMEM; | ||
997 | |||
998 | mutex_lock(&core_lock); | 985 | mutex_lock(&core_lock); |
999 | /* "above" here means "above or equal to", sigh; | 986 | id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1, |
1000 | * we need the "equal to" result to force the result | 987 | GFP_KERNEL); |
1001 | */ | ||
1002 | status = idr_get_new_above(&i2c_adapter_idr, adap, adap->nr, &id); | ||
1003 | if (status == 0 && id != adap->nr) { | ||
1004 | status = -EBUSY; | ||
1005 | idr_remove(&i2c_adapter_idr, id); | ||
1006 | } | ||
1007 | mutex_unlock(&core_lock); | 988 | mutex_unlock(&core_lock); |
1008 | if (status == -EAGAIN) | 989 | if (id < 0) |
1009 | goto retry; | 990 | return id == -ENOSPC ? -EBUSY : id; |
1010 | 991 | return i2c_register_adapter(adap); | |
1011 | if (status == 0) | ||
1012 | status = i2c_register_adapter(adap); | ||
1013 | return status; | ||
1014 | } | 992 | } |
1015 | EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); | 993 | EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); |
1016 | 994 | ||