All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@kernel.org>
To: <davem@davemloft.net>
Cc: <daniel@iogearbox.net>, <torvalds@linux-foundation.org>,
	<peterz@infradead.org>, <rostedt@goodmis.org>,
	<mathieu.desnoyers@efficios.com>, <netdev@vger.kernel.org>,
	<kernel-team@fb.com>, <linux-api@vger.kernel.org>
Subject: [PATCH v8 bpf-next 5/9] macro: introduce COUNT_ARGS() macro
Date: Wed, 28 Mar 2018 12:05:36 -0700	[thread overview]
Message-ID: <20180328190540.370956-6-ast@kernel.org> (raw)
In-Reply-To: <20180328190540.370956-1-ast@kernel.org>

move COUNT_ARGS() macro from apparmor to generic header and extend it
to count till twelve.

COUNT() was an alternative name for this logic, but it's used for
different purpose in many other places.

Similarly for CONCATENATE() macro.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 include/linux/kernel.h           | 7 +++++++
 security/apparmor/include/path.h | 7 +------
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 3fd291503576..293fa0677fba 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -919,6 +919,13 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
 #define swap(a, b) \
 	do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
 
+/* This counts to 12. Any more, it will return 13th argument. */
+#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _n, X...) _n
+#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
+
+#define __CONCAT(a, b) a ## b
+#define CONCATENATE(a, b) __CONCAT(a, b)
+
 /**
  * container_of - cast a member of a structure out to the containing structure
  * @ptr:	the pointer to the member.
diff --git a/security/apparmor/include/path.h b/security/apparmor/include/path.h
index 05fb3305671e..e042b994f2b8 100644
--- a/security/apparmor/include/path.h
+++ b/security/apparmor/include/path.h
@@ -43,15 +43,10 @@ struct aa_buffers {
 
 DECLARE_PER_CPU(struct aa_buffers, aa_buffers);
 
-#define COUNT_ARGS(X...) COUNT_ARGS_HELPER(, ##X, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
-#define COUNT_ARGS_HELPER(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, n, X...) n
-#define CONCAT(X, Y) X ## Y
-#define CONCAT_AFTER(X, Y) CONCAT(X, Y)
-
 #define ASSIGN(FN, X, N) ((X) = FN(N))
 #define EVAL1(FN, X) ASSIGN(FN, X, 0) /*X = FN(0)*/
 #define EVAL2(FN, X, Y...) do { ASSIGN(FN, X, 1);  EVAL1(FN, Y); } while (0)
-#define EVAL(FN, X...) CONCAT_AFTER(EVAL, COUNT_ARGS(X))(FN, X)
+#define EVAL(FN, X...) CONCATENATE(EVAL, COUNT_ARGS(X))(FN, X)
 
 #define for_each_cpu_buffer(I) for ((I) = 0; (I) < MAX_PATH_BUFFERS; (I)++)
 
-- 
2.9.5

WARNING: multiple messages have this Message-ID (diff)
From: Alexei Starovoitov <ast@kernel.org>
To: davem@davemloft.net
Cc: daniel@iogearbox.net, torvalds@linux-foundation.org,
	peterz@infradead.org, rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com, netdev@vger.kernel.org,
	kernel-team@fb.com, linux-api@vger.kernel.org
Subject: [PATCH v8 bpf-next 5/9] macro: introduce COUNT_ARGS() macro
Date: Wed, 28 Mar 2018 12:05:36 -0700	[thread overview]
Message-ID: <20180328190540.370956-6-ast@kernel.org> (raw)
In-Reply-To: <20180328190540.370956-1-ast@kernel.org>

move COUNT_ARGS() macro from apparmor to generic header and extend it
to count till twelve.

COUNT() was an alternative name for this logic, but it's used for
different purpose in many other places.

Similarly for CONCATENATE() macro.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 include/linux/kernel.h           | 7 +++++++
 security/apparmor/include/path.h | 7 +------
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 3fd291503576..293fa0677fba 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -919,6 +919,13 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
 #define swap(a, b) \
 	do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
 
