axmap: ensure that overlaps are handled strictly sequential
authorJens Axboe <axboe@kernel.dk>
Tue, 10 Jul 2018 22:52:16 +0000 (16:52 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 10 Jul 2018 22:52:16 +0000 (16:52 -0600)
We must terminate at the first overlapping bit, we can't
just mask off non-sequential ranges.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
lib/axmap.c

index 3c65308..c29597f 100644 (file)
@@ -234,17 +234,18 @@ static bool axmap_set_fn(struct axmap_level *al, unsigned long offset,
        if (overlap == mask)
                return true;
 
        if (overlap == mask)
                return true;
 
-       while (overlap) {
-               unsigned long clear_mask = ~(1UL << ffz(~overlap));
+       if (overlap) {
+               const int __bit = ffz(~overlap);
 
 
-               mask &= clear_mask;
-               overlap &= clear_mask;
-               nr_bits--;
+               if (__bit == bit)
+                       return true;
+
+               nr_bits = __bit - bit;
+               mask = bit_masks[nr_bits] << bit;
        }
 
        assert(mask);
        assert(!(al->map[offset] & mask));
        }
 
        assert(mask);
        assert(!(al->map[offset] & mask));
-               
        al->map[offset] |= mask;
 
        if (!al->level)
        al->map[offset] |= mask;
 
        if (!al->level)