[Skiboot-stable] [PATCH] npu2-opencapi: Fix integer promotion bug in LPC allocation

Andrew Donnellan ajd at linux.ibm.com
Thu Sep 26 22:55:46 AEST 2019


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 at d-silva.org>
Cc: skiboot-stable at lists.ozlabs.org
Signed-off-by: Andrew Donnellan <ajd at linux.ibm.com>
---

Alastair: please double check this fixes whatever issue you were seeing

---

 hw/npu2-opencapi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/npu2-opencapi.c b/hw/npu2-opencapi.c
index 9a391bb01461..a54ef63a86f8 100644
--- a/hw/npu2-opencapi.c
+++ b/hw/npu2-opencapi.c
@@ -2135,7 +2135,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);
-- 
2.20.1



More information about the Skiboot-stable mailing list