From: Joel Granados Date: Tue, 18 Mar 2025 21:04:28 +0000 (+0100) Subject: sysctl: call sysctl tests with a for loop X-Git-Tag: v6.16-rc1~156^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2bac112eaaf391f190905134cc8e7ffc02dd131c;p=thirdparty%2Fkernel%2Flinux.git 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 Signed-off-by: Joel Granados --- diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index 54a22e4b13467..4b3d56de6269b 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);