diff mbox series

[3/4] sysctl: call sysctl tests with a for loop

Message ID 20250321-jag-test_extra_val-v1-3-a01b3b17dc66@kernel.org (mailing list archive)
State New
Headers show
Series sysctl: Move the u8 range check test to lib/test_sysctl.c | expand

Commit Message

Joel Granados March 21, 2025, 12:47 p.m. UTC
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.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
---
 lib/test_sysctl.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c
index 54a22e4b134677e022af05df3c75268e7a4a79e7..4b3d56de6269b93220ecbeb3d3d4e42944b0ca78 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;
+	int err = 0;
 
-	err = test_sysctl_setup_node_tests();
-	if (err)
-		goto out;
+	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_run_unregister_nested();
-	if (err)
-		goto out;
+	for (int i = 0; !err && i < ARRAY_SIZE(func_array); i++)
+		err = func_array[i]();
 
-	err = test_sysctl_run_register_mount_point();
-	if (err)
-		goto out;
-
-	err = test_sysctl_run_register_empty();
-	if (err)
-		goto out;
-
-	err = test_sysctl_register_u8_extra();
-
-out:
 	return err;
 }
 module_init(test_sysctl_init);