arch/powerpc/boot/addnote.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
The PUT_64[LB]E() macros need to cast the value to unsigned long long
like the GET_64[LB]E() macros. Caused lots of warnings when compiled
on 32-bit, and clobbered addresses (36-bit P4080).
Signed-off-by: Ben Collins <bcollins@kernel.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
---
arch/powerpc/boot/addnote.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/boot/addnote.c b/arch/powerpc/boot/addnote.c
index 53b3b2621457d..78704927453aa 100644
--- a/arch/powerpc/boot/addnote.c
+++ b/arch/powerpc/boot/addnote.c
@@ -68,8 +68,8 @@ static int e_class = ELFCLASS32;
#define PUT_16BE(off, v)(buf[off] = ((v) >> 8) & 0xff, \
buf[(off) + 1] = (v) & 0xff)
#define PUT_32BE(off, v)(PUT_16BE((off), (v) >> 16L), PUT_16BE((off) + 2, (v)))
-#define PUT_64BE(off, v)((PUT_32BE((off), (v) >> 32L), \
- PUT_32BE((off) + 4, (v))))
+#define PUT_64BE(off, v)((PUT_32BE((off), (unsigned long long)(v) >> 32L), \
+ PUT_32BE((off) + 4, (unsigned long long)(v))))
#define GET_16LE(off) ((buf[off]) + (buf[(off)+1] << 8))
#define GET_32LE(off) (GET_16LE(off) + (GET_16LE((off)+2U) << 16U))
@@ -78,7 +78,8 @@ static int e_class = ELFCLASS32;
#define PUT_16LE(off, v) (buf[off] = (v) & 0xff, \
buf[(off) + 1] = ((v) >> 8) & 0xff)
#define PUT_32LE(off, v) (PUT_16LE((off), (v)), PUT_16LE((off) + 2, (v) >> 16L))
-#define PUT_64LE(off, v) (PUT_32LE((off), (v)), PUT_32LE((off) + 4, (v) >> 32L))
+#define PUT_64LE(off, v) (PUT_32LE((off), (unsigned long long)(v)), \
+ PUT_32LE((off) + 4, (unsigned long long)(v) >> 32L))
#define GET_16(off) (e_data == ELFDATA2MSB ? GET_16BE(off) : GET_16LE(off))
#define GET_32(off) (e_data == ELFDATA2MSB ? GET_32BE(off) : GET_32LE(off))
--
2.49.0
--
Ben Collins
https://libjwt.io
https://github.com/benmcollins
--
3EC9 7598 1672 961A 1139 173A 5D5A 57C7 242B 22CF
On Mon, 21 Apr 2025 22:31:13 -0400, Ben Collins wrote:
> The PUT_64[LB]E() macros need to cast the value to unsigned long long
> like the GET_64[LB]E() macros. Caused lots of warnings when compiled
> on 32-bit, and clobbered addresses (36-bit P4080).
>
>
Applied to powerpc/next.
[1/1] powerpc/addnote: Fix overflow on 32-bit builds
https://git.kernel.org/powerpc/c/825ce89a3ef17f84cf2c0eacfa6b8dc9fd11d13f
Thanks
Le 22/04/2025 à 04:31, Ben Collins a écrit : > The PUT_64[LB]E() macros need to cast the value to unsigned long long > like the GET_64[LB]E() macros. Caused lots of warnings when compiled > on 32-bit, and clobbered addresses (36-bit P4080). > > Signed-off-by: Ben Collins <bcollins@kernel.org> > Cc: Madhavan Srinivasan <maddy@linux.ibm.com> > Cc: Michael Ellerman <mpe@ellerman.id.au> > Cc: linuxppc-dev@lists.ozlabs.org Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> > --- > arch/powerpc/boot/addnote.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/arch/powerpc/boot/addnote.c b/arch/powerpc/boot/addnote.c > index 53b3b2621457d..78704927453aa 100644 > --- a/arch/powerpc/boot/addnote.c > +++ b/arch/powerpc/boot/addnote.c > @@ -68,8 +68,8 @@ static int e_class = ELFCLASS32; > #define PUT_16BE(off, v)(buf[off] = ((v) >> 8) & 0xff, \ > buf[(off) + 1] = (v) & 0xff) > #define PUT_32BE(off, v)(PUT_16BE((off), (v) >> 16L), PUT_16BE((off) + 2, (v))) > -#define PUT_64BE(off, v)((PUT_32BE((off), (v) >> 32L), \ > - PUT_32BE((off) + 4, (v)))) > +#define PUT_64BE(off, v)((PUT_32BE((off), (unsigned long long)(v) >> 32L), \ > + PUT_32BE((off) + 4, (unsigned long long)(v)))) > > #define GET_16LE(off) ((buf[off]) + (buf[(off)+1] << 8)) > #define GET_32LE(off) (GET_16LE(off) + (GET_16LE((off)+2U) << 16U)) > @@ -78,7 +78,8 @@ static int e_class = ELFCLASS32; > #define PUT_16LE(off, v) (buf[off] = (v) & 0xff, \ > buf[(off) + 1] = ((v) >> 8) & 0xff) > #define PUT_32LE(off, v) (PUT_16LE((off), (v)), PUT_16LE((off) + 2, (v) >> 16L)) > -#define PUT_64LE(off, v) (PUT_32LE((off), (v)), PUT_32LE((off) + 4, (v) >> 32L)) > +#define PUT_64LE(off, v) (PUT_32LE((off), (unsigned long long)(v)), \ > + PUT_32LE((off) + 4, (unsigned long long)(v) >> 32L)) > > #define GET_16(off) (e_data == ELFDATA2MSB ? GET_16BE(off) : GET_16LE(off)) > #define GET_32(off) (e_data == ELFDATA2MSB ? GET_32BE(off) : GET_32LE(off))
© 2016 - 2025 Red Hat, Inc.