Skip to contentSkip to conversation

printk cleanups

PATCH In review Namhyung Kim 2 participants 6 messages Sep 18, 2010 – Sep 21, 2010 Proc sysctl

lore
Share & tools
lore
#0 lore raw

cover printk cleanups

Hello,

This patchset tries to remove sparse warnings on printk routines. All patches in this series are simple, one-liner and don't waste your time much. Please take a look and consider applying it. :-)

Thanks.

---
Namhyung Kim (4):
printk: Fixup declaration of kmsg_reasons
printk: Add lock context annotation
printk: Change type of 'boot_delay' to int *
printk: Declare printk_ratelimit_state in ratelimit.h

 include/linux/ratelimit.h |    4 ++++
 kernel/printk.c           |    5 +++--
 kernel/sysctl.c           |    2 --
 3 files changed, 7 insertions(+), 4 deletions(-)
#1 lore raw

PATCH 1/4 printk: Fixup declaration of kmsg_reasons

Move redundant 'const' after '*' to make pointer itself const

---
 kernel/printk.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/printk.c +1 -1
index 8fe465a..a491251 100644
@@ -1511,7 +1511,7 @@ int kmsg_dump_unregister(struct kmsg_dumper *dumper)
 }
 EXPORT_SYMBOL_GPL(kmsg_dump_unregister);
 
-static const char const *kmsg_reasons[] = {
+static const char * const kmsg_reasons[] = {
 	[KMSG_DUMP_OOPS]	= "oops",
 	[KMSG_DUMP_PANIC]	= "panic",
 	[KMSG_DUMP_KEXEC]	= "kexec",
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH 2/4 printk: Add lock context annotation

In reply to Namhyung Kim

acquire_console_semaphore_for_printk() releases logbuf_lock but was missing proper annotation. Add it.

---
 kernel/printk.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
kernel/printk.c +1 -0
index a491251..a7aa858 100644
@@ -647,6 +647,7 @@ static inline int can_use_console(unsigned int cpu)
  * released but interrupts still disabled.
  */
 static int acquire_console_semaphore_for_printk(unsigned int cpu)
+	__releases(&logbuf_lock)
 {
 	int retval = 0;
 
Signature · 1 line
1.7.0.4
#3 lore raw

PATCH 3/4 printk: Change type of 'boot_delay' to int *

In reply to Namhyung Kim

get_option() takes its 2nd arg as int * so passing boot_delay to it caused following warnings from sparse:

kernel/printk.c:223:27: warning: incorrect type in argument 2 (different signedness)
kernel/printk.c:223:27: expected int *pint
kernel/printk.c:223:27: got unsigned int static [toplevel] *<noident>

Since boot_delay can't grow more than 10,000 changing it to 'int *' will not produce any problem.

---
 kernel/printk.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/printk.c +1 -1
index a7aa858..e5a5c13 100644
@@ -210,7 +210,7 @@ __setup("log_buf_len=", log_buf_len_setup);
 
 #ifdef CONFIG_BOOT_PRINTK_DELAY
 
-static unsigned int boot_delay; /* msecs delay after each printk during bootup */
+static int boot_delay; /* msecs delay after each printk during bootup */
 static unsigned long long loops_per_msec;	/* based on boot_delay */
 
 static int __init boot_delay_setup(char *str)
Signature · 1 line
1.7.0.4
#4 lore raw

PATCH 4/4 printk: Declare printk_ratelimit_state in ratelimit.h

In reply to Namhyung Kim

Adding declaration of printk_ratelimit_state in ratelimit.h removes potential build breakage and following sparse warning:

kernel/printk.c:1426:1: warning: symbol 'printk_ratelimit_state' was not declared. Should it be static?

---
 include/linux/ratelimit.h |    4 ++++
 kernel/sysctl.c           |    2 --
 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/ratelimit.h +4 -0
index 8f69d09..55e1bbc 100644
@@ -36,6 +36,10 @@ static inline void ratelimit_state_init(struct ratelimit_state *rs,
 	rs->begin = 0;
 }
 
+#ifdef CONFIG_PRINTK
+extern struct ratelimit_state printk_ratelimit_state;
+#endif
+
 extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
 #define __ratelimit(state) ___ratelimit(state, __func__)
 
kernel/sysctl.c +0 -2
index f88552c..720ab2b 100644
@@ -161,8 +161,6 @@ extern int no_unaligned_warning;
 extern int unaligned_dump_stack;
 #endif
 
-extern struct ratelimit_state printk_ratelimit_state;
-
 #ifdef CONFIG_PROC_SYSCTL
 static int proc_do_cad_pid(struct ctl_table *table, int write,
 		  void __user *buffer, size_t *lenp, loff_t *ppos);
Signature · 1 line
1.7.0.4
#5 lore raw

Re: [PATCH 4/4] printk: Declare printk_ratelimit_state in ratelimit.h

Quoted 16 lines · On Sun, 19 Sep 2010 00:53:02 +0900 Namhyung Kim <[email protected]> wrote:

Adding declaration of printk_ratelimit_state in ratelimit.h removes potential build breakage and following sparse warning:

kernel/printk.c:1426:1: warning: symbol 'printk_ratelimit_state' was not declared. Should it be static?

---
 include/linux/ratelimit.h |    4 ++++
 kernel/sysctl.c           |    2 --
 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/ratelimit.h +0 -0
index 8f69d09..55e1bbc 100644

include/linux/ratelimit.h static inline void ratelimit_state_init(struct ratelimit_state *rs, · line 42

Quoted 7 lines
include/linux/ratelimit.h +4 -0
@@ -36,6 +36,10 @@ static inline void ratelimit_state_init(struct ratelimit_state *rs,
 	rs->begin = 0;
 }
 
+#ifdef CONFIG_PRINTK
+extern struct ratelimit_state printk_ratelimit_state;
+#endif
+

We don't actually need the ifdefs there.

If we remove them then it adds a risk that someone will discover their error at link-timer rather than at compile-time. On the other hand, removing the ifdefs deuglifies the code for everyone, for ever. Personally I prefer to not have the ifdefs.

include/linux/ratelimit.h renamed from include/linux/ratelimit.h~printk-declare-printk_ratelimit_state-in-ratelimith-fix +0 -2
@@ -36,9 +36,7 @@ static inline void ratelimit_state_init(
 	rs->begin = 0;
 }
 
-#ifdef CONFIG_PRINTK
 extern struct ratelimit_state printk_ratelimit_state;
-#endif
 
 extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
 #define __ratelimit(state) ___ratelimit(state, __func__)

diff -puN kernel/sysctl.c~printk-declare-printk_ratelimit_state-in-ratelimith-fix kernel/sysctl.c _