From 226caa377714699adda6ca83adb2398896927cfa Mon Sep 17 00:00:00 2001 From: Sonny Rao Date: Sun, 25 Jun 2006 05:49:34 -0700 Subject: [PATCH] --- yaml --- r: 29832 b: refs/heads/master c: 1eec00565d849ceda67f425e089c3233e3ef2ca2 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/lib/idr.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/[refs] b/[refs] index 55925857c949..984fb45851eb 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: a45219483e2894af3c07f959cbd4edb4575b4f8c +refs/heads/master: 1eec00565d849ceda67f425e089c3233e3ef2ca2 diff --git a/trunk/lib/idr.c b/trunk/lib/idr.c index d226259c3c28..de19030a999b 100644 --- a/trunk/lib/idr.c +++ b/trunk/lib/idr.c @@ -48,15 +48,21 @@ static struct idr_layer *alloc_layer(struct idr *idp) return(p); } +/* only called when idp->lock is held */ +static void __free_layer(struct idr *idp, struct idr_layer *p) +{ + p->ary[0] = idp->id_free; + idp->id_free = p; + idp->id_free_cnt++; +} + static void free_layer(struct idr *idp, struct idr_layer *p) { /* * Depends on the return element being zeroed. */ spin_lock(&idp->lock); - p->ary[0] = idp->id_free; - idp->id_free = p; - idp->id_free_cnt++; + __free_layer(idp, p); spin_unlock(&idp->lock); } @@ -184,12 +190,14 @@ static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id) * The allocation failed. If we built part of * the structure tear it down. */ + spin_lock(&idp->lock); for (new = p; p && p != idp->top; new = p) { p = p->ary[0]; new->ary[0] = NULL; new->bitmap = new->count = 0; - free_layer(idp, new); + __free_layer(idp, new); } + spin_unlock(&idp->lock); return -1; } new->ary[0] = p;