aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/idr.h47
-rw-r--r--lib/idr.c49
2 files changed, 35 insertions, 61 deletions
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 8f4980db3524..ff44bc83f3cb 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -99,7 +99,6 @@ struct idr {
99 99
100void *idr_find(struct idr *idp, int id); 100void *idr_find(struct idr *idp, int id);
101int idr_pre_get(struct idr *idp, gfp_t gfp_mask); 101int idr_pre_get(struct idr *idp, gfp_t gfp_mask);
102int idr_get_new(struct idr *idp, void *ptr, int *id);
103int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id); 102int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id);
104int idr_for_each(struct idr *idp, 103int idr_for_each(struct idr *idp,
105 int (*fn)(int id, void *p, void *data), void *data); 104 int (*fn)(int id, void *p, void *data), void *data);
@@ -109,6 +108,30 @@ void idr_remove(struct idr *idp, int id);
109void idr_destroy(struct idr *idp); 108void idr_destroy(struct idr *idp);
110void idr_init(struct idr *idp); 109void idr_init(struct idr *idp);
111 110
111/**
112 * idr_get_new - allocate new idr entry
113 * @idp: idr handle
114 * @ptr: pointer you want associated with the id
115 * @id: pointer to the allocated handle
116 *
117 * Simple wrapper around idr_get_new_above() w/ @starting_id of zero.
118 */
119static inline int idr_get_new(struct idr *idp, void *ptr, int *id)
120{
121 return idr_get_new_above(idp, ptr, 0, id);
122}
123
124/**
125 * idr_for_each_entry - iterate over an idr's elements of a given type
126 * @idp: idr handle
127 * @entry: the type * to use as cursor
128 * @id: id entry's key
129 */
130#define idr_for_each_entry(idp, entry, id) \
131 for (id = 0, entry = (typeof(entry))idr_get_next((idp), &(id)); \
132 entry != NULL; \
133 ++id, entry = (typeof(entry))idr_get_next((idp), &(id)))
134
112void __idr_remove_all(struct idr *idp); /* don't use */ 135void __idr_remove_all(struct idr *idp); /* don't use */
113 136
114/** 137/**
@@ -149,7 +172,6 @@ struct ida {
149 172
150int ida_pre_get(struct ida *ida, gfp_t gfp_mask); 173int ida_pre_get(struct ida *ida, gfp_t gfp_mask);
151int ida_get_new_above(struct ida *ida, int starting_id, int *p_id); 174int ida_get_new_above(struct ida *ida, int starting_id, int *p_id);
152int ida_get_new(struct ida *ida, int *p_id);
153void ida_remove(struct ida *ida, int id); 175void ida_remove(struct ida *ida, int id);
154void ida_destroy(struct ida *ida); 176void ida_destroy(struct ida *ida);
155void ida_init(struct ida *ida); 177void ida_init(struct ida *ida);
@@ -158,17 +180,18 @@ int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end,
158 gfp_t gfp_mask); 180 gfp_t gfp_mask);
159void ida_simple_remove(struct ida *ida, unsigned int id); 181void ida_simple_remove(struct ida *ida, unsigned int id);
160 182
161void __init idr_init_cache(void);
162
163/** 183/**
164 * idr_for_each_entry - iterate over an idr's elements of a given type 184 * ida_get_new - allocate new ID
165 * @idp: idr handle 185 * @ida: idr handle
166 * @entry: the type * to use as cursor 186 * @p_id: pointer to the allocated handle
167 * @id: id entry's key 187 *
188 * Simple wrapper around ida_get_new_above() w/ @starting_id of zero.
168 */ 189 */
169#define idr_for_each_entry(idp, entry, id) \ 190static inline int ida_get_new(struct ida *ida, int *p_id)
170 for (id = 0, entry = (typeof(entry))idr_get_next((idp), &(id)); \ 191{
171 entry != NULL; \ 192 return ida_get_new_above(ida, 0, p_id);
172 ++id, entry = (typeof(entry))idr_get_next((idp), &(id))) 193}
194
195void __init idr_init_cache(void);
173 196
174#endif /* __IDR_H__ */ 197#endif /* __IDR_H__ */
diff --git a/lib/idr.c b/lib/idr.c
index 814c53ce0d41..282841b5a561 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -317,36 +317,6 @@ int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id)
317} 317}
318EXPORT_SYMBOL(idr_get_new_above); 318EXPORT_SYMBOL(idr_get_new_above);
319 319
320/**
321 * idr_get_new - allocate new idr entry
322 * @idp: idr handle
323 * @ptr: pointer you want associated with the id
324 * @id: pointer to the allocated handle
325 *
326 * If allocation from IDR's private freelist fails, idr_get_new_above() will
327 * return %-EAGAIN. The caller should retry the idr_pre_get() call to refill
328 * IDR's preallocation and then retry the idr_get_new_above() call.
329 *
330 * If the idr is full idr_get_new_above() will return %-ENOSPC.
331 *
332 * @id returns a value in the range %0 ... %0x7fffffff
333 */
334int idr_get_new(struct idr *idp, void *ptr, int *id)
335{
336 int rv;
337
338 rv = idr_get_new_above_int(idp, ptr, 0);
339 /*
340 * This is a cheap hack until the IDR code can be fixed to
341 * return proper error values.
342 */
343 if (rv < 0)
344 return _idr_rc_to_errno(rv);
345 *id = rv;
346 return 0;
347}
348EXPORT_SYMBOL(idr_get_new);
349
350static void idr_remove_warning(int id) 320static void idr_remove_warning(int id)
351{ 321{
352 printk(KERN_WARNING 322 printk(KERN_WARNING
@@ -857,25 +827,6 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id)
857EXPORT_SYMBOL(ida_get_new_above); 827EXPORT_SYMBOL(ida_get_new_above);
858 828
859/** 829/**
860 * ida_get_new - allocate new ID
861 * @ida: idr handle
862 * @p_id: pointer to the allocated handle
863 *
864 * Allocate new ID. It should be called with any required locks.
865 *
866 * If memory is required, it will return %-EAGAIN, you should unlock
867 * and go back to the idr_pre_get() call. If the idr is full, it will
868 * return %-ENOSPC.
869 *
870 * @p_id returns a value in the range %0 ... %0x7fffffff.
871 */
872int ida_get_new(struct ida *ida, int *p_id)
873{
874 return ida_get_new_above(ida, 0, p_id);
875}
876EXPORT_SYMBOL(ida_get_new);
877
878/**
879 * ida_remove - remove the given ID 830 * ida_remove - remove the given ID
880 * @ida: ida handle 831 * @ida: ida handle
881 * @id: ID to free 832 * @id: ID to free