On Tue, Apr 26, 2022 at 3:58 AM Jakub Kicinski <kuba@xxxxxxxxxx> wrote: > > On Fri, 22 Apr 2022 15:01:41 +0800 xiangxia.m.yue@xxxxxxxxx wrote: > > static int __init test_sysctl_init(void) > > { > > + test_data.match_int[0] = *(int *)SYSCTL_ZERO, > > + test_data.match_int[1] = *(int *)SYSCTL_ONE, > > + test_data.match_int[2] = *(int *)SYSCTL_TWO, > > + test_data.match_int[3] = *(int *)SYSCTL_THREE, > > + test_data.match_int[4] = *(int *)SYSCTL_FOUR, > > + test_data.match_int[5] = *(int *)SYSCTL_ONE_HUNDRED, > > + test_data.match_int[6] = *(int *)SYSCTL_TWO_HUNDRED, > > + test_data.match_int[7] = *(int *)SYSCTL_ONE_THOUSAND, > > + test_data.match_int[8] = *(int *)SYSCTL_THREE_THOUSAND, > > + test_data.match_int[9] = *(int *)SYSCTL_INT_MAX, > > + test_data.match_int[10] = *(int *)SYSCTL_MAXOLDUID, > > + test_data.match_int[11] = *(int *)SYSCTL_NEG_ONE, > > > + local VALUES=(0 1 2 3 4 100 200 1000 3000 $INT_MAX 65535 -1) > > How does this test work? Am I reading it right that it checks if this > bash array is in sync with the kernel code? This patch tries to avoid SYSCTL_XXX not mapping the values we hoped, when introducing the new SYSCTL_YYY. for example: SYSCTL_TWO, we hope it is 2, so we check it in userspace. > I'd be better if we were checking the values of the constants against > literals / defines. Hi Jakub, I think this patch checks the values of the constants against defines. But I should make the codes more readable static int __init test_sysctl_init(void) { + int i; + + struct { + int defined; + int wanted; + } match_int[] = { + {.defined = *(int *)SYSCTL_ZERO, .wanted = 0}, + {.defined = *(int *)SYSCTL_ONE, .wanted = 1}, + {.defined = *(int *)SYSCTL_TWO, .wanted = 2}, + {.defined = *(int *)SYSCTL_THREE, .wanted = 3}, + {.defined = *(int *)SYSCTL_FOUR, .wanted = 4}, + {.defined = *(int *)SYSCTL_ONE_HUNDRED, .wanted = 100}, + {.defined = *(int *)SYSCTL_TWO_HUNDRED, .wanted = 200}, + {.defined = *(int *)SYSCTL_ONE_THOUSAND, .wanted = 1000}, + {.defined = *(int *)SYSCTL_THREE_THOUSAND, .wanted = 3000}, + {.defined = *(int *)SYSCTL_INT_MAX, .wanted = INT_MAX}, + {.defined = *(int *)SYSCTL_MAXOLDUID, .wanted = 65535}, + {.defined = *(int *)SYSCTL_NEG_ONE, .wanted = -1}, + }; + + for (i = 0; i < ARRAY_SIZE(match_int); i++) + if (match_int[i].defined != match_int[i].wanted) + match_int_ok = 0; + -- Best regards, Tonghao