kernel.h printk/panic/string cleanup
Subsystems (2)
PATCH 2/6 kernel.h printk/panic/string cleanup
Cleanup kernel.h extern declarations, move printk/panic/string stuff to their own head files. But due to lots of files need them, include them in kernel.h for convinience. At least it can be thought as the first step to do the full cleanup.
Signed-off-by Dave Young <[email protected]>
--- include/linux/kernel.h | 438 ------------------------------------------------- include/linux/panic.h | 35 +++ include/linux/printk.h | 220 ++++++++++++++++++++++++ include/linux/string.h | 30 +++ 4 files changed, 288 insertions(+), 435 deletions(-)
include/linux/printk.h new file +220 -0
@@ -0,0 +1,220 @@ +#ifndef _PRINTK_H +#define _PRINTK_H + +#include <stdarg.h> +#include <linux/linkage.h> +#include <linux/types.h> +#include <linux/dynamic_debug.h> +#define KERN_EMERG "<0>"/* system is unusable */ +#define KERN_ALERT "<1>"/* action must be taken immediately */ +#define KERN_CRIT "<2>"/* critical conditions */ +#define KERN_ERR "<3>"/* error conditions */ +#define KERN_WARNING "<4>"/* warning conditions */ +#define KERN_NOTICE "<5>"/* normal but significant condition */ +#define KERN_INFO "<6>"/* informational */ +#define KERN_DEBUG "<7>"/* debug-level messages */ + +/* Use the default kernel loglevel */ +#define KERN_DEFAULT "<d>" +/* +* Annotation for a "continued" line of log printout (only done after a +* line that had no enclosing \n). Only to be used by core/arch code +* during early bootup (a continued line is not SMP-safe otherwise). +*/ +#define KERN_CONT "<c>" + +/* +* FW_BUG +* Add this to a message where you are sure the firmware is buggy or behaves +* really stupid or out of spec. Be aware that the responsible BIOS developer +* should be able to fix this issue or at least get a concrete idea of the +* problem by reading your message without the need of looking at the kernel +* code. +* +* Use it for definite and high priority BIOS bugs. +* +* FW_WARN +* Use it for not that clear (e.g. could the kernel messed up things already?) +* and medium priority BIOS bugs. +* +* FW_INFO +* Use this one if you want to tell the user or vendor about something +* suspicious, but generally harmless related to the firmware. +* +* Use it for information or very low priority BIOS bugs. +*/ +#define FW_BUG "[Firmware Bug]: " +#define FW_WARN "[Firmware Warn]: " +#define FW_INFO "[Firmware Info]: " + +extern int console_printk[]; + +#define console_loglevel (console_printk[0]) +#define default_message_loglevel (console_printk[1]) +#define minimum_console_loglevel (console_printk[2]) +#define default_console_loglevel (console_printk[3]) + +#ifdef CONFIG_PRINTK +asmlinkage int vprintk(const char *fmt, va_list args) + __attribute__ ((format (printf,1 ,0 ))); +asmlinkage int printk(const char * fmt, ...) + __attribute__ ((format (printf,1 ,2 )))__cold ; + +extern int __printk_ratelimit (const char *func); +#define printk_ratelimit () __printk_ratelimit(__func__) +extern bool printk_timed_ratelimit (unsigned long *caller_jiffies, +unsigned int interval_msec); + +extern int printk_delay_msec; + +/* +* Print a one-time message (analogous to WARN_ONCE() et al): +*/ +#define printk_once(x...) ({ \ + static bool __print_once; \ + \ + if (!__print_once) { \ + __print_once = true; \ + printk(x); \ + } \ +}) + +void log_buf_kexec_setup (void ); +#else +static inline int vprintk (const char *s,va_list args) + __attribute__ ((format (printf,1 ,0 ))); +static inline int vprintk (const char *s,va_list args) {return 0 ; } +static inline int printk (const char *s, ...) + __attribute__ ((format (printf,1 ,2 ))); +static inline int __cold printk (const char *s, ...) {return 0 ; } +static inline int printk_ratelimit (void ) {return 0 ; } +static inline bool printk_timed_ratelimit (unsigned long *caller_jiffies, \ +unsigned int interval_msec) \ + {return false; } + +/* No effect, but we still get type checking even in the !PRINTK case: */ +#define printk_once(x...) printk(x) + +static inline void log_buf_kexec_setup (void ) +{ +} +#endif + +extern int printk_needs_cpu (int cpu); +extern void printk_tick (void ); + +extern void asmlinkage __attribute__((format(printf, 1, 2))) + early_printk(const char *fmt, ...); + +static inline void console_silent (void ) +{ + console_loglevel =0 ; +} + +static inline void console_verbose (void ) +{ +if (console_loglevel) + console_loglevel =15 ; +} + +#ifndef pr_fmt +#define pr_fmt (fmt) fmt +#endif + +#define pr_emerg (fmt, ...) \ + printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) +#define pr_alert (fmt, ...) \ + printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_crit (fmt, ...) \ + printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_err (fmt, ...) \ + printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) +#define pr_warning (fmt, ...) \ + printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) +#define pr_notice (fmt, ...) \ + printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info (fmt, ...) \ + printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) +#define pr_cont (fmt, ...) \ + printk(KERN_CONT fmt, ##__VA_ARGS__) + +/* pr_devel() should produce zero code unless DEBUG is defined */ +#ifdef DEBUG +#define pr_devel (fmt, ...) \ + printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) +#else +#define pr_devel (fmt, ...) \ + ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) +#endif + +/* If you are writing a driver, please use dev_dbg instead */ +#if defined(DEBUG ) +#define pr_debug (fmt, ...) \ + printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) +#elif defined(CONFIG_DYNAMIC_DEBUG ) +/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ +#define pr_debug (fmt, ...) \ + dynamic_pr_debug(fmt, ##__VA_ARGS__) +#else +#define pr_debug (fmt, ...) \ + ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) +#endif + +/* +* ratelimited messages with local ratelimit_state, +* no local ratelimit_state used in the !PRINTK case +*/ +#ifdef CONFIG_PRINTK +#define printk_ratelimited (fmt, ...) ({ \ + static struct ratelimit_state _rs = { \ + .interval = DEFAULT_RATELIMIT_INTERVAL, \ + .burst = DEFAULT_RATELIMIT_BURST, \ + }; \ + \ + if (!__ratelimit(&_rs)) \ + printk(fmt, ##__VA_ARGS__); \ +}) +#else +/* No effect, but we still get type checking even in the !PRINTK case: */ +#define printk_ratelimited printk +#endif + +#define pr_emerg_ratelimited (fmt, ...) \ + printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) +#define pr_alert_ratelimited (fmt, ...) \ + printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_crit_ratelimited (fmt, ...) \ + printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_err_ratelimited (fmt, ...) \ + printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) +#define pr_warning_ratelimited (fmt, ...) \ + printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) +#define pr_notice_ratelimited (fmt, ...) \ + printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info_ratelimited (fmt, ...) \ + printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) +/* no pr_cont_ratelimited, don't do that... */ +/* If you are writing a driver, please use dev_dbg instead */ +#if defined(DEBUG ) +#define pr_debug_ratelimited (fmt, ...) \ + printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) +#else +#define pr_debug_ratelimited (fmt, ...) \ + ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \ + ##__VA_ARGS__); 0; }) +#endif + +extern void wake_up_klogd (void ); + +/* +* Display an IP address in readable format. +*/ + +#define NIPQUAD (addr) \ + ((unsigned char *)&addr)[0], \ + ((unsigned char *)&addr)[1], \ + ((unsigned char *)&addr)[2], \ + ((unsigned char *)&addr)[3] +#define NIPQUAD_FMT "%u.%u.%u.%u" + +#endif
include/linux/kernel.h +3 -435
481 lines not on this page · raw message
include/linux/panic.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef _PANIC_H +#define _PANIC_H + +#define TAINT_PROPRIETARY_MODULE 0 +#define TAINT_FORCED_MODULE 1 +#define TAINT_UNSAFE_SMP 2 +#define TAINT_FORCED_RMMOD 3 +#define TAINT_MACHINE_CHECK 4 +#define TAINT_BAD_PAGE 5 +#define TAINT_USER 6 +#define TAINT_DIE 7 +#define TAINT_OVERRIDDEN_ACPI_TABLE 8 +#define TAINT_WARN 9 +#define TAINT_CRAP 10 + +extern struct atomic_notifier_head panic_notifier_list; +extern long (*panic_blink)(long time); +NORET_TYPE void panic(const char * fmt, ...) + __attribute__ ((NORET_AND format (printf, 1, 2))) __cold; +extern void oops_enter (void ); +extern void oops_exit (void ); +extern int oops_may_print (void ); +extern const char *print_tainted (void ); +extern void add_taint (unsigned flag); +extern int test_taint (unsigned flag); +extern unsigned long get_taint (void ); +/* If oops_in_progress is set, +an oops, panic(), BUG() or die() is in progress */ +extern int oops_in_progress; +extern int panic_timeout; +extern int panic_on_oops; +extern int panic_on_unrecovered_nmi; +extern int panic_on_io_nmi; + +#endif
include/linux/string.h +30 -0
@@ -142,5 +142,35 @@ static inline bool strstarts(const char {return strncmp (str, prefix,strlen (prefix)) ==0 ; } + +extern unsigned long simple_strtoul (const char *,char **,unsigned int ); +extern long simple_strtol (const char *,char **,unsigned int ); +extern unsigned long long simple_strtoull (const char *,char **,unsigned int ); +extern long long simple_strtoll (const char *,char **,unsigned int ); +extern int strict_strtoul (const char *,unsigned int ,unsigned long *); +extern int strict_strtol (const char *,unsigned int ,long *); +extern int strict_strtoull (const char *,unsigned int ,unsigned long long *); +extern int strict_strtoll (const char *,unsigned int ,long long *); +extern int sprintf (char * buf,const char * fmt, ...) + __attribute__ ((format (printf,2 ,3 ))); +extern int vsprintf (char *buf,const char *,va_list ) + __attribute__ ((format (printf,2 ,0 ))); +extern int snprintf (char * buf,size_t size,const char * fmt, ...) + __attribute__ ((format (printf,3 ,4 ))); +extern int vsnprintf (char *buf,size_t size,const char *fmt,va_list args) + __attribute__ ((format (printf,3 ,0 ))); +extern int scnprintf (char * buf,size_t size,const char * fmt, ...) + __attribute__ ((format (printf,3 ,4 ))); +extern int vscnprintf (char *buf,size_t size,const char *fmt,va_list args) + __attribute__ ((format (printf,3 ,0 ))); +extern char *kasprintf (gfp_t gfp,const char *fmt, ...) + __attribute__ ((format (printf,2 ,3 ))); +extern char *kvasprintf (gfp_t gfp,const char *fmt,va_list args); + +extern int sscanf (const char *,const char *, ...) + __attribute__ ((format (scanf,2 ,3 ))); +extern int vsscanf (const char *,const char *,va_list ) + __attribute__ ((format (scanf,2 ,0 )));#endif +#endif /* _LINUX_STRING_H_ */