diff options
author | Jiri Slaby <jslaby@suse.cz> | 2016-12-19 19:23:12 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-12-20 12:48:47 -0500 |
commit | 1b011e2f13fcf37e1e577fed25b295808d6c83b9 (patch) | |
tree | 50bb2b58757f3c578f40dec19c2b42a8d6bc534d /include/linux/ratelimit.h | |
parent | 4983f0ab7ffaad1e534b21975367429736475205 (diff) |
ratelimit: fix WARN_ON_RATELIMIT return value
The macro is to be used similarly as WARN_ON as:
if (WARN_ON_RATELIMIT(condition, state))
do_something();
One would expect only 'condition' to affect the 'if', but
WARN_ON_RATELIMIT does internally only:
WARN_ON((condition) && __ratelimit(state))
So the 'if' is affected by the ratelimiting state too. Fix this by
returning 'condition' in any case.
Note that nobody uses WARN_ON_RATELIMIT yet, so there is nothing to
worry about. But I was about to use it and was a bit surprised.
Link: http://lkml.kernel.org/r/20161215093224.23126-1-jslaby@suse.cz
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/ratelimit.h')
-rw-r--r-- | include/linux/ratelimit.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h index 57c9e0622a38..56375edf2ed2 100644 --- a/include/linux/ratelimit.h +++ b/include/linux/ratelimit.h | |||
@@ -77,8 +77,11 @@ extern int ___ratelimit(struct ratelimit_state *rs, const char *func); | |||
77 | 77 | ||
78 | #ifdef CONFIG_PRINTK | 78 | #ifdef CONFIG_PRINTK |
79 | 79 | ||
80 | #define WARN_ON_RATELIMIT(condition, state) \ | 80 | #define WARN_ON_RATELIMIT(condition, state) ({ \ |
81 | WARN_ON((condition) && __ratelimit(state)) | 81 | bool __rtn_cond = !!(condition); \ |
82 | WARN_ON(__rtn_cond && __ratelimit(state)); \ | ||
83 | __rtn_cond; \ | ||
84 | }) | ||
82 | 85 | ||
83 | #define WARN_RATELIMIT(condition, format, ...) \ | 86 | #define WARN_RATELIMIT(condition, format, ...) \ |
84 | ({ \ | 87 | ({ \ |