hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/include/linux/moduleparam.h
....@@ -10,23 +10,21 @@
1010 module name. */
1111 #ifdef MODULE
1212 #define MODULE_PARAM_PREFIX /* empty */
13
+#define __MODULE_INFO_PREFIX /* empty */
1314 #else
1415 #define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
16
+/* We cannot use MODULE_PARAM_PREFIX because some modules override it. */
17
+#define __MODULE_INFO_PREFIX KBUILD_MODNAME "."
1518 #endif
1619
1720 /* Chosen so that structs with an unsigned long line up. */
1821 #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
1922
20
-#ifdef MODULE
2123 #define __MODULE_INFO(tag, name, info) \
2224 static const char __UNIQUE_ID(name)[] \
23
- __used __attribute__((section(".modinfo"), unused, aligned(1))) \
24
- = __stringify(tag) "=" info
25
-#else /* !MODULE */
26
-/* This struct is here for syntactic coherency, it is not used */
27
-#define __MODULE_INFO(tag, name, info) \
28
- struct __UNIQUE_ID(name) {}
29
-#endif
25
+ __used __section(".modinfo") __attribute__((unused, aligned(1))) \
26
+ = __MODULE_INFO_PREFIX __stringify(tag) "=" info
27
+
3028 #define __MODULE_PARM_TYPE(name, _type) \
3129 __MODULE_INFO(parmtype, name##type, #name ":" _type)
3230
....@@ -102,15 +100,15 @@
102100
103101 /**
104102 * module_param - typesafe helper for a module/cmdline parameter
105
- * @value: the variable to alter, and exposed parameter name.
103
+ * @name: the variable to alter, and exposed parameter name.
106104 * @type: the type of the parameter
107105 * @perm: visibility in sysfs.
108106 *
109
- * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
107
+ * @name becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
110108 * ".") the kernel commandline parameter. Note that - is changed to _, so
111109 * the user can use "foo-bar=1" even for variable "foo_bar".
112110 *
113
- * @perm is 0 if the the variable is not to appear in sysfs, or 0444
111
+ * @perm is 0 if the variable is not to appear in sysfs, or 0444
114112 * for world-readable, 0644 for root-writable, etc. Note that if it
115113 * is writable, you may need to use kernel_param_lock() around
116114 * accesses (esp. charp, which can be kfreed when it changes).
....@@ -120,7 +118,7 @@
120118 * you can create your own by defining those variables.
121119 *
122120 * Standard types are:
123
- * byte, short, ushort, int, uint, long, ulong
121
+ * byte, hexint, short, ushort, int, uint, long, ulong
124122 * charp: a character pointer
125123 * bool: a bool, values 0/1, y/n, Y/N.
126124 * invbool: the above, only sense-reversed (N = true).
....@@ -130,6 +128,9 @@
130128
131129 /**
132130 * module_param_unsafe - same as module_param but taints kernel
131
+ * @name: the variable to alter, and exposed parameter name.
132
+ * @type: the type of the parameter
133
+ * @perm: visibility in sysfs.
133134 */
134135 #define module_param_unsafe(name, type, perm) \
135136 module_param_named_unsafe(name, name, type, perm)
....@@ -152,6 +153,10 @@
152153
153154 /**
154155 * module_param_named_unsafe - same as module_param_named but taints kernel
156
+ * @name: a valid C identifier which is the parameter name.
157
+ * @value: the actual lvalue to alter.
158
+ * @type: the type of the parameter
159
+ * @perm: visibility in sysfs.
155160 */
156161 #define module_param_named_unsafe(name, value, type, perm) \
157162 param_check_##type(name, &(value)); \
....@@ -162,6 +167,7 @@
162167 * module_param_cb - general callback for a module/cmdline parameter
163168 * @name: a valid C identifier which is the parameter name.
164169 * @ops: the set & get operations for this parameter.
170
+ * @arg: args for @ops
165171 * @perm: visibility in sysfs.
166172 *
167173 * The ops can have NULL set or get functions.
....@@ -173,36 +179,96 @@
173179 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \
174180 KERNEL_PARAM_FL_UNSAFE)
175181
182
+#define __level_param_cb(name, ops, arg, perm, level) \
183
+ __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
176184 /**
177
- * <level>_param_cb - general callback for a module/cmdline parameter
178
- * to be evaluated before certain initcall level
185
+ * core_param_cb - general callback for a module/cmdline parameter
186
+ * to be evaluated before core initcall level
179187 * @name: a valid C identifier which is the parameter name.
180188 * @ops: the set & get operations for this parameter.
189
+ * @arg: args for @ops
181190 * @perm: visibility in sysfs.
182191 *
183192 * The ops can have NULL set or get functions.
184193 */
185
-#define __level_param_cb(name, ops, arg, perm, level) \
186
- __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
187
-
188194 #define core_param_cb(name, ops, arg, perm) \
189195 __level_param_cb(name, ops, arg, perm, 1)
190196
197
+/**
198
+ * postcore_param_cb - general callback for a module/cmdline parameter
199
+ * to be evaluated before postcore initcall level
200
+ * @name: a valid C identifier which is the parameter name.
201
+ * @ops: the set & get operations for this parameter.
202
+ * @arg: args for @ops
203
+ * @perm: visibility in sysfs.
204
+ *
205
+ * The ops can have NULL set or get functions.
206
+ */
191207 #define postcore_param_cb(name, ops, arg, perm) \
192208 __level_param_cb(name, ops, arg, perm, 2)
193209
210
+/**
211
+ * arch_param_cb - general callback for a module/cmdline parameter
212
+ * to be evaluated before arch initcall level
213
+ * @name: a valid C identifier which is the parameter name.
214
+ * @ops: the set & get operations for this parameter.
215
+ * @arg: args for @ops
216
+ * @perm: visibility in sysfs.
217
+ *
218
+ * The ops can have NULL set or get functions.
219
+ */
194220 #define arch_param_cb(name, ops, arg, perm) \
195221 __level_param_cb(name, ops, arg, perm, 3)
196222
223
+/**
224
+ * subsys_param_cb - general callback for a module/cmdline parameter
225
+ * to be evaluated before subsys initcall level
226
+ * @name: a valid C identifier which is the parameter name.
227
+ * @ops: the set & get operations for this parameter.
228
+ * @arg: args for @ops
229
+ * @perm: visibility in sysfs.
230
+ *
231
+ * The ops can have NULL set or get functions.
232
+ */
197233 #define subsys_param_cb(name, ops, arg, perm) \
198234 __level_param_cb(name, ops, arg, perm, 4)
199235
236
+/**
237
+ * fs_param_cb - general callback for a module/cmdline parameter
238
+ * to be evaluated before fs initcall level
239
+ * @name: a valid C identifier which is the parameter name.
240
+ * @ops: the set & get operations for this parameter.
241
+ * @arg: args for @ops
242
+ * @perm: visibility in sysfs.
243
+ *
244
+ * The ops can have NULL set or get functions.
245
+ */
200246 #define fs_param_cb(name, ops, arg, perm) \
201247 __level_param_cb(name, ops, arg, perm, 5)
202248
249
+/**
250
+ * device_param_cb - general callback for a module/cmdline parameter
251
+ * to be evaluated before device initcall level
252
+ * @name: a valid C identifier which is the parameter name.
253
+ * @ops: the set & get operations for this parameter.
254
+ * @arg: args for @ops
255
+ * @perm: visibility in sysfs.
256
+ *
257
+ * The ops can have NULL set or get functions.
258
+ */
203259 #define device_param_cb(name, ops, arg, perm) \
204260 __level_param_cb(name, ops, arg, perm, 6)
205261
262
+/**
263
+ * late_param_cb - general callback for a module/cmdline parameter
264
+ * to be evaluated before late initcall level
265
+ * @name: a valid C identifier which is the parameter name.
266
+ * @ops: the set & get operations for this parameter.
267
+ * @arg: args for @ops
268
+ * @perm: visibility in sysfs.
269
+ *
270
+ * The ops can have NULL set or get functions.
271
+ */
206272 #define late_param_cb(name, ops, arg, perm) \
207273 __level_param_cb(name, ops, arg, perm, 7)
208274
....@@ -223,7 +289,7 @@
223289 static const char __param_str_##name[] = prefix #name; \
224290 static struct kernel_param __moduleparam_const __param_##name \
225291 __used \
226
- __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
292
+ __section("__param") __attribute__ ((unused, aligned(sizeof(void *)))) \
227293 = { __param_str_##name, THIS_MODULE, ops, \
228294 VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
229295
....@@ -265,6 +331,10 @@
265331
266332 /**
267333 * core_param_unsafe - same as core_param but taints kernel
334
+ * @name: the name of the cmdline and sysfs parameter (often the same as var)
335
+ * @var: the variable
336
+ * @type: the type of the parameter
337
+ * @perm: visibility in sysfs
268338 */
269339 #define core_param_unsafe(name, var, type, perm) \
270340 param_check_##type(name, &(var)); \
....@@ -378,6 +448,11 @@
378448 extern int param_get_ullong(char *buffer, const struct kernel_param *kp);
379449 #define param_check_ullong(name, p) __param_check(name, p, unsigned long long)
380450
451
+extern const struct kernel_param_ops param_ops_hexint;
452
+extern int param_set_hexint(const char *val, const struct kernel_param *kp);
453
+extern int param_get_hexint(char *buffer, const struct kernel_param *kp);
454
+#define param_check_hexint(name, p) param_check_uint(name, p)
455
+
381456 extern const struct kernel_param_ops param_ops_charp;
382457 extern int param_set_charp(const char *val, const struct kernel_param *kp);
383458 extern int param_get_charp(char *buffer, const struct kernel_param *kp);