From c3bfa3f6a9f5e7bc8acf5aa7f5ac4501fefda77b Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Thu, 26 Jul 2018 16:01:09 +0900 Subject: [PATCH] move BUG_ON, panic and kprintf define to debug.h; add BUILD_BUG_ON these functions are more logical to keep together there as they depend on each other. Also add a comment about the __printf attribute, if we have a quiet period it would be useful to enable and clear the thousands of warnings... Change-Id: I47d3891c9cd87da28b2883c29384959f5abd1459 --- arch/arm64/kernel/cpu.c | 3 --- arch/arm64/kernel/fpsimd.c | 3 --- arch/arm64/kernel/ptrace.c | 3 --- arch/arm64/kernel/syscall.c | 3 --- kernel/include/debug.h | 16 +++++++++++++++- kernel/include/kmalloc.h | 8 +++----- lib/bitmap.c | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/arch/arm64/kernel/cpu.c b/arch/arm64/kernel/cpu.c index 644b24aa..27fd920e 100644 --- a/arch/arm64/kernel/cpu.c +++ b/arch/arm64/kernel/cpu.c @@ -44,9 +44,6 @@ #define DDEBUG_DEFAULT DDEBUG_PRINT #endif -#define BUG_ON(condition) do { if (condition) { kprintf("PANIC: %s: %s(line:%d)\n",\ - __FILE__, __FUNCTION__, __LINE__); panic(""); } } while(0) - struct cpuinfo_arm64 cpuinfo_data[NR_CPUS]; /* index is logical cpuid */ static unsigned int per_cpu_timer_val[NR_CPUS] = { 0 }; diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 04b6a13e..2e7bfe0f 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -19,9 +19,6 @@ #define DDEBUG_DEFAULT DDEBUG_PRINT #endif -#define BUG_ON(condition) do { if (condition) { kprintf("PANIC: %s: %s(line:%d)\n",\ - __FILE__, __FUNCTION__, __LINE__); panic(""); } } while(0) - #ifdef CONFIG_ARM64_SVE /* Maximum supported vector length across all CPUs (initially poisoned) */ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 84b91dd1..da3652af 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -22,9 +22,6 @@ #define NOT_IMPLEMENTED() do { kprintf("%s is not implemented\n", __func__); while(1);} while(0) -#define BUG_ON(condition) do { if (condition) { kprintf("PANIC: %s: %s(line:%d)\n",\ - __FILE__, __FUNCTION__, __LINE__); panic(""); } } while(0) - extern void save_debugreg(unsigned long *debugreg); extern unsigned long do_kill(struct thread *thread, int pid, int tid, int sig, struct siginfo *info, int ptracecont); extern int interrupt_from_user(void *); diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index d2a309c0..453b0c72 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -35,9 +35,6 @@ static void __check_signal(unsigned long rc, void *regs, int num, int irq_disabl #define NOT_IMPLEMENTED() do { kprintf("%s is not implemented\n", __func__); while(1);} while(0) -#define BUG_ON(condition) do { if (condition) { kprintf("PANIC: %s: %s(line:%d)\n",\ - __FILE__, __FUNCTION__, __LINE__); panic(""); } } while(0) - uintptr_t debug_constants[] = { sizeof(struct cpu_local_var), offsetof(struct cpu_local_var, current), diff --git a/kernel/include/debug.h b/kernel/include/debug.h index 4a512942..6c471ab9 100644 --- a/kernel/include/debug.h +++ b/kernel/include/debug.h @@ -1,7 +1,12 @@ #ifndef DEBUG_H #define DEBUG_H -#include +#include "lwk/compiler.h" + +void panic(const char *); + +/* when someone has a lot of time, add attribute __printf(1, 2) to kprintf */ +int kprintf(const char *format, ...); struct ddebug { const char *file; @@ -37,4 +42,13 @@ do { \ } while (0) #define ekprintf(fmt, args...) kprintf(fmt, ##args) +#define BUG_ON(condition) do { \ + if (condition) { \ + kprintf("PANIC: %s: %s(line:%d)\n", \ + __FILE__, __func__, __LINE__); \ + panic(""); \ + } \ +} while (0) +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) + #endif diff --git a/kernel/include/kmalloc.h b/kernel/include/kmalloc.h index d48704e1..384d87fe 100644 --- a/kernel/include/kmalloc.h +++ b/kernel/include/kmalloc.h @@ -13,11 +13,9 @@ #ifndef __HEADER_KMALLOC_H #define __HEADER_KMALLOC_H -#include -#include - -void panic(const char *); -int kprintf(const char *format, ...); +#include "ihk/mm.h" +#include "cls.h" +#include "debug.h" #define kmalloc(size, flag) ({\ void *r = _kmalloc(size, flag, __FILE__, __LINE__);\ diff --git a/lib/bitmap.c b/lib/bitmap.c index 2eb47142..f059e771 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -11,9 +11,9 @@ #include #include #include +#include #define EXPORT_SYMBOL(x) -#define BUG_ON(x) /** * hex_to_bin - convert a hex digit to its real value