Linux-RISC-V Archive on lore.kernel.org
 help / color / Atom feed
From: Vincent Chen <vincent.chen@sifive.com>
To: linux-riscv@lists.infradead.org
Cc: vincent.chen@sifive.com, palmer@sifive.com,
	linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu,
	paul.walmsley@sifive.com
Subject: [PATCH 4/4] riscv: remove the switch statement in do_trap_break()
Date: Mon, 23 Sep 2019 08:45:17 +0800
Message-ID: <1569199517-5884-5-git-send-email-vincent.chen@sifive.com> (raw)
In-Reply-To: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com>

To make the code more straightforward, replacing the switch statement
with if statement.

Suggested-by: Paul Walmsley <paul.walmsley@sifive.com>
Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
---
 arch/riscv/kernel/traps.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index dd13bc90aeb6..1ac75f7d0bff 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -124,23 +124,24 @@ static inline unsigned long get_break_insn_length(unsigned long pc)
 
 asmlinkage void do_trap_break(struct pt_regs *regs)
 {
-	if (!user_mode(regs)) {
+	if (user_mode(regs)) {
+		force_sig_fault(SIGTRAP, TRAP_BRKPT,
+				(void __user *)(regs->sepc));
+		return;
+	}
+#ifdef CONFIG_GENERIC_BUG
+	{
 		enum bug_trap_type type;
 
 		type = report_bug(regs->sepc, regs);
-		switch (type) {
-#ifdef CONFIG_GENERIC_BUG
-		case BUG_TRAP_TYPE_WARN:
+		if (type == BUG_TRAP_TYPE_WARN) {
 			regs->sepc += get_break_insn_length(regs->sepc);
 			return;
-		case BUG_TRAP_TYPE_BUG:
-#endif /* CONFIG_GENERIC_BUG */
-		default:
-			die(regs, "Kernel BUG");
 		}
-	} else
-		force_sig_fault(SIGTRAP, TRAP_BRKPT,
-				(void __user *)(regs->sepc));
+	}
+#endif /* CONFIG_GENERIC_BUG */
+
+	die(regs, "Kernel BUG");
 }
 
 #ifdef CONFIG_GENERIC_BUG
-- 
2.7.4


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply index

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-23  0:45 [PATCH 0/4] riscv: correct the do_trap_break() Vincent Chen
2019-09-23  0:45 ` [PATCH 1/4] riscv: avoid kernel hangs when trapped in BUG() Vincent Chen
2019-09-27 22:25   ` Christoph Hellwig
2019-10-04 18:26   ` Paul Walmsley
2019-09-23  0:45 ` [PATCH 2/4] rsicv: avoid sending a SIGTRAP to a user thread trapped in WARN() Vincent Chen
2019-09-27 22:27   ` Christoph Hellwig
2019-09-27 22:56   ` Christoph Hellwig
2019-09-30  0:22     ` Vincent Chen
2019-10-04 18:26   ` Paul Walmsley
2019-09-23  0:45 ` [PATCH 3/4] riscv: Correct the handling of unexpected ebreak in do_trap_break() Vincent Chen
2019-09-27 22:43   ` Christoph Hellwig
2019-10-04 18:28   ` Paul Walmsley
2019-09-23  0:45 ` Vincent Chen [this message]
2019-09-27 22:47   ` [PATCH 4/4] riscv: remove the switch statement " Christoph Hellwig
2019-10-07 16:08     ` Paul Walmsley
2019-10-07 16:10       ` Christoph Hellwig
2019-10-07 16:30         ` Paul Walmsley
2019-10-08  0:14           ` Vincent Chen
2019-10-08 17:07             ` Paul Walmsley
2019-10-09 22:26         ` Paul Walmsley

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1569199517-5884-5-git-send-email-vincent.chen@sifive.com \
    --to=vincent.chen@sifive.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@sifive.com \
    --cc=paul.walmsley@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-RISC-V Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-riscv/0 linux-riscv/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-riscv linux-riscv/ https://lore.kernel.org/linux-riscv \
		linux-riscv@lists.infradead.org
	public-inbox-index linux-riscv

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-riscv


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git