diff mbox series

npu2-opencapi: Fix integer promotion bug in LPC allocation

Message ID 20190926125545.21745-1-ajd@linux.ibm.com
State Accepted
Headers show
Series npu2-opencapi: Fix integer promotion bug in LPC allocation | expand

Commit Message

Andrew Donnellan Sept. 26, 2019, 12:55 p.m. UTC
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>
---

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

---

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

Comments

Oliver O'Halloran Nov. 8, 2019, 5:07 a.m. UTC | #1
On Thu, Sep 26, 2019 at 10:57 PM Andrew Donnellan <ajd@linux.ibm.com> wrote:
>
> 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>

Merged as of e85e2e2b8b0a4dd96e10343df19df1a161cd6aac
Vasant Hegde Dec. 9, 2019, 8:19 a.m. UTC | #2
On 9/26/19 6:25 PM, Andrew Donnellan wrote:
> 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


skiboot v6.5.2 stable release contains this fix.


-Vasant
diff mbox series

Patch

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);