aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2018-03-28 15:05:36 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-03-28 16:55:19 -0400
commitcf14f27f82af78e713f8a57c477cf9233faf8b30 (patch)
tree35b9919d56890c7c3d04ec24e8c1c427b71786e2
parent4fe43c2c00349557fdf4e6d61a67ebbe670412b8 (diff)
macro: introduce COUNT_ARGS() macro
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> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--include/linux/kernel.h7
-rw-r--r--security/apparmor/include/path.h7
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) { }
919#define swap(a, b) \ 919#define swap(a, b) \
920 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) 920 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
921 921
922/* This counts to 12. Any more, it will return 13th argument. */
923#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _n, X...) _n
924#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
925
926#define __CONCAT(a, b) a ## b
927#define CONCATENATE(a, b) __CONCAT(a, b)
928
922/** 929/**
923 * container_of - cast a member of a structure out to the containing structure 930 * container_of - cast a member of a structure out to the containing structure
924 * @ptr: the pointer to the member. 931 * @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 {
43 43
44DECLARE_PER_CPU(struct aa_buffers, aa_buffers); 44DECLARE_PER_CPU(struct aa_buffers, aa_buffers);
45 45
46#define COUNT_ARGS(X...) COUNT_ARGS_HELPER(, ##X, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
47#define COUNT_ARGS_HELPER(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, n, X...) n
48#define CONCAT(X, Y) X ## Y
49#define CONCAT_AFTER(X, Y) CONCAT(X, Y)
50
51#define ASSIGN(FN, X, N) ((X) = FN(N)) 46#define ASSIGN(FN, X, N) ((X) = FN(N))
52#define EVAL1(FN, X) ASSIGN(FN, X, 0) /*X = FN(0)*/ 47#define EVAL1(FN, X) ASSIGN(FN, X, 0) /*X = FN(0)*/
53#define EVAL2(FN, X, Y...) do { ASSIGN(FN, X, 1); EVAL1(FN, Y); } while (0) 48#define EVAL2(FN, X, Y...) do { ASSIGN(FN, X, 1); EVAL1(FN, Y); } while (0)
54#define EVAL(FN, X...) CONCAT_AFTER(EVAL, COUNT_ARGS(X))(FN, X) 49#define EVAL(FN, X...) CONCATENATE(EVAL, COUNT_ARGS(X))(FN, X)
55 50
56#define for_each_cpu_buffer(I) for ((I) = 0; (I) < MAX_PATH_BUFFERS; (I)++) 51#define for_each_cpu_buffer(I) for ((I) = 0; (I) < MAX_PATH_BUFFERS; (I)++)
57 52