Skip to content

Commit

Permalink
ida: Change ida_get_new_above to return the id
Browse files Browse the repository at this point in the history
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: Matthew Wilcox <willy@infradead.org>
  • Loading branch information
Matthew Wilcox committed Aug 22, 2018
1 parent b03f8e4 commit 1df8951
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions lib/idr.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ EXPORT_SYMBOL(idr_replace);

#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;
void __rcu **slot;
Expand Down Expand Up @@ -402,8 +402,8 @@ static int ida_get_new_above(struct ida *ida, int start, int *id)
if (ebit < BITS_PER_LONG) {
tmp |= 1UL << ebit;
rcu_assign_pointer(*slot, (void *)tmp);
*id = new + ebit - RADIX_TREE_EXCEPTIONAL_SHIFT;
return 0;
return new + ebit -
RADIX_TREE_EXCEPTIONAL_SHIFT;
}
bitmap = this_cpu_xchg(ida_bitmap, NULL);
if (!bitmap)
Expand Down Expand Up @@ -434,8 +434,7 @@ static int ida_get_new_above(struct ida *ida, int start, int *id)
RADIX_TREE_EXCEPTIONAL_ENTRY);
radix_tree_iter_replace(root, &iter, slot,
bitmap);
*id = new;
return 0;
return new;
}
bitmap = this_cpu_xchg(ida_bitmap, NULL);
if (!bitmap)
Expand All @@ -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);
}

*id = new;
return 0;
return new;
}
}

Expand Down Expand Up @@ -534,7 +532,7 @@ EXPORT_SYMBOL(ida_destroy);
int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max,
gfp_t gfp)
{
int ret, id = 0;
int id = 0;
unsigned long flags;

if ((int)min < 0)
Expand All @@ -545,24 +543,20 @@ int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max,

again:
xa_lock_irqsave(&ida->ida_rt, flags);
ret = ida_get_new_above(ida, min, &id);
if (!ret) {
if (id > max) {
ida_remove(ida, id);
ret = -ENOSPC;
} else {
ret = id;
}
id = ida_get_new_above(ida, min);
if (id > (int)max) {
ida_remove(ida, id);
id = -ENOSPC;
}
xa_unlock_irqrestore(&ida->ida_rt, flags);

if (unlikely(ret == -EAGAIN)) {
if (unlikely(id == -EAGAIN)) {
if (!ida_pre_get(ida, gfp))
return -ENOMEM;
goto again;
}

return ret;
return id;
}
EXPORT_SYMBOL(ida_alloc_range);

Expand Down

0 comments on commit 1df8951

Please sign in to comment.