diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/idr.c | 9 |
1 files changed, 6 insertions, 3 deletions
| @@ -140,7 +140,8 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa) | |||
| 140 | id = *starting_id; | 140 | id = *starting_id; |
| 141 | restart: | 141 | restart: |
| 142 | p = idp->top; | 142 | p = idp->top; |
| 143 | l = p->layer; | 143 | l = idp->layers; |
| 144 | pa[l--] = NULL; | ||
| 144 | while (1) { | 145 | while (1) { |
| 145 | /* | 146 | /* |
| 146 | * We run around this while until we reach the leaf node... | 147 | * 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) | |||
| 154 | oid = id; | 155 | oid = id; |
| 155 | id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1; | 156 | id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1; |
| 156 | 157 | ||
| 157 | /* did id go over the limit? */ | 158 | /* if already at the top layer, we need to grow */ |
| 158 | if (id >= (1 << (idp->layers * IDR_BITS))) { | 159 | if (id >= 1 << (idp->layers * IDR_BITS)) { |
| 159 | *starting_id = id; | 160 | *starting_id = id; |
| 160 | return IDR_NEED_TO_GROW; | 161 | return IDR_NEED_TO_GROW; |
| 161 | } | 162 | } |
| 163 | p = pa[l]; | ||
| 164 | BUG_ON(!p); | ||
| 162 | 165 | ||
| 163 | /* If we need to go up one layer, continue the | 166 | /* If we need to go up one layer, continue the |
| 164 | * loop; otherwise, restart from the top. | 167 | * loop; otherwise, restart from the top. |
