[PATCH 2/4] sbitmap: mask out top bits that can't be used

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If the tag depth isn't a multiple of the bits_per_word we selected,
we'll have dead bits at the top. Ensure that they are set. This
doesn't matter for the bit finding as we limit it to the depth of
the individual map, but it'll matter for when we try and grab
batches of tags off one map.

Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
 lib/sbitmap.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index c13a9623e9b5..a6c6c104b063 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -46,7 +46,13 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
 		return -ENOMEM;
 
 	for (i = 0; i < sb->map_nr; i++) {
-		sb->map[i].depth = min(depth, bits_per_word);
+		if (depth >= bits_per_word) {
+			sb->map[i].depth = bits_per_word;
+		} else {
+			sb->map[i].depth = depth;
+			/* mask off top unused bits, can never get allocated */
+			sb->map[i].word = ~((1UL << depth) - 1);
+		}
 		depth -= sb->map[i].depth;
 	}
 	return 0;
-- 
2.24.1




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux