diff mbox series

[v1,20/22] powerpc/modules: Use PPC_INST_BRANCH_MASK instead of opencoding

Message ID a301c94f63888165960e21e92a0584364beb09fb.1648131740.git.christophe.leroy@csgroup.eu (mailing list archive)
State Superseded
Headers show
Series powerpc: ftrace optimisation and cleanup and more [v1] | expand

Commit Message

Christophe Leroy March 24, 2022, 2:30 p.m. UTC
Use PPC_INST_BRANCH_MASK instead of opencoding.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/kernel/module_32.c | 13 ++++++-------
 arch/powerpc/kernel/module_64.c |  4 ++--
 2 files changed, 8 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
index 1282cfd672f2..344941855e9e 100644
--- a/arch/powerpc/kernel/module_32.c
+++ b/arch/powerpc/kernel/module_32.c
@@ -256,9 +256,8 @@  int apply_relocate_add(Elf32_Shdr *sechdrs,
 			       value, (uint32_t)location);
 			pr_debug("Location before: %08X.\n",
 			       *(uint32_t *)location);
-			value = (*(uint32_t *)location & ~0x03fffffc)
-				| ((value - (uint32_t)location)
-				   & 0x03fffffc);
+			value = (*(uint32_t *)location & ~PPC_INST_OFFSET24_MASK) |
+				((value - (uint32_t)location) & PPC_INST_OFFSET24_MASK);
 
 			if (patch_instruction(location, ppc_inst(value)))
 				return -EFAULT;
@@ -266,10 +265,10 @@  int apply_relocate_add(Elf32_Shdr *sechdrs,
 			pr_debug("Location after: %08X.\n",
 			       *(uint32_t *)location);
 			pr_debug("ie. jump to %08X+%08X = %08X\n",
-			       *(uint32_t *)location & 0x03fffffc,
-			       (uint32_t)location,
-			       (*(uint32_t *)location & 0x03fffffc)
-			       + (uint32_t)location);
+				 *(uint32_t *)location & PPC_INST_OFFSET24_MASK,
+				 (uint32_t)location,
+				 (*(uint32_t *)location & PPC_INST_OFFSET24_MASK) +
+				 (uint32_t)location);
 			break;
 
 		case R_PPC_REL32:
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index b13a72665eee..8f70a04aac6c 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -653,8 +653,8 @@  int apply_relocate_add(Elf64_Shdr *sechdrs,
 			}
 
 			/* Only replace bits 2 through 26 */
-			value = (*(uint32_t *)location & ~0x03fffffc)
-				| (value & 0x03fffffc);
+			value = (*(uint32_t *)location & ~PPC_INST_OFFSET24_MASK) |
+				(value & PPC_INST_OFFSET24_MASK);
 
 			if (patch_instruction((u32 *)location, ppc_inst(value)))
 				return -EFAULT;