Skip to content

Commit 095704d

Browse files
Ben Collinsgregkh
authored andcommitted
powerpc/addnote: Fix overflow on 32-bit builds
[ Upstream commit 825ce89 ] 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> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/2025042122-mustard-wrasse-694572@boujee-and-buff Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d45fcd3 commit 095704d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

arch/powerpc/boot/addnote.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static int e_class = ELFCLASS32;
6868
#define PUT_16BE(off, v)(buf[off] = ((v) >> 8) & 0xff, \
6969
buf[(off) + 1] = (v) & 0xff)
7070
#define PUT_32BE(off, v)(PUT_16BE((off), (v) >> 16L), PUT_16BE((off) + 2, (v)))
71-
#define PUT_64BE(off, v)((PUT_32BE((off), (v) >> 32L), \
72-
PUT_32BE((off) + 4, (v))))
71+
#define PUT_64BE(off, v)((PUT_32BE((off), (unsigned long long)(v) >> 32L), \
72+
PUT_32BE((off) + 4, (unsigned long long)(v))))
7373

7474
#define GET_16LE(off) ((buf[off]) + (buf[(off)+1] << 8))
7575
#define GET_32LE(off) (GET_16LE(off) + (GET_16LE((off)+2U) << 16U))
@@ -78,7 +78,8 @@ static int e_class = ELFCLASS32;
7878
#define PUT_16LE(off, v) (buf[off] = (v) & 0xff, \
7979
buf[(off) + 1] = ((v) >> 8) & 0xff)
8080
#define PUT_32LE(off, v) (PUT_16LE((off), (v)), PUT_16LE((off) + 2, (v) >> 16L))
81-
#define PUT_64LE(off, v) (PUT_32LE((off), (v)), PUT_32LE((off) + 4, (v) >> 32L))
81+
#define PUT_64LE(off, v) (PUT_32LE((off), (unsigned long long)(v)), \
82+
PUT_32LE((off) + 4, (unsigned long long)(v) >> 32L))
8283

8384
#define GET_16(off) (e_data == ELFDATA2MSB ? GET_16BE(off) : GET_16LE(off))
8485
#define GET_32(off) (e_data == ELFDATA2MSB ? GET_32BE(off) : GET_32LE(off))

0 commit comments

Comments
 (0)