Skip to content

Commit 2f01b78

Browse files
VincentZWCpaul-walmsley-sifive
authored andcommitted
riscv: remove the switch statement in do_trap_break()
To make the code more straightforward, replace the switch statement with an if statement. Suggested-by: Paul Walmsley <[email protected]> Signed-off-by: Vincent Chen <[email protected]> [[email protected]: cleaned up patch description; updated to apply] Link: https://lore.kernel.org/linux-riscv/[email protected]/ Link: https://lore.kernel.org/linux-riscv/CABvJ_xiHJSB7P5QekuLRP=LBPzXXghAfuUpPUYb=a_HbnOQ6BA@mail.gmail.com/ Link: https://lists.01.org/hyperkitty/list/[email protected]/thread/VDCU2WOB6KQISREO4V5DTXEI2M7VOV55/ Cc: Christoph Hellwig <[email protected]> Signed-off-by: Paul Walmsley <[email protected]>
1 parent 4f5cafb commit 2f01b78

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

arch/riscv/kernel/traps.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,24 @@ static inline unsigned long get_break_insn_length(unsigned long pc)
124124

125125
asmlinkage void do_trap_break(struct pt_regs *regs)
126126
{
127-
if (!user_mode(regs)) {
127+
if (user_mode(regs)) {
128+
force_sig_fault(SIGTRAP, TRAP_BRKPT,
129+
(void __user *)(regs->sepc));
130+
return;
131+
}
132+
#ifdef CONFIG_GENERIC_BUG
133+
{
128134
enum bug_trap_type type;
129135

130136
type = report_bug(regs->sepc, regs);
131-
switch (type) {
132-
#ifdef CONFIG_GENERIC_BUG
133-
case BUG_TRAP_TYPE_WARN:
137+
if (type == BUG_TRAP_TYPE_WARN) {
134138
regs->sepc += get_break_insn_length(regs->sepc);
135139
return;
136-
case BUG_TRAP_TYPE_BUG:
137-
#endif /* CONFIG_GENERIC_BUG */
138-
default:
139-
die(regs, "Kernel BUG");
140140
}
141-
} else {
142-
force_sig_fault(SIGTRAP, TRAP_BRKPT,
143-
(void __user *)(regs->sepc));
144141
}
142+
#endif /* CONFIG_GENERIC_BUG */
143+
144+
die(regs, "Kernel BUG");
145145
}
146146

147147
#ifdef CONFIG_GENERIC_BUG

0 commit comments

Comments
 (0)