From: Wen Yang The debug module still passes extra pointers for its numeric ranges. Convert them to numeric min/max so it exercises the same shape as the rest of the tree, and keep the dynamic-value entry's context in data for now; the priv conversion comes later. Suggested-by: Joel Granados Signed-off-by: Wen Yang --- lib/test_sysctl.c | 135 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 109 insertions(+), 26 deletions(-) diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index eed2cc1bea82..1411896fdbd0 100644 --- a/lib/test_sysctl.c +++ b/lib/test_sysctl.c @@ -15,7 +15,6 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include -#include #include #include #include @@ -28,8 +27,6 @@ #include #include -static int i_zero; -static int i_one_hundred = 100; static int match_int_ok = 1; enum { @@ -43,6 +40,12 @@ enum { }; static struct ctl_table_header *ctl_headers[TEST_H_SIZE] = {}; + +struct test_sysctl_range_context { + int value; + int limit; +}; + struct test_sysctl_data { int int_0001; int int_0002; @@ -56,6 +59,11 @@ struct test_sysctl_data { unsigned int uint_0001; + struct test_sysctl_range_context dynamic; + int int_zero; + unsigned long ulong_zero; + u8 u8_zero; + char string_0001[65]; #define SYSCTL_TEST_BITMAP_SIZE 65536 @@ -80,9 +88,25 @@ static struct test_sysctl_data test_data = { .uint_0001 = 314, + .dynamic = { .value = 0, .limit = 100 }, + .string_0001 = "(none)", }; +/* The registered data is typed context, not the backing integer. */ +static int test_sysctl_dynamic_value(const struct ctl_table *table, int dir, + void *buffer, size_t *lenp, loff_t *ppos) +{ + struct test_sysctl_range_context *context = table->data; + struct ctl_table resolved = *table; + + resolved.data = &context->value; + resolved.maxlen = sizeof(context->value); + resolved.min = INT_MIN; + resolved.max = READ_ONCE(context->limit); + return proc_dointvec_minmax(&resolved, dir, buffer, lenp, ppos); +} + /* These are all under /proc/sys/debug/test_sysctl/ */ static const struct ctl_table test_table[] = { { @@ -91,8 +115,8 @@ static const struct ctl_table test_table[] = { .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec_minmax, - .extra1 = &i_zero, - .extra2 = &i_one_hundred, + .min = 0, + .max = 100, }, { .procname = "int_0002", @@ -100,6 +124,8 @@ static const struct ctl_table test_table[] = { .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec, + .min = INT_MIN, + .max = INT_MAX, }, { .procname = "int_0003", @@ -107,6 +133,8 @@ static const struct ctl_table test_table[] = { .maxlen = sizeof(test_data.int_0003), .mode = 0644, .proc_handler = proc_dointvec, + .min = INT_MIN, + .max = INT_MAX, }, { .procname = "match_int", @@ -114,6 +142,8 @@ static const struct ctl_table test_table[] = { .maxlen = sizeof(match_int_ok), .mode = 0444, .proc_handler = proc_dointvec, + .min = INT_MIN, + .max = INT_MAX, }, { .procname = "boot_int", @@ -121,8 +151,8 @@ static const struct ctl_table test_table[] = { .maxlen = sizeof(test_data.boot_int), .mode = 0644, .proc_handler = proc_dointvec, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, + .min = 0, + .max = 1, }, { .procname = "int_jiffies", @@ -130,6 +160,8 @@ static const struct ctl_table test_table[] = { .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec_jiffies, + .min = INT_MIN, + .max = INT_MAX, }, { .procname = "int_ms_jiffies", @@ -137,6 +169,8 @@ static const struct ctl_table test_table[] = { .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec_ms_jiffies, + .min = INT_MIN, + .max = INT_MAX, }, { .procname = "int_userhz_jiffies", @@ -144,6 +178,8 @@ static const struct ctl_table test_table[] = { .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec_userhz_jiffies, + .min = INT_MIN, + .max = INT_MAX, }, { .procname = "uint_0001", @@ -151,6 +187,8 @@ static const struct ctl_table test_table[] = { .maxlen = sizeof(unsigned int), .mode = 0644, .proc_handler = proc_douintvec, + .min = 0, + .max = UINT_MAX, }, { .procname = "string_0001", @@ -166,28 +204,73 @@ static const struct ctl_table test_table[] = { .mode = 0644, .proc_handler = proc_do_large_bitmap, }, + { + .procname = "dynamic_limit", + .data = &test_data.dynamic.limit, + .maxlen = sizeof(test_data.dynamic.limit), + .mode = 0644, + .proc_handler = proc_dointvec, + .min = INT_MIN, + .max = INT_MAX, + }, + { + .procname = "dynamic_value", + .data = &test_data.dynamic, + .maxlen = sizeof(test_data.dynamic), + .mode = 0644, + .proc_handler = test_sysctl_dynamic_value, + .min = 0, + .max = ULONG_MAX, + }, + { + .procname = "int_zero", + .data = &test_data.int_zero, + .maxlen = sizeof(test_data.int_zero), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .min = 0, + .max = 0, + }, + { + .procname = "ulong_zero", + .data = &test_data.ulong_zero, + .maxlen = sizeof(test_data.ulong_zero), + .mode = 0644, + .proc_handler = proc_doulongvec_minmax, + .min = 0, + .max = 0, + }, + { + .procname = "u8_zero", + .data = &test_data.u8_zero, + .maxlen = sizeof(test_data.u8_zero), + .mode = 0644, + .proc_handler = proc_dou8vec_minmax, + .min = 0, + .max = 0, + }, }; static void test_sysctl_calc_match_int_ok(void) { int i; - struct { + const 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}, + { .defined = 0, .wanted = 0 }, + { .defined = 1, .wanted = 1 }, + { .defined = 2, .wanted = 2 }, + { .defined = 3, .wanted = 3 }, + { .defined = 4, .wanted = 4 }, + { .defined = 100, .wanted = 100 }, + { .defined = 200, .wanted = 200 }, + { .defined = 1000, .wanted = 1000 }, + { .defined = 3000, .wanted = 3000 }, + { .defined = INT_MAX, .wanted = INT_MAX }, + { .defined = 65535, .wanted = 65535 }, + { .defined = -1, .wanted = -1 }, }; for (i = 0; i < ARRAY_SIZE(match_int); i++) @@ -282,8 +365,8 @@ static const struct ctl_table table_u8_over[] = { .maxlen = sizeof(u8), .mode = 0644, .proc_handler = proc_dou8vec_minmax, - .extra1 = SYSCTL_FOUR, - .extra2 = SYSCTL_ONE_THOUSAND, + .min = 4, + .max = 1000, }, }; @@ -294,8 +377,8 @@ static const struct ctl_table table_u8_under[] = { .maxlen = sizeof(u8), .mode = 0644, .proc_handler = proc_dou8vec_minmax, - .extra1 = SYSCTL_NEG_ONE, - .extra2 = SYSCTL_ONE_HUNDRED, + .min = ULONG_MAX, + .max = 100, }, }; @@ -306,8 +389,8 @@ static const struct ctl_table table_u8_valid[] = { .maxlen = sizeof(u8), .mode = 0644, .proc_handler = proc_dou8vec_minmax, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_TWO_HUNDRED, + .min = 0, + .max = 200, }, }; -- 2.25.1