test_sysctl.c (c25141062a82ae8bddced1b3ce2b57a1c0efabe0) test_sysctl.c (2ea622b887e74497ce5aac5bfe247502b5786f56)
1/*
2 * proc sysctl test driver
3 *
4 * Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or at your option any

--- 33 unchanged lines hidden (view full) ---

42struct test_sysctl_data {
43 int int_0001;
44 int int_0002;
45 int int_0003[4];
46
47 unsigned int uint_0001;
48
49 char string_0001[65];
1/*
2 * proc sysctl test driver
3 *
4 * Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or at your option any

--- 33 unchanged lines hidden (view full) ---

42struct test_sysctl_data {
43 int int_0001;
44 int int_0002;
45 int int_0003[4];
46
47 unsigned int uint_0001;
48
49 char string_0001[65];
50
51#define SYSCTL_TEST_BITMAP_SIZE 65536
52 unsigned long *bitmap_0001;
50};
51
52static struct test_sysctl_data test_data = {
53 .int_0001 = 60,
54 .int_0002 = 1,
55
56 .int_0003[0] = 0,
57 .int_0003[1] = 1,

--- 39 unchanged lines hidden (view full) ---

97 },
98 {
99 .procname = "string_0001",
100 .data = &test_data.string_0001,
101 .maxlen = sizeof(test_data.string_0001),
102 .mode = 0644,
103 .proc_handler = proc_dostring,
104 },
53};
54
55static struct test_sysctl_data test_data = {
56 .int_0001 = 60,
57 .int_0002 = 1,
58
59 .int_0003[0] = 0,
60 .int_0003[1] = 1,

--- 39 unchanged lines hidden (view full) ---

100 },
101 {
102 .procname = "string_0001",
103 .data = &test_data.string_0001,
104 .maxlen = sizeof(test_data.string_0001),
105 .mode = 0644,
106 .proc_handler = proc_dostring,
107 },
108 {
109 .procname = "bitmap_0001",
110 .data = &test_data.bitmap_0001,
111 .maxlen = SYSCTL_TEST_BITMAP_SIZE,
112 .mode = 0644,
113 .proc_handler = proc_do_large_bitmap,
114 },
105 { }
106};
107
108static struct ctl_table test_sysctl_table[] = {
109 {
110 .procname = "test_sysctl",
111 .maxlen = 0,
112 .mode = 0555,

--- 11 unchanged lines hidden (view full) ---

124 },
125 { }
126};
127
128static struct ctl_table_header *test_sysctl_header;
129
130static int __init test_sysctl_init(void)
131{
115 { }
116};
117
118static struct ctl_table test_sysctl_table[] = {
119 {
120 .procname = "test_sysctl",
121 .maxlen = 0,
122 .mode = 0555,

--- 11 unchanged lines hidden (view full) ---

134 },
135 { }
136};
137
138static struct ctl_table_header *test_sysctl_header;
139
140static int __init test_sysctl_init(void)
141{
142 test_data.bitmap_0001 = kzalloc(SYSCTL_TEST_BITMAP_SIZE/8, GFP_KERNEL);
143 if (!test_data.bitmap_0001)
144 return -ENOMEM;
132 test_sysctl_header = register_sysctl_table(test_sysctl_root_table);
145 test_sysctl_header = register_sysctl_table(test_sysctl_root_table);
133 if (!test_sysctl_header)
146 if (!test_sysctl_header) {
147 kfree(test_data.bitmap_0001);
134 return -ENOMEM;
148 return -ENOMEM;
149 }
135 return 0;
136}
137late_initcall(test_sysctl_init);
138
139static void __exit test_sysctl_exit(void)
140{
150 return 0;
151}
152late_initcall(test_sysctl_init);
153
154static void __exit test_sysctl_exit(void)
155{
156 kfree(test_data.bitmap_0001);
141 if (test_sysctl_header)
142 unregister_sysctl_table(test_sysctl_header);
143}
144
145module_exit(test_sysctl_exit);
146
147MODULE_AUTHOR("Luis R. Rodriguez <mcgrof@kernel.org>");
148MODULE_LICENSE("GPL");
157 if (test_sysctl_header)
158 unregister_sysctl_table(test_sysctl_header);
159}
160
161module_exit(test_sysctl_exit);
162
163MODULE_AUTHOR("Luis R. Rodriguez <mcgrof@kernel.org>");
164MODULE_LICENSE("GPL");