[PATCH 4/9] panic: use panic_try_start() in nmi_panic()
From: Jinchao Wang
Date: Wed Aug 20 2025 - 05:27:18 EST
nmi_panic() duplicated the logic to claim
panic_cpu with atomic_try_cmpxchg. This is
already wrapped in panic_try_start().
Replace the open-coded logic with
panic_try_start(), and use
panic_on_other_cpu() for the fallback path.
This removes duplication and keeps panic
handling code consistent.
Signed-off-by: Jinchao Wang <wangjinchao600@xxxxxxxxx>
---
kernel/panic.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/kernel/panic.c b/kernel/panic.c
index eacb0c972110..cd86d37d124c 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -355,15 +355,9 @@ EXPORT_SYMBOL(panic_on_other_cpu);
*/
void nmi_panic(struct pt_regs *regs, const char *msg)
{
- int old_cpu, this_cpu;
-
- old_cpu = PANIC_CPU_INVALID;
- this_cpu = raw_smp_processor_id();
-
- /* atomic_try_cmpxchg updates old_cpu on failure */
- if (atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu))
+ if (panic_try_start())
panic("%s", msg);
- else if (old_cpu != this_cpu)
+ else if (panic_on_other_cpu())
nmi_panic_self_stop(regs);
}
EXPORT_SYMBOL(nmi_panic);
--
2.43.0