All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 14/15] ratelimit: fix WARN_ON_RATELIMIT return value
@ 2016-12-20  0:23 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2016-12-20  0:23 UTC (permalink / raw)
  To: torvalds, mm-commits, akpm, jslaby

From: Jiri Slaby <jslaby@suse.cz>
Subject: 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>
---

 include/linux/ratelimit.h |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff -puN include/linux/ratelimit.h~ratelimit-fix-warn_on_ratelimit-return-value include/linux/ratelimit.h
--- a/include/linux/ratelimit.h~ratelimit-fix-warn_on_ratelimit-return-value
+++ a/include/linux/ratelimit.h
@@ -77,8 +77,11 @@ extern int ___ratelimit(struct ratelimit
 
 #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, ...)			\
 ({								\
_

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-12-20  0:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-20  0:23 [patch 14/15] ratelimit: fix WARN_ON_RATELIMIT return value akpm

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.