Commit 975db45e authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Ingo Molnar

locking/static_keys: Avoid nested functions

clang does not support nested functions inside of an array definition:

  lib/test_static_keys.c:105:16: error: function definition is not allowed here
                          .test_key       = test_key_func(&old_true_key, static_key_true),
  lib/test_static_keys.c:50:20: note: expanded from macro 'test_key_func'
          ({bool func(void) { return branch(key); } func; })

That code appears to be a little too clever, so this simplifies it
a bit by defining functions outside of the array.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarJason Baron <jbaron@akamai.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lkml.kernel.org/r/1454942223-2781480-1-git-send-email-arnd@arndb.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 2a96fd74
...@@ -47,7 +47,10 @@ struct test_key { ...@@ -47,7 +47,10 @@ struct test_key {
}; };
#define test_key_func(key, branch) \ #define test_key_func(key, branch) \
({bool func(void) { return branch(key); } func; }) static bool key ## _ ## branch(void) \
{ \
return branch(&key); \
}
static void invert_key(struct static_key *key) static void invert_key(struct static_key *key)
{ {
...@@ -92,6 +95,25 @@ static int verify_keys(struct test_key *keys, int size, bool invert) ...@@ -92,6 +95,25 @@ static int verify_keys(struct test_key *keys, int size, bool invert)
return 0; return 0;
} }
test_key_func(old_true_key, static_key_true)
test_key_func(old_false_key, static_key_false)
test_key_func(true_key, static_branch_likely)
test_key_func(true_key, static_branch_unlikely)
test_key_func(false_key, static_branch_likely)
test_key_func(false_key, static_branch_unlikely)
test_key_func(base_old_true_key, static_key_true)
test_key_func(base_inv_old_true_key, static_key_true)
test_key_func(base_old_false_key, static_key_false)
test_key_func(base_inv_old_false_key, static_key_false)
test_key_func(base_true_key, static_branch_likely)
test_key_func(base_true_key, static_branch_unlikely)
test_key_func(base_inv_true_key, static_branch_likely)
test_key_func(base_inv_true_key, static_branch_unlikely)
test_key_func(base_false_key, static_branch_likely)
test_key_func(base_false_key, static_branch_unlikely)
test_key_func(base_inv_false_key, static_branch_likely)
test_key_func(base_inv_false_key, static_branch_unlikely)
static int __init test_static_key_init(void) static int __init test_static_key_init(void)
{ {
int ret; int ret;
...@@ -102,95 +124,95 @@ static int __init test_static_key_init(void) ...@@ -102,95 +124,95 @@ static int __init test_static_key_init(void)
{ {
.init_state = true, .init_state = true,
.key = &old_true_key, .key = &old_true_key,
.test_key = test_key_func(&old_true_key, static_key_true), .test_key = &old_true_key_static_key_true,
}, },
{ {
.init_state = false, .init_state = false,
.key = &old_false_key, .key = &old_false_key,
.test_key = test_key_func(&old_false_key, static_key_false), .test_key = &old_false_key_static_key_false,
}, },
/* internal keys - new keys */ /* internal keys - new keys */
{ {
.init_state = true, .init_state = true,
.key = &true_key.key, .key = &true_key.key,
.test_key = test_key_func(&true_key, static_branch_likely), .test_key = &true_key_static_branch_likely,
}, },
{ {
.init_state = true, .init_state = true,
.key = &true_key.key, .key = &true_key.key,
.test_key = test_key_func(&true_key, static_branch_unlikely), .test_key = &true_key_static_branch_unlikely,
}, },
{ {
.init_state = false, .init_state = false,
.key = &false_key.key, .key = &false_key.key,
.test_key = test_key_func(&false_key, static_branch_likely), .test_key = &false_key_static_branch_likely,
}, },
{ {
.init_state = false, .init_state = false,
.key = &false_key.key, .key = &false_key.key,
.test_key = test_key_func(&false_key, static_branch_unlikely), .test_key = &false_key_static_branch_unlikely,
}, },
/* external keys - old keys */ /* external keys - old keys */
{ {
.init_state = true, .init_state = true,
.key = &base_old_true_key, .key = &base_old_true_key,
.test_key = test_key_func(&base_old_true_key, static_key_true), .test_key = &base_old_true_key_static_key_true,
}, },
{ {
.init_state = false, .init_state = false,
.key = &base_inv_old_true_key, .key = &base_inv_old_true_key,
.test_key = test_key_func(&base_inv_old_true_key, static_key_true), .test_key = &base_inv_old_true_key_static_key_true,
}, },
{ {
.init_state = false, .init_state = false,
.key = &base_old_false_key, .key = &base_old_false_key,
.test_key = test_key_func(&base_old_false_key, static_key_false), .test_key = &base_old_false_key_static_key_false,
}, },
{ {
.init_state = true, .init_state = true,
.key = &base_inv_old_false_key, .key = &base_inv_old_false_key,
.test_key = test_key_func(&base_inv_old_false_key, static_key_false), .test_key = &base_inv_old_false_key_static_key_false,
}, },
/* external keys - new keys */ /* external keys - new keys */
{ {
.init_state = true, .init_state = true,
.key = &base_true_key.key, .key = &base_true_key.key,
.test_key = test_key_func(&base_true_key, static_branch_likely), .test_key = &base_true_key_static_branch_likely,
}, },
{ {
.init_state = true, .init_state = true,
.key = &base_true_key.key, .key = &base_true_key.key,
.test_key = test_key_func(&base_true_key, static_branch_unlikely), .test_key = &base_true_key_static_branch_unlikely,
}, },
{ {
.init_state = false, .init_state = false,
.key = &base_inv_true_key.key, .key = &base_inv_true_key.key,
.test_key = test_key_func(&base_inv_true_key, static_branch_likely), .test_key = &base_inv_true_key_static_branch_likely,
}, },
{ {
.init_state = false, .init_state = false,
.key = &base_inv_true_key.key, .key = &base_inv_true_key.key,
.test_key = test_key_func(&base_inv_true_key, static_branch_unlikely), .test_key = &base_inv_true_key_static_branch_unlikely,
}, },
{ {
.init_state = false, .init_state = false,
.key = &base_false_key.key, .key = &base_false_key.key,
.test_key = test_key_func(&base_false_key, static_branch_likely), .test_key = &base_false_key_static_branch_likely,
}, },
{ {
.init_state = false, .init_state = false,
.key = &base_false_key.key, .key = &base_false_key.key,
.test_key = test_key_func(&base_false_key, static_branch_unlikely), .test_key = &base_false_key_static_branch_unlikely,
}, },
{ {
.init_state = true, .init_state = true,
.key = &base_inv_false_key.key, .key = &base_inv_false_key.key,
.test_key = test_key_func(&base_inv_false_key, static_branch_likely), .test_key = &base_inv_false_key_static_branch_likely,
}, },
{ {
.init_state = true, .init_state = true,
.key = &base_inv_false_key.key, .key = &base_inv_false_key.key,
.test_key = test_key_func(&base_inv_false_key, static_branch_unlikely), .test_key = &base_inv_false_key_static_branch_unlikely,
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment