From 8cd5a2fdad69fcc7acc85863b69cc9ded97edceb Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 10 Jul 2018 16:52:16 -0600 Subject: [PATCH] axmap: ensure that overlaps are handled strictly sequential We must terminate at the first overlapping bit, we can't just mask off non-sequential ranges. Signed-off-by: Jens Axboe --- lib/axmap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/axmap.c b/lib/axmap.c index 3c65308c..c29597f8 100644 --- a/lib/axmap.c +++ b/lib/axmap.c @@ -234,17 +234,18 @@ static bool axmap_set_fn(struct axmap_level *al, unsigned long offset, 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)); - al->map[offset] |= mask; if (!al->level) -- 2.25.1