mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Arnd Bergmann <arnd@arndb.de>,
	Casey Schaufler <casey@schaufler-ca.com>,
	linux-kernel@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [RFC][PATCH v1 1/1] Add WARN_ONCE_RETURN macro
Date: Fri, 14 Aug 2015 16:43:19 +0300	[thread overview]
Message-ID: <1439559799-116694-1-git-send-email-andriy.shevchenko@linux.intel.com> (raw)

The rationale is to replace the
	if (condition) {
		WARN_ONCE(1, ...);
		return value;
	}
by
	WARN_ONCE_RETURN(condition, value, ...);

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/asm-generic/bug.h  | 17 +++++++++++++++++
 security/smack/smack_lsm.c |  5 +----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 630dd23..fbf20fd 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -126,6 +126,18 @@ extern void warn_slowpath_null(const char *file, const int line);
 	unlikely(__ret_warn_once);				\
 })
 
+#define WARN_ONCE_RETURN(condition, value, format...)		\
+do {								\
+	static bool __section(.data.unlikely) __warned;		\
+	int __ret_warn_once = !!(condition);			\
+								\
+	if (unlikely(__ret_warn_once)) {			\
+		if (WARN(!__warned, format)) 			\
+			__warned = true;			\
+		return value;					\
+	}							\
+} while (0)
+
 #define WARN_TAINT_ONCE(condition, taint, format...)	({	\
 	static bool __section(.data.unlikely) __warned;		\
 	int __ret_warn_once = !!(condition);			\
@@ -162,6 +174,11 @@ extern void warn_slowpath_null(const char *file, const int line);
 
 #define WARN_ON_ONCE(condition) WARN_ON(condition)
 #define WARN_ONCE(condition, format...) WARN(condition, format)
+#define WARN_ONCE_RETURN(condition, value, format...)			\
+do {									\
+	if (WARN(condition, format))					\
+		return value;						\
+} while (0)
 #define WARN_TAINT(condition, taint, format...) WARN(condition, format)
 #define WARN_TAINT_ONCE(condition, taint, format...) WARN(condition, format)
 
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 54fb3a1..4160d0e 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -4401,10 +4401,7 @@ static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
 	struct smack_known *skp;
 	char *rule = vrule;
 
-	if (unlikely(!rule)) {
-		WARN_ONCE(1, "Smack: missing rule\n");
-		return -ENOENT;
-	}
+	WARN_ONCE_RETURN(unlikely(!rule), -ENOENT, "Smack: missing rule\n");
 
 	if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
 		return 0;
-- 
2.5.0


             reply	other threads:[~2015-08-14 13:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-14 13:43 Andy Shevchenko [this message]
2015-08-14 15:48 ` Casey Schaufler
2015-08-14 18:25   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439559799-116694-1-git-send-email-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=casey@schaufler-ca.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome