diff options
| -rw-r--r-- | lib/idr.c | 30 |
1 files changed, 12 insertions, 18 deletions
| @@ -363,7 +363,7 @@ EXPORT_SYMBOL(idr_replace); | |||
| 363 | 363 | ||
| 364 | #define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1) | 364 | #define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1) |
| 365 | 365 | ||
| 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) |
| 367 | { | 367 | { |
| 368 | struct radix_tree_root *root = &ida->ida_rt; | 368 | struct radix_tree_root *root = &ida->ida_rt; |
| 369 | void __rcu **slot; | 369 | void __rcu **slot; |
| @@ -402,8 +402,8 @@ static int ida_get_new_above(struct ida *ida, int start, int *id) | |||
| 402 | if (ebit < BITS_PER_LONG) { | 402 | if (ebit < BITS_PER_LONG) { |
| 403 | tmp |= 1UL << ebit; | 403 | tmp |= 1UL << ebit; |
| 404 | rcu_assign_pointer(*slot, (void *)tmp); | 404 | rcu_assign_pointer(*slot, (void *)tmp); |
| 405 | *id = new + ebit - RADIX_TREE_EXCEPTIONAL_SHIFT; | 405 | return new + ebit - |
| 406 | return 0; | 406 | RADIX_TREE_EXCEPTIONAL_SHIFT; |
| 407 | } | 407 | } |
| 408 | bitmap = this_cpu_xchg(ida_bitmap, NULL); | 408 | bitmap = this_cpu_xchg(ida_bitmap, NULL); |
| 409 | if (!bitmap) | 409 | if (!bitmap) |
| @@ -434,8 +434,7 @@ static int ida_get_new_above(struct ida *ida, int start, int *id) | |||
| 434 | RADIX_TREE_EXCEPTIONAL_ENTRY); | 434 | RADIX_TREE_EXCEPTIONAL_ENTRY); |
| 435 | radix_tree_iter_replace(root, &iter, slot, | 435 | radix_tree_iter_replace(root, &iter, slot, |
| 436 | bitmap); | 436 | bitmap); |
| 437 | *id = new; | 437 | return new; |
| 438 | return 0; | ||
| 439 | } | 438 | } |
| 440 | bitmap = this_cpu_xchg(ida_bitmap, NULL); | 439 | bitmap = this_cpu_xchg(ida_bitmap, NULL); |
| 441 | if (!bitmap) | 440 | if (!bitmap) |
| @@ -444,8 +443,7 @@ static int ida_get_new_above(struct ida *ida, int start, int *id) | |||
| 444 | radix_tree_iter_replace(root, &iter, slot, bitmap); | 443 | radix_tree_iter_replace(root, &iter, slot, bitmap); |
| 445 | } | 444 | } |
| 446 | 445 | ||
| 447 | *id = new; | 446 | return new; |
| 448 | return 0; | ||
| 449 | } | 447 | } |
| 450 | } | 448 | } |
| 451 | 449 | ||
| @@ -534,7 +532,7 @@ EXPORT_SYMBOL(ida_destroy); | |||
| 534 | int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, | 532 | int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, |
| 535 | gfp_t gfp) | 533 | gfp_t gfp) |
| 536 | { | 534 | { |
| 537 | int ret, id = 0; | 535 | int id = 0; |
| 538 | unsigned long flags; | 536 | unsigned long flags; |
| 539 | 537 | ||
| 540 | if ((int)min < 0) | 538 | if ((int)min < 0) |
| @@ -545,24 +543,20 @@ int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, | |||
| 545 | 543 | ||
| 546 | again: | 544 | again: |
| 547 | xa_lock_irqsave(&ida->ida_rt, flags); | 545 | xa_lock_irqsave(&ida->ida_rt, flags); |
| 548 | ret = ida_get_new_above(ida, min, &id); | 546 | id = ida_get_new_above(ida, min); |
| 549 | if (!ret) { | 547 | if (id > (int)max) { |
| 550 | if (id > max) { | 548 | ida_remove(ida, id); |
| 551 | ida_remove(ida, id); | 549 | id = -ENOSPC; |
| 552 | ret = -ENOSPC; | ||
| 553 | } else { | ||
| 554 | ret = id; | ||
| 555 | } | ||
| 556 | } | 550 | } |
| 557 | xa_unlock_irqrestore(&ida->ida_rt, flags); | 551 | xa_unlock_irqrestore(&ida->ida_rt, flags); |
| 558 | 552 | ||
| 559 | if (unlikely(ret == -EAGAIN)) { | 553 | if (unlikely(id == -EAGAIN)) { |
| 560 | if (!ida_pre_get(ida, gfp)) | 554 | if (!ida_pre_get(ida, gfp)) |
| 561 | return -ENOMEM; | 555 | return -ENOMEM; |
| 562 | goto again; | 556 | goto again; |
| 563 | } | 557 | } |
| 564 | 558 | ||
| 565 | return ret; | 559 | return id; |
| 566 | } | 560 | } |
| 567 | EXPORT_SYMBOL(ida_alloc_range); | 561 | EXPORT_SYMBOL(ida_alloc_range); |
| 568 | 562 | ||