+/* This counts to 12. Any more, it will return 13th argument. */
+#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _n, X...) _n
+#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
+
+#define __CONCAT(a, b) a ## b
+#define CONCATENATE(a, b) __CONCAT(a, b)
+
 /**
  * container_of - cast a member of a structure out to the containing structure
  * @ptr:	the pointer to the member.
diff --git a/security/apparmor/include/path.h b/security/apparmor/include/path.h
index 05fb3305671e..e042b994f2b8 100644
--- a/security/apparmor/include/path.h
+++ b/security/apparmor/include/path.h
@@ -43,15 +43,10 @@ struct aa_buffers {
 
 DECLARE_PER_CPU(struct aa_buffers, aa_buffers);
 
-#define COUNT_ARGS(X...) COUNT_ARGS_HELPER(, ##X, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
-#define COUNT_ARGS_HELPER(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, n, X...) n
-#define CONCAT(X, Y) X ## Y
-#define CONCAT_AFTER(X, Y) CONCAT(X, Y)
-
 #define ASSIGN(FN, X, N) ((X) = FN(N))
 #define EVAL1(FN, X) ASSIGN(FN, X, 0) /*X = FN(0)*/
 #define EVAL2(FN, X, Y...) do { ASSIGN(FN, X, 1);  EVAL1(FN, Y); } while (0)
-#define EVAL(FN, X...) CONCAT_AFTER(EVAL, COUNT_ARGS(X))(FN, X)
+#define EVAL(FN, X...) CONCATENATE(EVAL, COUNT_ARGS(X))(FN, X)
 
 #define for_each_cpu_buffer(I) for ((I) = 0; (I) < MAX_PATH_BUFFERS; (I)++)
 
-- 
2.9.5

  parent reply	other threads:[~2018-03-28 19:08 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 19:05 [PATCH v8 bpf-next 0/9] bpf, tracing: introduce bpf raw tracepoints Alexei Starovoitov
2018-03-28 19:05 ` Alexei Starovoitov
2018-03-28 19:05 ` [PATCH v8 bpf-next 1/9] treewide: remove large struct-pass-by-value from tracepoint arguments Alexei Starovoitov
2018-03-28 19:05   ` Alexei Starovoitov
2018-03-28 19:05 ` [PATCH v8 bpf-next 2/9] net/mediatek: disambiguate mt76 vs mt7601u trace events Alexei Starovoitov
2018-03-28 19:05   ` Alexei Starovoitov
2018-03-28 19:05 ` [PATCH v8 bpf-next 3/9] net/mac802154: disambiguate mac80215 vs mac802154 " Alexei Starovoitov
2018-03-28 19:05   ` Alexei Starovoitov
2018-03-28 19:05 ` [PATCH v8 bpf-next 4/9] net/wireless/iwlwifi: fix iwlwifi_dev_ucode_error tracepoint Alexei Starovoitov
2018-03-28 19:05   ` Alexei Starovoitov
2018-05-23 11:03   ` [v8, bpf-next, " Johannes Berg
2018-05-23 11:03     ` Johannes Berg
2018-05-24 23:28     ` Alexei Starovoitov
2018-05-24 23:28       ` Alexei Starovoitov
2018-05-24 23:39       ` Steven Rostedt
2018-05-25 10:48       ` Kalle Valo
2018-03-28 19:05 ` Alexei Starovoitov [this message]
2018-03-28 19:05   ` [PATCH v8 bpf-next 5/9] macro: introduce COUNT_ARGS() macro Alexei Starovoitov
2018-03-28 19:05 ` [PATCH v8 bpf-next 6/9] bpf: introduce BPF_RAW_TRACEPOINT Alexei Starovoitov
2018-03-28 19:05   ` Alexei Starovoitov
2018-03-28 19:34   ` Steven Rostedt
2018-03-28 19:34     ` Steven Rostedt
2018-03-28 19:38     ` Alexei Starovoitov
2018-03-28 19:38       ` Alexei Starovoitov
2018-03-28 19:40       ` Steven Rostedt
2018-03-28 19:40         ` Steven Rostedt
2018-03-28 19:48         ` Mathieu Desnoyers
2018-03-28 19:05 ` [PATCH v8 bpf-next 7/9] libbpf: add bpf_raw_tracepoint_open helper Alexei Starovoitov
2018-03-28 19:05   ` Alexei Starovoitov
2018-03-28 19:05 ` [PATCH v8 bpf-next 8/9] samples/bpf: raw tracepoint test Alexei Starovoitov
2018-03-28 19:05   ` Alexei Starovoitov
2018-03-28 19:05 ` [PATCH v8 bpf-next 9/9] selftests/bpf: test for bpf_get_stackid() from raw tracepoints Alexei Starovoitov
2018-03-28 19:05   ` Alexei Starovoitov
2018-03-28 23:59 ` [PATCH v8 bpf-next 0/9] bpf, tracing: introduce bpf " Daniel Borkmann

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=20180328190540.370956-6-ast@kernel.org \
    --to=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=kernel-team@fb.com \
    --cc=linux-api@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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 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.