aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-02-27 20:03:54 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:14 -0500
commit3594eb2894f571c9b9a497159b1e4d84fdac5688 (patch)
tree471f3da090b7b297b3c35e7901c91c3f5042ef52 /lib
parent12d1b4393e0d8df36b2646a5e512f0513fb532d2 (diff)
idr: refactor idr_get_new_above()
Move slot filling to idr_fill_slot() from idr_get_new_above_int() and make idr_get_new_above() directly call it. idr_get_new_above_int() is no longer needed and removed. This will be used to implement a new ID allocation interface. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/idr.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/idr.c b/lib/idr.c
index bde6eecb0e87..b13aae5bdc81 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -278,24 +278,15 @@ build_up:
278 return(v); 278 return(v);
279} 279}
280 280
281static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id) 281/*
282 * @id and @pa are from a successful allocation from idr_get_empty_slot().
283 * Install the user pointer @ptr and mark the slot full.
284 */
285static void idr_fill_slot(void *ptr, int id, struct idr_layer **pa)
282{ 286{
283 struct idr_layer *pa[MAX_IDR_LEVEL]; 287 rcu_assign_pointer(pa[0]->ary[id & IDR_MASK], (struct idr_layer *)ptr);
284 int id; 288 pa[0]->count++;
285 289 idr_mark_full(pa, id);
286 id = idr_get_empty_slot(idp, starting_id, pa);
287 if (id >= 0) {
288 /*
289 * Successfully found an empty slot. Install the user
290 * pointer and mark the slot full.
291 */
292 rcu_assign_pointer(pa[0]->ary[id & IDR_MASK],
293 (struct idr_layer *)ptr);
294 pa[0]->count++;
295 idr_mark_full(pa, id);
296 }
297
298 return id;
299} 290}
300 291
301/** 292/**
@@ -318,11 +309,14 @@ static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id)
318 */ 309 */
319int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id) 310int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id)
320{ 311{
312 struct idr_layer *pa[MAX_IDR_LEVEL];
321 int rv; 313 int rv;
322 314
323 rv = idr_get_new_above_int(idp, ptr, starting_id); 315 rv = idr_get_empty_slot(idp, starting_id, pa);
324 if (rv < 0) 316 if (rv < 0)
325 return rv == -ENOMEM ? -EAGAIN : rv; 317 return rv == -ENOMEM ? -EAGAIN : rv;
318
319 idr_fill_slot(ptr, rv, pa);
326 *id = rv; 320 *id = rv;
327 return 0; 321 return 0;
328} 322}