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 #if ! defined(RHEL_MINOR) || (RHEL_MINOR < 3)
12 #include <linux/idr.h>
14 static DEFINE_SPINLOCK(simple_ida_lock);
17 * ida_simple_get - get a new id.
18 * @ida: the (initialized) ida.
19 * @start: the minimum id (inclusive, < 0x8000000)
20 * @end: the maximum id (exclusive, < 0x8000000 or 0)
21 * @gfp_mask: memory allocation flags
23 * Allocates an id in the range start <= id < end, or returns -ENOSPC.
24 * On memory allocation failure, returns -ENOMEM.
26 * Use ida_simple_remove() to get rid of an id.
28 int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end,
35 BUG_ON((int)start < 0);
46 if (!ida_pre_get(ida, gfp_mask))
49 spin_lock_irqsave(&simple_ida_lock, flags);
50 ret = ida_get_new_above(ida, start, &id);
59 spin_unlock_irqrestore(&simple_ida_lock, flags);
61 if (unlikely(ret == -EAGAIN))
66 EXPORT_SYMBOL(ida_simple_get);
69 * ida_simple_remove - remove an allocated id.
70 * @ida: the (initialized) ida.
71 * @id: the id returned by ida_simple_get.
73 void ida_simple_remove(struct ida *ida, unsigned int id)
78 spin_lock_irqsave(&simple_ida_lock, flags);
80 spin_unlock_irqrestore(&simple_ida_lock, flags);
82 EXPORT_SYMBOL(ida_simple_remove);
83 /* source lib/idr.c */