From bd71edcedc3dcbce4fe32357523434d8f249b02d Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 11 Jul 2018 15:16:58 -0600 Subject: [PATCH] axmap: fix continued sequential bit setting We need to remember to clear ->set_bits if we don't set new bits, or the caller will think we re-set the previously set bits. Signed-off-by: Jens Axboe --- lib/axmap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/axmap.c b/lib/axmap.c index e4e40bf0..4047f236 100644 --- a/lib/axmap.c +++ b/lib/axmap.c @@ -227,15 +227,18 @@ static bool axmap_set_fn(struct axmap_level *al, unsigned long offset, * Mask off any potential overlap, only sets contig regions */ overlap = al->map[offset] & mask; - if (overlap == mask) + if (overlap == mask) { +done: + data->set_bits = 0; return true; + } if (overlap) { const int __bit = ffz(~overlap); nr_bits = __bit - bit; if (!nr_bits) - return true; + goto done; mask = bit_masks[nr_bits] << bit; } @@ -300,7 +303,7 @@ unsigned int axmap_set_nr(struct axmap *axmap, uint64_t bit_nr, unsigned int max_bits, this_set; max_bits = BLOCKS_PER_UNIT - (bit_nr & BLOCKS_PER_UNIT_MASK); - if (max_bits < nr_bits) + if (nr_bits > max_bits) data.nr_bits = max_bits; this_set = data.nr_bits; -- 2.25.1