diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2006-11-25 14:09:36 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-11-25 16:28:34 -0500 |
commit | ee3ce191e8eaa4cc15c51a28b34143b36404c4f5 (patch) | |
tree | 557c5ade9b92e91f095e4017d97ffe7afd83383f /include/linux/irqflags.h | |
parent | 5e66b0b5f187c811419ff10cfb5668c028a64d57 (diff) |
[PATCH] Enforce "unsigned long flags;" when spinlocking
Make it break or warn if you pass to spin_lock_irqsave() and friends
something different from "unsigned long flags;". Suprisingly large amount
of these was caught by recent commit
c53421b18f205c5f97c604ae55c6a921f034b0f6 and others.
Idea is largely from FRV typechecking. Suggestions from Andrew Morton.
All stupid typos in first version fixed.
Passes allmodconfig on i386, x86_64, alpha, arm as well as my usual config.
Note #1: checking with sparse is still needed, because a driver can save
and pass around flags or something. So far patch is very intrusive.
Note #2: techically, we should break only if
sizeof(flags) < sizeof(unsigned long),
however, the more pain for getting suspicious code into kernel,
the better.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/linux/irqflags.h')
-rw-r--r-- | include/linux/irqflags.h | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/include/linux/irqflags.h b/include/linux/irqflags.h index 412e025bc5c7..4fe740bf4eae 100644 --- a/include/linux/irqflags.h +++ b/include/linux/irqflags.h | |||
@@ -11,6 +11,12 @@ | |||
11 | #ifndef _LINUX_TRACE_IRQFLAGS_H | 11 | #ifndef _LINUX_TRACE_IRQFLAGS_H |
12 | #define _LINUX_TRACE_IRQFLAGS_H | 12 | #define _LINUX_TRACE_IRQFLAGS_H |
13 | 13 | ||
14 | #define BUILD_CHECK_IRQ_FLAGS(flags) \ | ||
15 | do { \ | ||
16 | BUILD_BUG_ON(sizeof(flags) != sizeof(unsigned long)); \ | ||
17 | typecheck(unsigned long, flags); \ | ||
18 | } while (0) | ||
19 | |||
14 | #ifdef CONFIG_TRACE_IRQFLAGS | 20 | #ifdef CONFIG_TRACE_IRQFLAGS |
15 | extern void trace_hardirqs_on(void); | 21 | extern void trace_hardirqs_on(void); |
16 | extern void trace_hardirqs_off(void); | 22 | extern void trace_hardirqs_off(void); |
@@ -50,10 +56,15 @@ | |||
50 | #define local_irq_disable() \ | 56 | #define local_irq_disable() \ |
51 | do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0) | 57 | do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0) |
52 | #define local_irq_save(flags) \ | 58 | #define local_irq_save(flags) \ |
53 | do { raw_local_irq_save(flags); trace_hardirqs_off(); } while (0) | 59 | do { \ |
60 | BUILD_CHECK_IRQ_FLAGS(flags); \ | ||
61 | raw_local_irq_save(flags); \ | ||
62 | trace_hardirqs_off(); \ | ||
63 | } while (0) | ||
54 | 64 | ||
55 | #define local_irq_restore(flags) \ | 65 | #define local_irq_restore(flags) \ |
56 | do { \ | 66 | do { \ |
67 | BUILD_CHECK_IRQ_FLAGS(flags); \ | ||
57 | if (raw_irqs_disabled_flags(flags)) { \ | 68 | if (raw_irqs_disabled_flags(flags)) { \ |
58 | raw_local_irq_restore(flags); \ | 69 | raw_local_irq_restore(flags); \ |
59 | trace_hardirqs_off(); \ | 70 | trace_hardirqs_off(); \ |
@@ -69,8 +80,16 @@ | |||
69 | */ | 80 | */ |
70 | # define raw_local_irq_disable() local_irq_disable() | 81 | # define raw_local_irq_disable() local_irq_disable() |
71 | # define raw_local_irq_enable() local_irq_enable() | 82 | # define raw_local_irq_enable() local_irq_enable() |
72 | # define raw_local_irq_save(flags) local_irq_save(flags) | 83 | # define raw_local_irq_save(flags) \ |
73 | # define raw_local_irq_restore(flags) local_irq_restore(flags) | 84 | do { \ |
85 | BUILD_CHECK_IRQ_FLAGS(flags); \ | ||
86 | local_irq_save(flags); \ | ||
87 | } while (0) | ||
88 | # define raw_local_irq_restore(flags) \ | ||
89 | do { \ | ||
90 | BUILD_CHECK_IRQ_FLAGS(flags); \ | ||
91 | local_irq_restore(flags); \ | ||
92 | } while (0) | ||
74 | #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */ | 93 | #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */ |
75 | 94 | ||
76 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT | 95 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
@@ -80,7 +99,11 @@ | |||
80 | raw_safe_halt(); \ | 99 | raw_safe_halt(); \ |
81 | } while (0) | 100 | } while (0) |
82 | 101 | ||
83 | #define local_save_flags(flags) raw_local_save_flags(flags) | 102 | #define local_save_flags(flags) \ |
103 | do { \ | ||
104 | BUILD_CHECK_IRQ_FLAGS(flags); \ | ||
105 | raw_local_save_flags(flags); \ | ||
106 | } while (0) | ||
84 | 107 | ||
85 | #define irqs_disabled() \ | 108 | #define irqs_disabled() \ |
86 | ({ \ | 109 | ({ \ |
@@ -90,7 +113,11 @@ | |||
90 | raw_irqs_disabled_flags(flags); \ | 113 | raw_irqs_disabled_flags(flags); \ |
91 | }) | 114 | }) |
92 | 115 | ||
93 | #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags) | 116 | #define irqs_disabled_flags(flags) \ |
117 | ({ \ | ||
118 | BUILD_CHECK_IRQ_FLAGS(flags); \ | ||
119 | raw_irqs_disabled_flags(flags); \ | ||
120 | }) | ||
94 | #endif /* CONFIG_X86 */ | 121 | #endif /* CONFIG_X86 */ |
95 | 122 | ||
96 | #endif | 123 | #endif |