topology: convert cpu notifier to return encapsulate errno value
[safe/jmp/linux-2.6] / lib / idr.c
index ba7d37c..422a9d5 100644 (file)
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -140,7 +140,8 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
        id = *starting_id;
  restart:
        p = idp->top;
-       l = p->layer;
+       l = idp->layers;
+       pa[l--] = NULL;
        while (1) {
                /*
                 * We run around this while until we reach the leaf node...
@@ -154,11 +155,13 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
                        oid = id;
                        id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
 
-                       /* did id go over the limit? */
-                       if (id >= (1 << (idp->layers * IDR_BITS))) {
+                       /* if already at the top layer, we need to grow */
+                       if (id >= 1 << (idp->layers * IDR_BITS)) {
                                *starting_id = id;
                                return IDR_NEED_TO_GROW;
                        }
+                       p = pa[l];
+                       BUG_ON(!p);
 
                        /* If we need to go up one layer, continue the
                         * loop; otherwise, restart from the top.
@@ -501,7 +504,7 @@ void *idr_find(struct idr *idp, int id)
        int n;
        struct idr_layer *p;
 
-       p = rcu_dereference(idp->top);
+       p = rcu_dereference_raw(idp->top);
        if (!p)
                return NULL;
        n = (p->layer+1) * IDR_BITS;
@@ -516,7 +519,7 @@ void *idr_find(struct idr *idp, int id)
        while (n > 0 && p) {
                n -= IDR_BITS;
                BUG_ON(n != p->layer*IDR_BITS);
-               p = rcu_dereference(p->ary[(id >> n) & IDR_MASK]);
+               p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]);
        }
        return((void *)p);
 }
@@ -549,7 +552,7 @@ int idr_for_each(struct idr *idp,
        struct idr_layer **paa = &pa[0];
 
        n = idp->layers * IDR_BITS;
-       p = rcu_dereference(idp->top);
+       p = rcu_dereference_raw(idp->top);
        max = 1 << n;
 
        id = 0;
@@ -557,7 +560,7 @@ int idr_for_each(struct idr *idp,
                while (n > 0 && p) {
                        n -= IDR_BITS;
                        *paa++ = p;
-                       p = rcu_dereference(p->ary[(id >> n) & IDR_MASK]);
+                       p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]);
                }
 
                if (p) {
@@ -620,7 +623,7 @@ void *idr_get_next(struct idr *idp, int *nextidp)
        }
        return NULL;
 }
-
+EXPORT_SYMBOL(idr_get_next);
 
 
 /**