Skip to content

Commit

Permalink
npu2-opencapi: Fix integer promotion bug in LPC allocation
Browse files Browse the repository at this point in the history
If you try to allocate an amount of LPC memory that's not a power of 2,
we round the value up to the nearest power of 2.

By the magic of C, "1 << n" gets treated as an int, even if you're
assigning it to a uint64_t.

Change 1 to 1ULL to fix this.

(C, it's great.)

Reported-by: Alastair D'Silva <alistair@d-silva.org>
Cc: skiboot-stable@lists.ozlabs.org
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
ajdlinux authored and oohal committed Nov 5, 2019
1 parent ad8cdd0 commit e85e2e2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion hw/npu2-opencapi.c
Expand Up @@ -2219,7 +2219,7 @@ static int64_t alloc_mem_bar(struct npu2_dev *dev, uint64_t size, uint64_t *bar)
}

if (!is_pow2(size)) {
size = 1 << (ilog2(size) + 1);
size = 1ull << (ilog2(size) + 1);
}

set_mem_bar(dev, phys_map_base, size);
Expand Down

0 comments on commit e85e2e2

Please sign in to comment.