Skip to content

Commit ddbb7ea

Browse files
masahir0yRussell King (Oracle)
authored andcommitted
ARM: 9299/1: module: use sign_extend32() to extend the signedness
The function name clarifies the intention. Signed-off-by: Masahiro Yamada <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent 5bb578a commit ddbb7ea

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

arch/arm/kernel/module.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
169169

170170
offset = __mem_to_opcode_arm(*(u32 *)loc);
171171
offset = (offset & 0x00ffffff) << 2;
172-
if (offset & 0x02000000)
173-
offset -= 0x04000000;
172+
offset = sign_extend32(offset, 25);
174173

175174
offset += sym->st_value - loc;
176175

@@ -236,7 +235,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
236235
case R_ARM_MOVT_PREL:
237236
offset = tmp = __mem_to_opcode_arm(*(u32 *)loc);
238237
offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff);
239-
offset = (offset ^ 0x8000) - 0x8000;
238+
offset = sign_extend32(offset, 15);
240239

241240
offset += sym->st_value;
242241
if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_PREL ||
@@ -344,8 +343,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
344343
((~(j2 ^ sign) & 1) << 22) |
345344
((upper & 0x03ff) << 12) |
346345
((lower & 0x07ff) << 1);
347-
if (offset & 0x01000000)
348-
offset -= 0x02000000;
346+
offset = sign_extend32(offset, 24);
349347
offset += sym->st_value - loc;
350348

351349
/*
@@ -401,7 +399,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
401399
offset = ((upper & 0x000f) << 12) |
402400
((upper & 0x0400) << 1) |
403401
((lower & 0x7000) >> 4) | (lower & 0x00ff);
404-
offset = (offset ^ 0x8000) - 0x8000;
402+
offset = sign_extend32(offset, 15);
405403
offset += sym->st_value;
406404

407405
if (ELF32_R_TYPE(rel->r_info) == R_ARM_THM_MOVT_PREL ||

0 commit comments

Comments
 (0)