[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20221014015956.2006-3-thunder.leizhen@huawei.com>
Date: Fri, 14 Oct 2022 09:59:55 +0800
From: Zhen Lei <thunder.leizhen@...wei.com>
To: Russell King <linux@...linux.org.uk>,
Ard Biesheuvel <ardb@...nel.org>,
<linux-arm-kernel@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>
CC: Zhen Lei <thunder.leizhen@...wei.com>
Subject: [PATCH v3 2/3] ARM: Refactor dump_instr()
1. Rename local variable 'val16' to 'tmp'. So that the processing
statements of thumb and arm can be aligned.
2. Prepare for the next patch to avoid repeated judgment.
Before:
if (!user_mode(regs)) {
if (thumb)
else
} else {
if (thumb)
else
}
After:
if (thumb) {
if (user_mode(regs))
else
} else {
if (user_mode(regs))
else
}
Signed-off-by: Zhen Lei <thunder.leizhen@...wei.com>
---
arch/arm/kernel/traps.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index d455c97237e2079..182469a5b28a394 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -178,19 +178,20 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
for (i = -4; i < 1 + !!thumb; i++) {
unsigned int val, bad;
- if (!user_mode(regs)) {
- if (thumb) {
- u16 val16;
- bad = get_kernel_nofault(val16, &((u16 *)addr)[i]);
- val = val16;
- } else {
- bad = get_kernel_nofault(val, &((u32 *)addr)[i]);
- }
- } else {
- if (thumb)
- bad = get_user(val, &((u16 __user *)addr)[i]);
+ if (thumb) {
+ u16 tmp;
+
+ if (user_mode(regs))
+ bad = get_user(tmp, &((u16 __user *)addr)[i]);
else
+ bad = get_kernel_nofault(tmp, &((u16 *)addr)[i]);
+
+ val = tmp;
+ } else {
+ if (user_mode(regs))
bad = get_user(val, &((u32 __user *)addr)[i]);
+ else
+ bad = get_kernel_nofault(val, &((u32 *)addr)[i]);
}
if (!bad)
--
2.25.1
Powered by blists - more mailing lists