pmem: Correctly account for aligned blocks
when finding an aligned chunk, the allocator cannot assume that
bit 0 will point to an aligned block. The only way to guarantee
a block will be aligned is to pass in the starting bit of a block
that is aligned. if t is the start bit which points to an aligned
block, and s is the spacing, bit t+n*s is guaranteed to be aligned
to spacing s for positive integer values of n.
CRs-Fixed: 288000
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
diff --git a/drivers/misc/pmem.c b/drivers/misc/pmem.c
index df36ad5..a9d1990 100644
--- a/drivers/misc/pmem.c
+++ b/drivers/misc/pmem.c
@@ -1118,17 +1118,17 @@
static int
bitmap_allocate_contiguous(uint32_t *bitp, int num_bits_to_alloc,
- int total_bits, int spacing)
+ int total_bits, int spacing, int start_bit)
{
int bit_start, last_bit, word_index;
if (num_bits_to_alloc <= 0)
return -1;
- for (bit_start = 0; ;
- bit_start = (last_bit +
+ for (bit_start = start_bit; ;
+ bit_start = ((last_bit +
(word_index << PMEM_32BIT_WORD_ORDER) + spacing - 1)
- & ~(spacing - 1)) {
+ & ~(spacing - 1)) + start_bit) {
int bit_end = bit_start + num_bits_to_alloc, total_words;
if (bit_end > total_bits)
@@ -1206,7 +1206,8 @@
ret = bitmap_allocate_contiguous(pmem[id].allocator.bitmap.bitmap,
quanta_needed,
(pmem[id].size + pmem[id].quantum - 1) / pmem[id].quantum,
- spacing);
+ spacing,
+ start_bit);
#if PMEM_DEBUG
if (ret < 0)