summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Granados <joel.granados@kernel.org>2025-03-18 22:04:28 +0100
committerJoel Granados <joel.granados@kernel.org>2025-04-14 14:13:41 +0200
commit2bac112eaaf391f190905134cc8e7ffc02dd131c (patch)
treeb22a9deaae9a23cd51fd7d75cca7ce2bfad24eed
parent8e4acabdc8691529c163c18a45bcdd332bd75145 (diff)
sysctl: call sysctl tests with a for loop
As we add more test functions in lib/tests_sysctl the main test function (test_sysctl_init) grows. Condense the logic to make it easier to add/remove tests. Reviewed-by: Kees Cook <kees@kernel.org> Signed-off-by: Joel Granados <joel.granados@kernel.org>
-rw-r--r--lib/test_sysctl.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c
index 54a22e4b1346..4b3d56de6269 100644
--- a/lib/test_sysctl.c
+++ b/lib/test_sysctl.c
@@ -301,27 +301,19 @@ static int test_sysctl_register_u8_extra(void)
static int __init test_sysctl_init(void)
{
- int err;
-
- err = test_sysctl_setup_node_tests();
- if (err)
- goto out;
-
- err = test_sysctl_run_unregister_nested();
- if (err)
- goto out;
-
- err = test_sysctl_run_register_mount_point();
- if (err)
- goto out;
-
- err = test_sysctl_run_register_empty();
- if (err)
- goto out;
+ int err = 0;
+
+ int (*func_array[])(void) = {
+ test_sysctl_setup_node_tests,
+ test_sysctl_run_unregister_nested,
+ test_sysctl_run_register_mount_point,
+ test_sysctl_run_register_empty,
+ test_sysctl_register_u8_extra
+ };
- err = test_sysctl_register_u8_extra();
+ for (int i = 0; !err && i < ARRAY_SIZE(func_array); i++)
+ err = func_array[i]();
-out:
return err;
}
module_init(test_sysctl_init);