diff options
Diffstat (limited to 'lib/idr.c')
-rw-r--r-- | lib/idr.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -495,6 +495,33 @@ int idr_alloc(struct idr *idr, void *ptr, int start, int end, gfp_t gfp_mask) | |||
495 | } | 495 | } |
496 | EXPORT_SYMBOL_GPL(idr_alloc); | 496 | EXPORT_SYMBOL_GPL(idr_alloc); |
497 | 497 | ||
498 | /** | ||
499 | * idr_alloc_cyclic - allocate new idr entry in a cyclical fashion | ||
500 | * @idr: the (initialized) idr | ||
501 | * @ptr: pointer to be associated with the new id | ||
502 | * @start: the minimum id (inclusive) | ||
503 | * @end: the maximum id (exclusive, <= 0 for max) | ||
504 | * @gfp_mask: memory allocation flags | ||
505 | * | ||
506 | * Essentially the same as idr_alloc, but prefers to allocate progressively | ||
507 | * higher ids if it can. If the "cur" counter wraps, then it will start again | ||
508 | * at the "start" end of the range and allocate one that has already been used. | ||
509 | */ | ||
510 | int idr_alloc_cyclic(struct idr *idr, void *ptr, int start, int end, | ||
511 | gfp_t gfp_mask) | ||
512 | { | ||
513 | int id; | ||
514 | |||
515 | id = idr_alloc(idr, ptr, max(start, idr->cur), end, gfp_mask); | ||
516 | if (id == -ENOSPC) | ||
517 | id = idr_alloc(idr, ptr, start, end, gfp_mask); | ||
518 | |||
519 | if (likely(id >= 0)) | ||
520 | idr->cur = id + 1; | ||
521 | return id; | ||
522 | } | ||
523 | EXPORT_SYMBOL(idr_alloc_cyclic); | ||
524 | |||
498 | static void idr_remove_warning(int id) | 525 | static void idr_remove_warning(int id) |
499 | { | 526 | { |
500 | printk(KERN_WARNING | 527 | printk(KERN_WARNING |