aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2011-11-02 16:38:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-11-02 19:07:00 -0400
commit46cbc1d3981ee753518fbf9198a14f71a9f6841e (patch)
tree0a2fbbec4adf2839e29cb1425644096d7ed6ae00 /lib
parentaa6afca5bcaba8101f3ea09d5c3e4100b2b9f0e5 (diff)
ida: make ida_simple_get/put() IRQ safe
It's often convenient to be able to release resource from IRQ context. Make ida_simple_*() use irqsave/restore spin ops so that they are IRQ safe. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/idr.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/idr.c b/lib/idr.c
index bbf211aea4eb..ed055b297c81 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -944,6 +944,7 @@ int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end,
944{ 944{
945 int ret, id; 945 int ret, id;
946 unsigned int max; 946 unsigned int max;
947 unsigned long flags;
947 948
948 BUG_ON((int)start < 0); 949 BUG_ON((int)start < 0);
949 BUG_ON((int)end < 0); 950 BUG_ON((int)end < 0);
@@ -959,7 +960,7 @@ again:
959 if (!ida_pre_get(ida, gfp_mask)) 960 if (!ida_pre_get(ida, gfp_mask))
960 return -ENOMEM; 961 return -ENOMEM;
961 962
962 spin_lock(&simple_ida_lock); 963 spin_lock_irqsave(&simple_ida_lock, flags);
963 ret = ida_get_new_above(ida, start, &id); 964 ret = ida_get_new_above(ida, start, &id);
964 if (!ret) { 965 if (!ret) {
965 if (id > max) { 966 if (id > max) {
@@ -969,7 +970,7 @@ again:
969 ret = id; 970 ret = id;
970 } 971 }
971 } 972 }
972 spin_unlock(&simple_ida_lock); 973 spin_unlock_irqrestore(&simple_ida_lock, flags);
973 974
974 if (unlikely(ret == -EAGAIN)) 975 if (unlikely(ret == -EAGAIN))
975 goto again; 976 goto again;
@@ -985,10 +986,12 @@ EXPORT_SYMBOL(ida_simple_get);
985 */ 986 */
986void ida_simple_remove(struct ida *ida, unsigned int id) 987void ida_simple_remove(struct ida *ida, unsigned int id)
987{ 988{
989 unsigned long flags;
990
988 BUG_ON((int)id < 0); 991 BUG_ON((int)id < 0);
989 spin_lock(&simple_ida_lock); 992 spin_lock_irqsave(&simple_ida_lock, flags);
990 ida_remove(ida, id); 993 ida_remove(ida, id);
991 spin_unlock(&simple_ida_lock); 994 spin_unlock_irqrestore(&simple_ida_lock, flags);
992} 995}
993EXPORT_SYMBOL(ida_simple_remove); 996EXPORT_SYMBOL(ida_simple_remove);
994 997