Skip to content

Commit 5f1a58e

Browse files
BigBrotherJuAlexandre Ghiti
authored andcommitted
riscv: ftrace: Add parentheses in macro definitions of make_call_t0 and make_call_ra
This patch adds parentheses to parameters caller and callee of macros make_call_t0 and make_call_ra. Every existing invocation of these two macros uses a single variable for each argument, so the absence of the parentheses seems okay. However, future invocations might use more complex expressions as arguments. For example, a future invocation might look like this: make_call_t0(a - b, c, call). Without parentheses in the macro definition, the macro invocation expands to: ... unsigned int offset = (unsigned long) c - (unsigned long) a - b; ... which is clearly wrong. The use of parentheses ensures arguments are correctly evaluated and potentially saves future users of make_call_t0 and make_call_ra debugging trouble. Fixes: 6724a76 ("riscv: ftrace: Reduce the detour code size to half") Signed-off-by: Juhan Jin <juhan.jin@foxmail.com> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/tencent_AE90AA59903A628E87E9F80E563DA5BA5508@qq.com Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
1 parent 82e81b8 commit 5f1a58e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/riscv/include/asm/ftrace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct dyn_arch_ftrace {
9292
#define make_call_t0(caller, callee, call) \
9393
do { \
9494
unsigned int offset = \
95-
(unsigned long) callee - (unsigned long) caller; \
95+
(unsigned long) (callee) - (unsigned long) (caller); \
9696
call[0] = to_auipc_t0(offset); \
9797
call[1] = to_jalr_t0(offset); \
9898
} while (0)
@@ -108,7 +108,7 @@ do { \
108108
#define make_call_ra(caller, callee, call) \
109109
do { \
110110
unsigned int offset = \
111-
(unsigned long) callee - (unsigned long) caller; \
111+
(unsigned long) (callee) - (unsigned long) (caller); \
112112
call[0] = to_auipc_ra(offset); \
113113
call[1] = to_jalr_ra(offset); \
114114
} while (0)

0 commit comments

Comments
 (0)