2 * Copyright 2012 Hauke Mehrtens <hauke@hauke-m.de>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * Compatibility file for Linux wireless for kernels 3.1.
11 #include <linux/idr.h>
13 static DEFINE_SPINLOCK(simple_ida_lock);
16 * ida_simple_get - get a new id.
17 * @ida: the (initialized) ida.
18 * @start: the minimum id (inclusive, < 0x8000000)
19 * @end: the maximum id (exclusive, < 0x8000000 or 0)
20 * @gfp_mask: memory allocation flags
22 * Allocates an id in the range start <= id < end, or returns -ENOSPC.
23 * On memory allocation failure, returns -ENOMEM.
25 * Use ida_simple_remove() to get rid of an id.
27 int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end,
34 BUG_ON((int)start < 0);
45 if (!ida_pre_get(ida, gfp_mask))
48 spin_lock_irqsave(&simple_ida_lock, flags);
49 ret = ida_get_new_above(ida, start, &id);
58 spin_unlock_irqrestore(&simple_ida_lock, flags);
60 if (unlikely(ret == -EAGAIN))
65 EXPORT_SYMBOL(ida_simple_get);
68 * ida_simple_remove - remove an allocated id.
69 * @ida: the (initialized) ida.
70 * @id: the id returned by ida_simple_get.
72 void ida_simple_remove(struct ida *ida, unsigned int id)
77 spin_lock_irqsave(&simple_ida_lock, flags);
79 spin_unlock_irqrestore(&simple_ida_lock, flags);
81 EXPORT_SYMBOL(ida_simple_remove);
82 /* source lib/idr.c */