Skip to content

Commit

Permalink
ratelimit: fix WARN_ON_RATELIMIT return value
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jiri Slaby authored and torvalds committed Dec 20, 2016
1 parent 4983f0a commit 1b011e2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/linux/ratelimit.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ extern int ___ratelimit(struct ratelimit_state *rs, const char *func);

#ifdef CONFIG_PRINTK

#define WARN_ON_RATELIMIT(condition, state) \
WARN_ON((condition) && __ratelimit(state))
#define WARN_ON_RATELIMIT(condition, state) ({ \
bool __rtn_cond = !!(condition); \
WARN_ON(__rtn_cond && __ratelimit(state)); \
__rtn_cond; \
})

#define WARN_RATELIMIT(condition, format, ...) \
({ \
Expand Down

0 comments on commit 1b011e2

Please sign in to comment.