Commit 1df89519 authored by Matthew Wilcox's avatar Matthew Wilcox

ida: Change ida_get_new_above to return the id

This calling convention makes more sense for the implementation as well
as the callers.  It even shaves 32 bytes off the compiled code size.
Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
parent b03f8e43
...@@ -363,7 +363,7 @@ EXPORT_SYMBOL(idr_replace); ...@@ -363,7 +363,7 @@ EXPORT_SYMBOL(idr_replace);
#define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1) #define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1)
static int ida_get_new_above(struct ida *ida, int start, int *id) static int ida_get_new_above(struct ida *ida, int start)
{ {
struct radix_tree_root *root = &ida->ida_rt; struct radix_tree_root *root = &ida->ida_rt;
void __rcu **slot; void __rcu **slot;
...@@ -402,8 +402,8 @@ static int ida_get_new_above(struct ida *ida, int start, int *id) ...@@ -402,8 +402,8 @@ static int ida_get_new_above(struct ida *ida, int start, int *id)
if (ebit < BITS_PER_LONG) { if (ebit < BITS_PER_LONG) {
tmp |= 1UL << ebit; tmp |= 1UL << ebit;
rcu_assign_pointer(*slot, (void *)tmp); rcu_assign_pointer(*slot, (void *)tmp);
*id = new + ebit - RADIX_TREE_EXCEPTIONAL_SHIFT; return new + ebit -
return 0; RADIX_TREE_EXCEPTIONAL_SHIFT;
} }
bitmap = this_cpu_xchg(ida_bitmap, NULL); bitmap = this_cpu_xchg(ida_bitmap, NULL);
if (!bitmap) if (!bitmap)
...@@ -434,8 +434,7 @@ static int ida_get_new_above(struct ida *ida, int start, int *id) ...@@ -434,8 +434,7 @@ static int ida_get_new_above(struct ida *ida, int start, int *id)
RADIX_TREE_EXCEPTIONAL_ENTRY); RADIX_TREE_EXCEPTIONAL_ENTRY);
radix_tree_iter_replace(root, &iter, slot, radix_tree_iter_replace(root, &iter, slot,
bitmap); bitmap);
*id = new; return new;
return 0;
} }
bitmap = this_cpu_xchg(ida_bitmap, NULL); bitmap = this_cpu_xchg(ida_bitmap, NULL);
if (!bitmap) if (!bitmap)
...@@ -444,8 +443,7 @@ static int ida_get_new_above(struct ida *ida, int start, int *id) ...@@ -444,8 +443,7 @@ static int ida_get_new_above(struct ida *ida, int start, int *id)
radix_tree_iter_replace(root, &iter, slot, bitmap); radix_tree_iter_replace(root, &iter, slot, bitmap);
} }
*id = new; return new;
return 0;
} }
} }
...@@ -534,7 +532,7 @@ EXPORT_SYMBOL(ida_destroy); ...@@ -534,7 +532,7 @@ EXPORT_SYMBOL(ida_destroy);
int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max,
gfp_t gfp) gfp_t gfp)
{ {
int ret, id = 0; int id = 0;
unsigned long flags; unsigned long flags;
if ((int)min < 0) if ((int)min < 0)
...@@ -545,24 +543,20 @@ int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, ...@@ -545,24 +543,20 @@ int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max,
again: again:
xa_lock_irqsave(&ida->ida_rt, flags); xa_lock_irqsave(&ida->ida_rt, flags);
ret = ida_get_new_above(ida, min, &id); id = ida_get_new_above(ida, min);
if (!ret) { if (id > (int)max) {
if (id > max) {
ida_remove(ida, id); ida_remove(ida, id);
ret = -ENOSPC; id = -ENOSPC;
} else {
ret = id;
}
} }
xa_unlock_irqrestore(&ida->ida_rt, flags); xa_unlock_irqrestore(&ida->ida_rt, flags);
if (unlikely(ret == -EAGAIN)) { if (unlikely(id == -EAGAIN)) {
if (!ida_pre_get(ida, gfp)) if (!ida_pre_get(ida, gfp))
return -ENOMEM; return -ENOMEM;
goto again; goto again;
} }
return ret; return id;
} }
EXPORT_SYMBOL(ida_alloc_range); EXPORT_SYMBOL(ida_alloc_range);
......
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