From 2bac112eaaf391f190905134cc8e7ffc02dd131c Mon Sep 17 00:00:00 2001 From: Joel Granados Date: Tue, 18 Mar 2025 22:04:28 +0100 Subject: [PATCH] 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 --- lib/test_sysctl.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) 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); -- 2.47.2