aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/idr.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/idr.c b/lib/idr.c
index 2642fa8e424d..4df67928816e 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -249,7 +249,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa,
249 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1; 249 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
250 250
251 /* if already at the top layer, we need to grow */ 251 /* if already at the top layer, we need to grow */
252 if (id >= 1 << (idp->layers * IDR_BITS)) { 252 if (id > idr_max(idp->layers)) {
253 *starting_id = id; 253 *starting_id = id;
254 return -EAGAIN; 254 return -EAGAIN;
255 } 255 }
@@ -811,12 +811,10 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
811 if (!p) 811 if (!p)
812 return ERR_PTR(-EINVAL); 812 return ERR_PTR(-EINVAL);
813 813
814 n = (p->layer+1) * IDR_BITS; 814 if (id > idr_max(p->layer + 1))
815
816 if (id >= (1 << n))
817 return ERR_PTR(-EINVAL); 815 return ERR_PTR(-EINVAL);
818 816
819 n -= IDR_BITS; 817 n = p->layer * IDR_BITS;
820 while ((n > 0) && p) { 818 while ((n > 0) && p) {
821 p = p->ary[(id >> n) & IDR_MASK]; 819 p = p->ary[(id >> n) & IDR_MASK];
822 n -= IDR_BITS; 820 n -= IDR_BITS;