Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Tejun Heo and committed by
Linus Torvalds
46cbc1d3 aa6afca5

+7 -4
+7 -4
lib/idr.c
··· 944 944 { 945 945 int ret, id; 946 946 unsigned int max; 947 + unsigned long flags; 947 948 948 949 BUG_ON((int)start < 0); 949 950 BUG_ON((int)end < 0); ··· 960 959 if (!ida_pre_get(ida, gfp_mask)) 961 960 return -ENOMEM; 962 961 963 - spin_lock(&simple_ida_lock); 962 + spin_lock_irqsave(&simple_ida_lock, flags); 964 963 ret = ida_get_new_above(ida, start, &id); 965 964 if (!ret) { 966 965 if (id > max) { ··· 970 969 ret = id; 971 970 } 972 971 } 973 - spin_unlock(&simple_ida_lock); 972 + spin_unlock_irqrestore(&simple_ida_lock, flags); 974 973 975 974 if (unlikely(ret == -EAGAIN)) 976 975 goto again; ··· 986 985 */ 987 986 void ida_simple_remove(struct ida *ida, unsigned int id) 988 987 { 988 + unsigned long flags; 989 + 989 990 BUG_ON((int)id < 0); 990 - spin_lock(&simple_ida_lock); 991 + spin_lock_irqsave(&simple_ida_lock, flags); 991 992 ida_remove(ida, id); 992 - spin_unlock(&simple_ida_lock); 993 + spin_unlock_irqrestore(&simple_ida_lock, flags); 993 994 } 994 995 EXPORT_SYMBOL(ida_simple_remove); 995 996