]> www.infradead.org Git - users/hch/misc.git/commitdiff
riscv: kprobes: Remove duplication of RVC_EXTRACT_BTYPE_IMM
authorNam Cao <namcao@linutronix.de>
Sun, 11 May 2025 21:18:00 +0000 (23:18 +0200)
committerPaul Walmsley <pjw@kernel.org>
Wed, 17 Sep 2025 00:46:44 +0000 (18:46 -0600)
Use RVC_EXTRACT_BTYPE_IMM, instead of reimplementing it in
simulate_c_bnez_beqz().

Signed-off-by: Nam Cao <namcao@linutronix.de>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/linux-riscv/8a8ed970f279fa5f24c90d840c2130e37bc6d16e.1747215274.git.namcao@linutronix.de/
Signed-off-by: Paul Walmsley <pjw@kernel.org>
arch/riscv/kernel/probes/simulate-insn.c

index f5d64613dab5a8c7c303e74142dbcad74c18924e..e670e55954d27fcf7c47fc711759406abc9fd603 100644 (file)
@@ -232,16 +232,10 @@ static bool __kprobes simulate_c_bnez_beqz(u32 opcode, unsigned long addr, struc
        if (!rv_insn_reg_get_val(regs, rs1, &rs1_val))
                return false;
 
-       if ((rs1_val != 0 && is_bnez) || (rs1_val == 0 && !is_bnez)) {
-               offset =  ((opcode >> 3)  & 0x3) << 1;
-               offset |= ((opcode >> 10) & 0x3) << 3;
-               offset |= ((opcode >> 2)  & 0x1) << 5;
-               offset |= ((opcode >> 5)  & 0x3) << 6;
-               offset |= ((opcode >> 12) & 0x1) << 8;
-               offset = sign_extend32(offset, 8);
-       } else {
+       if ((rs1_val != 0 && is_bnez) || (rs1_val == 0 && !is_bnez))
+               offset = RVC_EXTRACT_BTYPE_IMM(opcode);
+       else
                offset = 2;
-       }
 
        instruction_pointer_set(regs, addr + offset);