static_call: make selftest available for out-of-line SC

Message ID 20240110104854.292752-1-songshuaishuai@tinylab.org
State New
Headers
Series static_call: make selftest available for out-of-line SC |

Commit Message

Song Shuai Jan. 10, 2024, 10:48 a.m. UTC
  Static call selftest should be built once HAVE_STATIC_CALL is configured.
but it's now bonded with HAVE_STATIC_CALL_INLINE.

Move selftest to static_call.c making it available for out-of-line SC.

Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
 kernel/static_call.c        | 44 +++++++++++++++++++++++++++++++++++++
 kernel/static_call_inline.c | 42 -----------------------------------
 2 files changed, 44 insertions(+), 42 deletions(-)
  

Patch

diff --git a/kernel/static_call.c b/kernel/static_call.c
index e9c3e69f3837..b1e1b4573201 100644
--- a/kernel/static_call.c
+++ b/kernel/static_call.c
@@ -1,8 +1,52 @@ 
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/static_call.h>
+#include <linux/init.h>
 
 long __static_call_return0(void)
 {
 	return 0;
 }
 EXPORT_SYMBOL_GPL(__static_call_return0);
+
+#ifdef CONFIG_STATIC_CALL_SELFTEST
+
+static int func_a(int x)
+{
+	return x+1;
+}
+
+static int func_b(int x)
+{
+	return x+2;
+}
+
+DEFINE_STATIC_CALL(sc_selftest, func_a);
+
+static struct static_call_data {
+      int (*func)(int);
+      int val;
+      int expect;
+} static_call_data [] __initdata = {
+      { NULL,   2, 3 },
+      { func_b, 2, 4 },
+      { func_a, 2, 3 }
+};
+
+static int __init test_static_call_init(void)
+{
+      int i;
+
+      for (i = 0; i < ARRAY_SIZE(static_call_data); i++ ) {
+	      struct static_call_data *scd = &static_call_data[i];
+
+              if (scd->func)
+                      static_call_update(sc_selftest, scd->func);
+
+              WARN_ON(static_call(sc_selftest)(scd->val) != scd->expect);
+      }
+
+      return 0;
+}
+early_initcall(test_static_call_init);
+
+#endif /* CONFIG_STATIC_CALL_SELFTEST */
diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c
index 639397b5491c..3e65bfafe559 100644
--- a/kernel/static_call_inline.c
+++ b/kernel/static_call_inline.c
@@ -512,45 +512,3 @@  int __init static_call_init(void)
 }
 early_initcall(static_call_init);
 
-#ifdef CONFIG_STATIC_CALL_SELFTEST
-
-static int func_a(int x)
-{
-	return x+1;
-}
-
-static int func_b(int x)
-{
-	return x+2;
-}
-
-DEFINE_STATIC_CALL(sc_selftest, func_a);
-
-static struct static_call_data {
-      int (*func)(int);
-      int val;
-      int expect;
-} static_call_data [] __initdata = {
-      { NULL,   2, 3 },
-      { func_b, 2, 4 },
-      { func_a, 2, 3 }
-};
-
-static int __init test_static_call_init(void)
-{
-      int i;
-
-      for (i = 0; i < ARRAY_SIZE(static_call_data); i++ ) {
-	      struct static_call_data *scd = &static_call_data[i];
-
-              if (scd->func)
-                      static_call_update(sc_selftest, scd->func);
-
-              WARN_ON(static_call(sc_selftest)(scd->val) != scd->expect);
-      }
-
-      return 0;
-}
-early_initcall(test_static_call_init);
-
-#endif /* CONFIG_STATIC_CALL_SELFTEST */