]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sysctl: call sysctl tests with a for loop
authorJoel Granados <joel.granados@kernel.org>
Tue, 18 Mar 2025 21:04:28 +0000 (22:04 +0100)
committerJoel Granados <joel.granados@kernel.org>
Mon, 14 Apr 2025 12:13:41 +0000 (14:13 +0200)
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>
lib/test_sysctl.c

index 54a22e4b134677e022af05df3c75268e7a4a79e7..4b3d56de6269b93220ecbeb3d3d4e42944b0ca78 100644 (file)
@@ -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);