* [PATCH] Fix uninitialized spinlock of printk_ratelimited()
@ 2010-05-16 23:57 OGAWA Hirofumi
2010-05-19 20:26 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: OGAWA Hirofumi @ 2010-05-16 23:57 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
ratelimit_state initialization of printk_ratelimited() seems
broken. This fixes it by using DEFINE_RATELIMIT_STATE() to initialize
spinlock properly.
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
include/linux/kernel.h | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff -puN include/linux/kernel.h~printk_ratelimited-fix include/linux/kernel.h
--- linux-2.6/include/linux/kernel.h~printk_ratelimited-fix 2010-05-17 03:37:33.000000000 +0900
+++ linux-2.6-hirofumi/include/linux/kernel.h 2010-05-17 03:37:33.000000000 +0900
@@ -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: */
_
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Fix uninitialized spinlock of printk_ratelimited()
2010-05-16 23:57 [PATCH] Fix uninitialized spinlock of printk_ratelimited() OGAWA Hirofumi
@ 2010-05-19 20:26 ` Andrew Morton
2010-05-19 20:44 ` OGAWA Hirofumi
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2010-05-19 20:26 UTC (permalink / raw)
To: OGAWA Hirofumi; +Cc: linux-kernel, Peter Zijlstra, Ingo Molnar
On Mon, 17 May 2010 08:57:38 +0900
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> wrote:
> ratelimit_state initialization of printk_ratelimited() seems
> broken. This fixes it by using DEFINE_RATELIMIT_STATE() to initialize
> spinlock properly.
>
> Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
> ---
>
> include/linux/kernel.h | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff -puN include/linux/kernel.h~printk_ratelimited-fix include/linux/kernel.h
> --- linux-2.6/include/linux/kernel.h~printk_ratelimited-fix 2010-05-17 03:37:33.000000000 +0900
> +++ linux-2.6-hirofumi/include/linux/kernel.h 2010-05-17 03:37:33.000000000 +0900
> @@ -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__); \
> })
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.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Fix uninitialized spinlock of printk_ratelimited()
2010-05-19 20:26 ` Andrew Morton
@ 2010-05-19 20:44 ` OGAWA Hirofumi
0 siblings, 0 replies; 3+ messages in thread
From: OGAWA Hirofumi @ 2010-05-19 20:44 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, Peter Zijlstra, Ingo Molnar
Andrew Morton <akpm@linux-foundation.org> writes:
>> #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__); \
>> })
>
> 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.
The reason that dynamic analysis didn't pick up is simple - nobody is
using this for now :)
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-05-19 20:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-16 23:57 [PATCH] Fix uninitialized spinlock of printk_ratelimited() OGAWA Hirofumi
2010-05-19 20:26 ` Andrew Morton
2010-05-19 20:44 ` OGAWA Hirofumi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox