Fix uninitialized spinlock of printk_ratelimited()
PATCH 1/1 Fix uninitialized spinlock of printk_ratelimited()
ratelimit_state initialization of printk_ratelimited() seems broken. This fixes it by using DEFINE_RATELIMIT_STATE() to initialize spinlock properly.
---
include/linux/kernel.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
include/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +7 -8
@@ -420,14 +420,13 @@ static inline char *pack_hex_byte(char ** 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__); \ +#define printk_ratelimited (fmt, ...) ({ \ + static DEFINE_RATELIMIT_STATE(_rs, \ + DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + \ + if (__ratelimit(&_rs)) \ + printk(fmt, ##__VA_ARGS__); \ })#else /* No effect, but we still get type checking even in the !PRINTK case: */
_
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Quoted 23 lines · On Mon, 17 May 2010 08:57:38 +0900 OGAWA Hirofumi…
ratelimit_stateinitialization ofprintk_ratelimited()seems broken. This fixes it by usingDEFINE_RATELIMIT_STATE()to initialize spinlock properly.Signed-off-by OGAWA Hirofumi <[email protected]>---
include/linux/kernel.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)diff -puN
include/linux/kernel.h~printk_ratelimited-fixinclude/linux/kernel.hinclude/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +0
-6@@ -420,14 +420,13 @@ static inline char *pack_hex_byte(char ** 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, \ - }; \ - \
include/linux/kernel.h static inline char *pack_hex_byte(char * · line 430
Quoted 10 lines
include/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +7
-2-if (__ratelimit (&_rs)) \ - printk(fmt, ##__VA_ARGS__); \ +#define printk_ratelimited (fmt, ...) ({ \ + static DEFINE_RATELIMIT_STATE(_rs, \ + DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + \ + if (__ratelimit(&_rs)) \ + printk(fmt, ##__VA_ARGS__); \ })
hm, yes, that spinlock will get the all-zeroes pattern.
It's been like this since December 2009. I'm a bit surprised that none of our spinlock-debugging goodies picked this up. All the CONFIG_DEBUG_SPINLOCK spinlock fields end up zeroed out also.
Quoted 20 lines · Andrew Morton
Quoted 7 lines
#ifdef
CONFIG_PRINTKinclude/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +0
-6-#define printk_ratelimited (fmt, ...) ({ \ - static struct ratelimit_state _rs = { \ - .interval = DEFAULT_RATELIMIT_INTERVAL, \ - .burst = DEFAULT_RATELIMIT_BURST, \ - }; \ - \include/linux/kernel.h static inline char *pack_hex_byte(char * · line 430
Quoted 10 lines
include/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +7
-2-if (__ratelimit (&_rs)) \ - printk(fmt, ##__VA_ARGS__); \ +#define printk_ratelimited (fmt, ...) ({ \ + static DEFINE_RATELIMIT_STATE(_rs, \ + DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + \ + if (__ratelimit(&_rs)) \ + printk(fmt, ##__VA_ARGS__); \ })hm, yes, that spinlock will get the all-zeroes pattern.
Quoted 3 lines
It's been like this since December 2009. I'm a bit surprised that none of our spinlock-debugging goodies picked this up. All the
CONFIG_DEBUG_SPINLOCKspinlock fields end up zeroed out also.
The reason that dynamic analysis didn't pick up is simple - nobody is using this for now :)
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>