From 7fce5e2db1461254c4985b8fc841adeb1c2516ed Mon Sep 17 00:00:00 2001 From: Manfred Spraul Date: Mon, 1 Dec 2008 13:14:02 -0800 Subject: [PATCH] --- yaml --- r: 119534 b: refs/heads/master c: 6ff2d39b91aec3dcae951afa982059e3dd9b49dc h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/include/linux/idr.h | 3 ++- trunk/lib/idr.c | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/[refs] b/[refs] index 9c6490788393..11f6cbca537a 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 1d678f365dae28420fa7329a2a35390b3582678d +refs/heads/master: 6ff2d39b91aec3dcae951afa982059e3dd9b49dc diff --git a/trunk/include/linux/idr.h b/trunk/include/linux/idr.h index fa035f96f2a3..dd846df8cd32 100644 --- a/trunk/include/linux/idr.h +++ b/trunk/include/linux/idr.h @@ -52,13 +52,14 @@ struct idr_layer { unsigned long bitmap; /* A zero bit means "space here" */ struct idr_layer *ary[1<layer = l-1; rcu_assign_pointer(p->ary[m], new); p->count++; } @@ -210,6 +211,7 @@ static int idr_get_empty_slot(struct idr *idp, int starting_id, if (unlikely(!p)) { if (!(p = get_from_free_list(idp))) return -1; + p->layer = 0; layers = 1; } /* @@ -237,6 +239,7 @@ static int idr_get_empty_slot(struct idr *idp, int starting_id, } new->ary[0] = p; new->count = 1; + new->layer = layers-1; if (p->bitmap == IDR_FULL) __set_bit(0, &new->bitmap); p = new; @@ -493,17 +496,21 @@ void *idr_find(struct idr *idp, int id) int n; struct idr_layer *p; - n = idp->layers * IDR_BITS; p = rcu_dereference(idp->top); + if (!p) + return NULL; + n = (p->layer+1) * IDR_BITS; /* Mask off upper bits we don't use for the search. */ id &= MAX_ID_MASK; if (id >= (1 << n)) return NULL; + BUG_ON(n == 0); while (n > 0 && p) { n -= IDR_BITS; + BUG_ON(n != p->layer*IDR_BITS); p = rcu_dereference(p->ary[(id >> n) & IDR_MASK]); } return((void *)p); @@ -582,8 +589,11 @@ void *idr_replace(struct idr *idp, void *ptr, int id) int n; struct idr_layer *p, *old_p; - n = idp->layers * IDR_BITS; p = idp->top; + if (!p) + return ERR_PTR(-EINVAL); + + n = (p->layer+1) * IDR_BITS; id &= MAX_ID_MASK;