@@ -30,16 +30,17 @@ static int i_zero;
3030static int i_one_hundred = 100 ;
3131static int match_int_ok = 1 ;
3232
33+ enum {
34+ TEST_H_SETUP_NODE ,
35+ TEST_H_MNT ,
36+ TEST_H_MNTERROR ,
37+ TEST_H_EMPTY_ADD ,
38+ TEST_H_EMPTY ,
39+ TEST_H_U8 ,
40+ TEST_H_SIZE /* Always at the end */
41+ };
3342
34- static struct {
35- struct ctl_table_header * test_h_setup_node ;
36- struct ctl_table_header * test_h_mnt ;
37- struct ctl_table_header * test_h_mnterror ;
38- struct ctl_table_header * empty_add ;
39- struct ctl_table_header * empty ;
40- struct ctl_table_header * test_u8 ;
41- } sysctl_test_headers ;
42-
43+ static struct ctl_table_header * ctl_headers [TEST_H_SIZE ] = {};
4344struct test_sysctl_data {
4445 int int_0001 ;
4546 int int_0002 ;
@@ -168,8 +169,8 @@ static int test_sysctl_setup_node_tests(void)
168169 test_data .bitmap_0001 = kzalloc (SYSCTL_TEST_BITMAP_SIZE /8 , GFP_KERNEL );
169170 if (!test_data .bitmap_0001 )
170171 return - ENOMEM ;
171- sysctl_test_headers . test_h_setup_node = register_sysctl ("debug/test_sysctl" , test_table );
172- if (!sysctl_test_headers . test_h_setup_node ) {
172+ ctl_headers [ TEST_H_SETUP_NODE ] = register_sysctl ("debug/test_sysctl" , test_table );
173+ if (!ctl_headers [ TEST_H_SETUP_NODE ] ) {
173174 kfree (test_data .bitmap_0001 );
174175 return - ENOMEM ;
175176 }
@@ -203,12 +204,12 @@ static int test_sysctl_run_unregister_nested(void)
203204
204205static int test_sysctl_run_register_mount_point (void )
205206{
206- sysctl_test_headers . test_h_mnt
207+ ctl_headers [ TEST_H_MNT ]
207208 = register_sysctl_mount_point ("debug/test_sysctl/mnt" );
208- if (!sysctl_test_headers . test_h_mnt )
209+ if (!ctl_headers [ TEST_H_MNT ] )
209210 return - ENOMEM ;
210211
211- sysctl_test_headers . test_h_mnterror
212+ ctl_headers [ TEST_H_MNTERROR ]
212213 = register_sysctl ("debug/test_sysctl/mnt/mnt_error" ,
213214 test_table_unregister );
214215 /*
@@ -226,15 +227,15 @@ static const struct ctl_table test_table_empty[] = { };
226227static int test_sysctl_run_register_empty (void )
227228{
228229 /* Tets that an empty dir can be created */
229- sysctl_test_headers . empty_add
230+ ctl_headers [ TEST_H_EMPTY_ADD ]
230231 = register_sysctl ("debug/test_sysctl/empty_add" , test_table_empty );
231- if (!sysctl_test_headers . empty_add )
232+ if (!ctl_headers [ TEST_H_EMPTY_ADD ] )
232233 return - ENOMEM ;
233234
234235 /* Test that register on top of an empty dir works */
235- sysctl_test_headers . empty
236+ ctl_headers [ TEST_H_EMPTY ]
236237 = register_sysctl ("debug/test_sysctl/empty_add/empty" , test_table_empty );
237- if (!sysctl_test_headers . empty )
238+ if (!ctl_headers [ TEST_H_EMPTY ] )
238239 return - ENOMEM ;
239240
240241 return 0 ;
@@ -279,21 +280,21 @@ static const struct ctl_table table_u8_valid[] = {
279280static int test_sysctl_register_u8_extra (void )
280281{
281282 /* should fail because it's over */
282- sysctl_test_headers . test_u8
283+ ctl_headers [ TEST_H_U8 ]
283284 = register_sysctl ("debug/test_sysctl" , table_u8_over );
284- if (sysctl_test_headers . test_u8 )
285+ if (ctl_headers [ TEST_H_U8 ] )
285286 return - ENOMEM ;
286287
287288 /* should fail because it's under */
288- sysctl_test_headers . test_u8
289+ ctl_headers [ TEST_H_U8 ]
289290 = register_sysctl ("debug/test_sysctl" , table_u8_under );
290- if (sysctl_test_headers . test_u8 )
291+ if (ctl_headers [ TEST_H_U8 ] )
291292 return - ENOMEM ;
292293
293294 /* should not fail because it's valid */
294- sysctl_test_headers . test_u8
295+ ctl_headers [ TEST_H_U8 ]
295296 = register_sysctl ("debug/test_sysctl" , table_u8_valid );
296- if (!sysctl_test_headers . test_u8 )
297+ if (!ctl_headers [ TEST_H_U8 ] )
297298 return - ENOMEM ;
298299
299300 return 0 ;
@@ -321,18 +322,10 @@ module_init(test_sysctl_init);
321322static void __exit test_sysctl_exit (void )
322323{
323324 kfree (test_data .bitmap_0001 );
324- if (sysctl_test_headers .test_h_setup_node )
325- unregister_sysctl_table (sysctl_test_headers .test_h_setup_node );
326- if (sysctl_test_headers .test_h_mnt )
327- unregister_sysctl_table (sysctl_test_headers .test_h_mnt );
328- if (sysctl_test_headers .test_h_mnterror )
329- unregister_sysctl_table (sysctl_test_headers .test_h_mnterror );
330- if (sysctl_test_headers .empty )
331- unregister_sysctl_table (sysctl_test_headers .empty );
332- if (sysctl_test_headers .empty_add )
333- unregister_sysctl_table (sysctl_test_headers .empty_add );
334- if (sysctl_test_headers .test_u8 )
335- unregister_sysctl_table (sysctl_test_headers .test_u8 );
325+ for (int i = 0 ; i < TEST_H_SIZE ; i ++ ) {
326+ if (ctl_headers [i ])
327+ unregister_sysctl_table (ctl_headers [i ]);
328+ }
336329}
337330
338331module_exit (test_sysctl_exit );
0 commit comments