Skip to content

Commit 1df8951

Browse files
author
Matthew Wilcox
committed
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: Matthew Wilcox <[email protected]>
1 parent b03f8e4 commit 1df8951

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

lib/idr.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ EXPORT_SYMBOL(idr_replace);
363363

364364
#define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1)
365365

366-
static int ida_get_new_above(struct ida *ida, int start, int *id)
366+
static int ida_get_new_above(struct ida *ida, int start)
367367
{
368368
struct radix_tree_root *root = &ida->ida_rt;
369369
void __rcu **slot;
@@ -402,8 +402,8 @@ static int ida_get_new_above(struct ida *ida, int start, int *id)
402402
if (ebit < BITS_PER_LONG) {
403403
tmp |= 1UL << ebit;
404404
rcu_assign_pointer(*slot, (void *)tmp);
405-
*id = new + ebit - RADIX_TREE_EXCEPTIONAL_SHIFT;
406-
return 0;
405+
return new + ebit -
406+
RADIX_TREE_EXCEPTIONAL_SHIFT;
407407
}
408408
bitmap = this_cpu_xchg(ida_bitmap, NULL);
409409
if (!bitmap)
@@ -434,8 +434,7 @@ static int ida_get_new_above(struct ida *ida, int start, int *id)
434434
RADIX_TREE_EXCEPTIONAL_ENTRY);
435435
radix_tree_iter_replace(root, &iter, slot,
436436
bitmap);
437-
*id = new;
438-
return 0;
437+
return new;
439438
}
440439
bitmap = this_cpu_xchg(ida_bitmap, NULL);
441440
if (!bitmap)
@@ -444,8 +443,7 @@ static int ida_get_new_above(struct ida *ida, int start, int *id)
444443
radix_tree_iter_replace(root, &iter, slot, bitmap);
445444
}
446445

447-
*id = new;
448-
return 0;
446+
return new;
449447
}
450448
}
451449

@@ -534,7 +532,7 @@ EXPORT_SYMBOL(ida_destroy);
534532
int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max,
535533
gfp_t gfp)
536534
{
537-
int ret, id = 0;
535+
int id = 0;
538536
unsigned long flags;
539537

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

546544
again:
547545
xa_lock_irqsave(&ida->ida_rt, flags);
548-
ret = ida_get_new_above(ida, min, &id);
549-
if (!ret) {
550-
if (id > max) {
551-
ida_remove(ida, id);
552-
ret = -ENOSPC;
553-
} else {
554-
ret = id;
555-
}
546+
id = ida_get_new_above(ida, min);
547+
if (id > (int)max) {
548+
ida_remove(ida, id);
549+
id = -ENOSPC;
556550
}
557551
xa_unlock_irqrestore(&ida->ida_rt, flags);
558552

559-
if (unlikely(ret == -EAGAIN)) {
553+
if (unlikely(id == -EAGAIN)) {
560554
if (!ida_pre_get(ida, gfp))
561555
return -ENOMEM;
562556
goto again;
563557
}
564558

565-
return ret;
559+
return id;
566560
}
567561
EXPORT_SYMBOL(ida_alloc_range);
568562

0 commit comments

Comments
 (0)