xref: /linux-6.15/include/linux/moduleparam.h (revision 91f9d330)
11da177e4SLinus Torvalds #ifndef _LINUX_MODULE_PARAMS_H
21da177e4SLinus Torvalds #define _LINUX_MODULE_PARAMS_H
31da177e4SLinus Torvalds /* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */
41da177e4SLinus Torvalds #include <linux/init.h>
51da177e4SLinus Torvalds #include <linux/stringify.h>
61da177e4SLinus Torvalds #include <linux/kernel.h>
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds /* You can override this manually, but generally this should match the
91da177e4SLinus Torvalds    module name. */
101da177e4SLinus Torvalds #ifdef MODULE
111da177e4SLinus Torvalds #define MODULE_PARAM_PREFIX /* empty */
121da177e4SLinus Torvalds #else
13367cb704SSam Ravnborg #define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
141da177e4SLinus Torvalds #endif
151da177e4SLinus Torvalds 
16730b69d2SRusty Russell /* Chosen so that structs with an unsigned long line up. */
17730b69d2SRusty Russell #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
18730b69d2SRusty Russell 
19b75be420SLinus Walleij #ifdef MODULE
201da177e4SLinus Torvalds #define __MODULE_INFO(tag, name, info)					  \
2134182eeaSRusty Russell static const char __UNIQUE_ID(name)[]					  \
22b6472776SJan Beulich   __used __attribute__((section(".modinfo"), unused, aligned(1)))	  \
23b6472776SJan Beulich   = __stringify(tag) "=" info
241da177e4SLinus Torvalds #else  /* !MODULE */
25b75be420SLinus Walleij /* This struct is here for syntactic coherency, it is not used */
26b75be420SLinus Walleij #define __MODULE_INFO(tag, name, info)					  \
2734182eeaSRusty Russell   struct __UNIQUE_ID(name) {}
281da177e4SLinus Torvalds #endif
291da177e4SLinus Torvalds #define __MODULE_PARM_TYPE(name, _type)					  \
301da177e4SLinus Torvalds   __MODULE_INFO(parmtype, name##type, #name ":" _type)
311da177e4SLinus Torvalds 
32639938ebSPaul Gortmaker /* One for each parameter, describing how to use it.  Some files do
33639938ebSPaul Gortmaker    multiple of these per line, so can't just use MODULE_INFO. */
34639938ebSPaul Gortmaker #define MODULE_PARM_DESC(_parm, desc) \
35639938ebSPaul Gortmaker 	__MODULE_INFO(parm, _parm, #_parm ":" desc)
36639938ebSPaul Gortmaker 
371da177e4SLinus Torvalds struct kernel_param;
381da177e4SLinus Torvalds 
39ab013c5fSSteven Rostedt /*
40ab013c5fSSteven Rostedt  * Flags available for kernel_param_ops
41ab013c5fSSteven Rostedt  *
42ab013c5fSSteven Rostedt  * NOARG - the parameter allows for no argument (foo instead of foo=1)
43ab013c5fSSteven Rostedt  */
44ab013c5fSSteven Rostedt enum {
456a4c2643SJani Nikula 	KERNEL_PARAM_OPS_FL_NOARG = (1 << 0)
46ab013c5fSSteven Rostedt };
47ab013c5fSSteven Rostedt 
489bbb9e5aSRusty Russell struct kernel_param_ops {
49ab013c5fSSteven Rostedt 	/* How the ops should behave */
50ab013c5fSSteven Rostedt 	unsigned int flags;
511da177e4SLinus Torvalds 	/* Returns 0, or -errno.  arg is in kp->arg. */
529bbb9e5aSRusty Russell 	int (*set)(const char *val, const struct kernel_param *kp);
531da177e4SLinus Torvalds 	/* Returns length written or -errno.  Buffer is 4k (ie. be short!) */
549bbb9e5aSRusty Russell 	int (*get)(char *buffer, const struct kernel_param *kp);
55e6df34a4SRusty Russell 	/* Optional function to free kp->arg when module unloaded. */
56e6df34a4SRusty Russell 	void (*free)(void *arg);
579bbb9e5aSRusty Russell };
581da177e4SLinus Torvalds 
59*91f9d330SJani Nikula /*
60*91f9d330SJani Nikula  * Flags available for kernel_param
61*91f9d330SJani Nikula  *
62*91f9d330SJani Nikula  * UNSAFE - the parameter is dangerous and setting it will taint the kernel
63*91f9d330SJani Nikula  */
64*91f9d330SJani Nikula enum {
65*91f9d330SJani Nikula 	KERNEL_PARAM_FL_UNSAFE = (1 << 0)
66*91f9d330SJani Nikula };
67*91f9d330SJani Nikula 
681da177e4SLinus Torvalds struct kernel_param {
691da177e4SLinus Torvalds 	const char *name;
709bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
7145fcc70cSRusty Russell 	u16 perm;
72*91f9d330SJani Nikula 	s8 level;
73*91f9d330SJani Nikula 	u8 flags;
7422e48eafSJan Beulich 	union {
751da177e4SLinus Torvalds 		void *arg;
7622e48eafSJan Beulich 		const struct kparam_string *str;
7722e48eafSJan Beulich 		const struct kparam_array *arr;
7822e48eafSJan Beulich 	};
791da177e4SLinus Torvalds };
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds /* Special one for strings we want to copy into */
821da177e4SLinus Torvalds struct kparam_string {
831da177e4SLinus Torvalds 	unsigned int maxlen;
841da177e4SLinus Torvalds 	char *string;
851da177e4SLinus Torvalds };
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds /* Special one for arrays */
881da177e4SLinus Torvalds struct kparam_array
891da177e4SLinus Torvalds {
901da177e4SLinus Torvalds 	unsigned int max;
91c5be0b2eSRichard Kennedy 	unsigned int elemsize;
921da177e4SLinus Torvalds 	unsigned int *num;
939bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
941da177e4SLinus Torvalds 	void *elem;
951da177e4SLinus Torvalds };
961da177e4SLinus Torvalds 
97546970bcSRusty Russell /**
98546970bcSRusty Russell  * module_param - typesafe helper for a module/cmdline parameter
99546970bcSRusty Russell  * @value: the variable to alter, and exposed parameter name.
100546970bcSRusty Russell  * @type: the type of the parameter
101546970bcSRusty Russell  * @perm: visibility in sysfs.
102546970bcSRusty Russell  *
103546970bcSRusty Russell  * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
104546970bcSRusty Russell  * ".") the kernel commandline parameter.  Note that - is changed to _, so
105546970bcSRusty Russell  * the user can use "foo-bar=1" even for variable "foo_bar".
106546970bcSRusty Russell  *
107546970bcSRusty Russell  * @perm is 0 if the the variable is not to appear in sysfs, or 0444
108546970bcSRusty Russell  * for world-readable, 0644 for root-writable, etc.  Note that if it
109546970bcSRusty Russell  * is writable, you may need to use kparam_block_sysfs_write() around
110546970bcSRusty Russell  * accesses (esp. charp, which can be kfreed when it changes).
111546970bcSRusty Russell  *
112546970bcSRusty Russell  * The @type is simply pasted to refer to a param_ops_##type and a
113546970bcSRusty Russell  * param_check_##type: for convenience many standard types are provided but
114546970bcSRusty Russell  * you can create your own by defining those variables.
115546970bcSRusty Russell  *
116546970bcSRusty Russell  * Standard types are:
117546970bcSRusty Russell  *	byte, short, ushort, int, uint, long, ulong
118546970bcSRusty Russell  *	charp: a character pointer
119546970bcSRusty Russell  *	bool: a bool, values 0/1, y/n, Y/N.
120546970bcSRusty Russell  *	invbool: the above, only sense-reversed (N = true).
121546970bcSRusty Russell  */
122546970bcSRusty Russell #define module_param(name, type, perm)				\
123546970bcSRusty Russell 	module_param_named(name, name, type, perm)
124546970bcSRusty Russell 
125546970bcSRusty Russell /**
126546970bcSRusty Russell  * module_param_named - typesafe helper for a renamed module/cmdline parameter
127546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
128546970bcSRusty Russell  * @value: the actual lvalue to alter.
129546970bcSRusty Russell  * @type: the type of the parameter
130546970bcSRusty Russell  * @perm: visibility in sysfs.
131546970bcSRusty Russell  *
132546970bcSRusty Russell  * Usually it's a good idea to have variable names and user-exposed names the
133546970bcSRusty Russell  * same, but that's harder if the variable must be non-static or is inside a
134546970bcSRusty Russell  * structure.  This allows exposure under a different name.
135546970bcSRusty Russell  */
136546970bcSRusty Russell #define module_param_named(name, value, type, perm)			   \
137546970bcSRusty Russell 	param_check_##type(name, &(value));				   \
138546970bcSRusty Russell 	module_param_cb(name, &param_ops_##type, &value, perm);		   \
139546970bcSRusty Russell 	__MODULE_PARM_TYPE(name, #type)
140546970bcSRusty Russell 
141546970bcSRusty Russell /**
142546970bcSRusty Russell  * module_param_cb - general callback for a module/cmdline parameter
143546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
144546970bcSRusty Russell  * @ops: the set & get operations for this parameter.
145546970bcSRusty Russell  * @perm: visibility in sysfs.
146546970bcSRusty Russell  *
147546970bcSRusty Russell  * The ops can have NULL set or get functions.
148546970bcSRusty Russell  */
149546970bcSRusty Russell #define module_param_cb(name, ops, arg, perm)				      \
150*91f9d330SJani Nikula 	__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)
151026cee00SPawel Moll 
152026cee00SPawel Moll /**
153026cee00SPawel Moll  * <level>_param_cb - general callback for a module/cmdline parameter
154026cee00SPawel Moll  *                    to be evaluated before certain initcall level
155026cee00SPawel Moll  * @name: a valid C identifier which is the parameter name.
156026cee00SPawel Moll  * @ops: the set & get operations for this parameter.
157026cee00SPawel Moll  * @perm: visibility in sysfs.
158026cee00SPawel Moll  *
159026cee00SPawel Moll  * The ops can have NULL set or get functions.
160026cee00SPawel Moll  */
161026cee00SPawel Moll #define __level_param_cb(name, ops, arg, perm, level)			\
162*91f9d330SJani Nikula 	__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
163026cee00SPawel Moll 
164026cee00SPawel Moll #define core_param_cb(name, ops, arg, perm)		\
165026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 1)
166026cee00SPawel Moll 
167026cee00SPawel Moll #define postcore_param_cb(name, ops, arg, perm)		\
168026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 2)
169026cee00SPawel Moll 
170026cee00SPawel Moll #define arch_param_cb(name, ops, arg, perm)		\
171026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 3)
172026cee00SPawel Moll 
173026cee00SPawel Moll #define subsys_param_cb(name, ops, arg, perm)		\
174026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 4)
175026cee00SPawel Moll 
176026cee00SPawel Moll #define fs_param_cb(name, ops, arg, perm)		\
177026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 5)
178026cee00SPawel Moll 
179026cee00SPawel Moll #define device_param_cb(name, ops, arg, perm)		\
180026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 6)
181026cee00SPawel Moll 
182026cee00SPawel Moll #define late_param_cb(name, ops, arg, perm)		\
183026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 7)
184546970bcSRusty Russell 
18591d35dd9SIvan Kokshaysky /* On alpha, ia64 and ppc64 relocations to global data cannot go into
18691d35dd9SIvan Kokshaysky    read-only sections (which is part of respective UNIX ABI on these
18791d35dd9SIvan Kokshaysky    platforms). So 'const' makes no sense and even causes compile failures
18891d35dd9SIvan Kokshaysky    with some compilers. */
18991d35dd9SIvan Kokshaysky #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
19091d35dd9SIvan Kokshaysky #define __moduleparam_const
19191d35dd9SIvan Kokshaysky #else
19291d35dd9SIvan Kokshaysky #define __moduleparam_const const
19391d35dd9SIvan Kokshaysky #endif
19491d35dd9SIvan Kokshaysky 
1951da177e4SLinus Torvalds /* This is the fundamental function for registering boot/module
196546970bcSRusty Russell    parameters. */
197*91f9d330SJani Nikula #define __module_param_call(prefix, name, ops, arg, perm, level, flags)	\
1989774a1f5SAlexey Dobriyan 	/* Default value instead of permissions? */			\
19922e48eafSJan Beulich 	static const char __param_str_##name[] = prefix #name; \
20091d35dd9SIvan Kokshaysky 	static struct kernel_param __moduleparam_const __param_##name	\
2013ff6eeccSAdrian Bunk 	__used								\
2021da177e4SLinus Torvalds     __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
20358f86cc8SRusty Russell 	= { __param_str_##name, ops, VERIFY_OCTAL_PERMISSIONS(perm),	\
204*91f9d330SJani Nikula 	    level, flags, { arg } }
2051da177e4SLinus Torvalds 
2069bbb9e5aSRusty Russell /* Obsolete - use module_param_cb() */
2071da177e4SLinus Torvalds #define module_param_call(name, set, get, arg, perm)			\
2089bbb9e5aSRusty Russell 	static struct kernel_param_ops __param_ops_##name =		\
209ab013c5fSSteven Rostedt 		{ 0, (void *)set, (void *)get };			\
210fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX,			\
2119bbb9e5aSRusty Russell 			    name, &__param_ops_##name, arg,		\
212*91f9d330SJani Nikula 			    (perm) + sizeof(__check_old_set_param(set))*0, -1, 0)
2131da177e4SLinus Torvalds 
2149bbb9e5aSRusty Russell /* We don't get oldget: it's often a new-style param_get_uint, etc. */
2159bbb9e5aSRusty Russell static inline int
2169bbb9e5aSRusty Russell __check_old_set_param(int (*oldset)(const char *, struct kernel_param *))
2179bbb9e5aSRusty Russell {
2189bbb9e5aSRusty Russell 	return 0;
2199bbb9e5aSRusty Russell }
2209bbb9e5aSRusty Russell 
221907b29ebSRusty Russell /**
222907b29ebSRusty Russell  * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs.
223907b29ebSRusty Russell  * @name: the name of the parameter
224907b29ebSRusty Russell  *
225907b29ebSRusty Russell  * There's no point blocking write on a paramter that isn't writable via sysfs!
226907b29ebSRusty Russell  */
227907b29ebSRusty Russell #define kparam_block_sysfs_write(name)			\
228907b29ebSRusty Russell 	do {						\
229907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
230907b29ebSRusty Russell 		__kernel_param_lock();			\
231907b29ebSRusty Russell 	} while (0)
232907b29ebSRusty Russell 
233907b29ebSRusty Russell /**
234907b29ebSRusty Russell  * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again.
235907b29ebSRusty Russell  * @name: the name of the parameter
236907b29ebSRusty Russell  */
237907b29ebSRusty Russell #define kparam_unblock_sysfs_write(name)		\
238907b29ebSRusty Russell 	do {						\
239907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
240907b29ebSRusty Russell 		__kernel_param_unlock();		\
241907b29ebSRusty Russell 	} while (0)
242907b29ebSRusty Russell 
243907b29ebSRusty Russell /**
244907b29ebSRusty Russell  * kparam_block_sysfs_read - make sure a parameter isn't read via sysfs.
245907b29ebSRusty Russell  * @name: the name of the parameter
246907b29ebSRusty Russell  *
247907b29ebSRusty Russell  * This also blocks sysfs writes.
248907b29ebSRusty Russell  */
249907b29ebSRusty Russell #define kparam_block_sysfs_read(name)			\
250907b29ebSRusty Russell 	do {						\
251907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
252907b29ebSRusty Russell 		__kernel_param_lock();			\
253907b29ebSRusty Russell 	} while (0)
254907b29ebSRusty Russell 
255907b29ebSRusty Russell /**
256907b29ebSRusty Russell  * kparam_unblock_sysfs_read - allows sysfs to read a parameter again.
257907b29ebSRusty Russell  * @name: the name of the parameter
258907b29ebSRusty Russell  */
259907b29ebSRusty Russell #define kparam_unblock_sysfs_read(name)			\
260907b29ebSRusty Russell 	do {						\
261907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
262907b29ebSRusty Russell 		__kernel_param_unlock();		\
263907b29ebSRusty Russell 	} while (0)
264907b29ebSRusty Russell 
265907b29ebSRusty Russell #ifdef CONFIG_SYSFS
266907b29ebSRusty Russell extern void __kernel_param_lock(void);
267907b29ebSRusty Russell extern void __kernel_param_unlock(void);
268907b29ebSRusty Russell #else
269907b29ebSRusty Russell static inline void __kernel_param_lock(void)
270907b29ebSRusty Russell {
271907b29ebSRusty Russell }
272907b29ebSRusty Russell static inline void __kernel_param_unlock(void)
273907b29ebSRusty Russell {
274907b29ebSRusty Russell }
275907b29ebSRusty Russell #endif
276907b29ebSRusty Russell 
27767e67ceaSRusty Russell #ifndef MODULE
27867e67ceaSRusty Russell /**
27967e67ceaSRusty Russell  * core_param - define a historical core kernel parameter.
28067e67ceaSRusty Russell  * @name: the name of the cmdline and sysfs parameter (often the same as var)
28167e67ceaSRusty Russell  * @var: the variable
282546970bcSRusty Russell  * @type: the type of the parameter
28367e67ceaSRusty Russell  * @perm: visibility in sysfs
28467e67ceaSRusty Russell  *
28567e67ceaSRusty Russell  * core_param is just like module_param(), but cannot be modular and
28667e67ceaSRusty Russell  * doesn't add a prefix (such as "printk.").  This is for compatibility
28767e67ceaSRusty Russell  * with __setup(), and it makes sense as truly core parameters aren't
28867e67ceaSRusty Russell  * tied to the particular file they're in.
28967e67ceaSRusty Russell  */
29067e67ceaSRusty Russell #define core_param(name, var, type, perm)				\
29167e67ceaSRusty Russell 	param_check_##type(name, &(var));				\
292*91f9d330SJani Nikula 	__module_param_call("", name, &param_ops_##type, &var, perm, -1, 0)
29367e67ceaSRusty Russell #endif /* !MODULE */
29467e67ceaSRusty Russell 
295546970bcSRusty Russell /**
296546970bcSRusty Russell  * module_param_string - a char array parameter
297546970bcSRusty Russell  * @name: the name of the parameter
298546970bcSRusty Russell  * @string: the string variable
299546970bcSRusty Russell  * @len: the maximum length of the string, incl. terminator
300546970bcSRusty Russell  * @perm: visibility in sysfs.
301546970bcSRusty Russell  *
302546970bcSRusty Russell  * This actually copies the string when it's set (unlike type charp).
303546970bcSRusty Russell  * @len is usually just sizeof(string).
304546970bcSRusty Russell  */
3051da177e4SLinus Torvalds #define module_param_string(name, string, len, perm)			\
30622e48eafSJan Beulich 	static const struct kparam_string __param_string_##name		\
3071da177e4SLinus Torvalds 		= { len, string };					\
308fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
3099bbb9e5aSRusty Russell 			    &param_ops_string,				\
310*91f9d330SJani Nikula 			    .str = &__param_string_##name, perm, -1, 0);\
3111da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "string")
3121da177e4SLinus Torvalds 
313b1e4d20cSMichal Schmidt /**
314b1e4d20cSMichal Schmidt  * parameq - checks if two parameter names match
315b1e4d20cSMichal Schmidt  * @name1: parameter name 1
316b1e4d20cSMichal Schmidt  * @name2: parameter name 2
317b1e4d20cSMichal Schmidt  *
318b1e4d20cSMichal Schmidt  * Returns true if the two parameter names are equal.
319b1e4d20cSMichal Schmidt  * Dashes (-) are considered equal to underscores (_).
320b1e4d20cSMichal Schmidt  */
321b1e4d20cSMichal Schmidt extern bool parameq(const char *name1, const char *name2);
322b1e4d20cSMichal Schmidt 
323b1e4d20cSMichal Schmidt /**
324b1e4d20cSMichal Schmidt  * parameqn - checks if two parameter names match
325b1e4d20cSMichal Schmidt  * @name1: parameter name 1
326b1e4d20cSMichal Schmidt  * @name2: parameter name 2
327b1e4d20cSMichal Schmidt  * @n: the length to compare
328b1e4d20cSMichal Schmidt  *
329b1e4d20cSMichal Schmidt  * Similar to parameq(), except it compares @n characters.
330b1e4d20cSMichal Schmidt  */
331b1e4d20cSMichal Schmidt extern bool parameqn(const char *name1, const char *name2, size_t n);
332b1e4d20cSMichal Schmidt 
3331da177e4SLinus Torvalds /* Called on module insert or kernel boot */
33451e158c1SRusty Russell extern char *parse_args(const char *name,
3351da177e4SLinus Torvalds 		      char *args,
336914dcaa8SRusty Russell 		      const struct kernel_param *params,
3371da177e4SLinus Torvalds 		      unsigned num,
338026cee00SPawel Moll 		      s16 level_min,
339026cee00SPawel Moll 		      s16 level_max,
3409fb48c74SJim Cromie 		      int (*unknown)(char *param, char *val,
3419fb48c74SJim Cromie 			      const char *doing));
3421da177e4SLinus Torvalds 
343e180a6b7SRusty Russell /* Called by module remove. */
344e180a6b7SRusty Russell #ifdef CONFIG_SYSFS
345e180a6b7SRusty Russell extern void destroy_params(const struct kernel_param *params, unsigned num);
346e180a6b7SRusty Russell #else
347e180a6b7SRusty Russell static inline void destroy_params(const struct kernel_param *params,
348e180a6b7SRusty Russell 				  unsigned num)
349e180a6b7SRusty Russell {
350e180a6b7SRusty Russell }
351e180a6b7SRusty Russell #endif /* !CONFIG_SYSFS */
352e180a6b7SRusty Russell 
3531da177e4SLinus Torvalds /* All the helper functions */
3541da177e4SLinus Torvalds /* The macros to do compile-time type checking stolen from Jakub
3551da177e4SLinus Torvalds    Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
3561da177e4SLinus Torvalds #define __param_check(name, p, type) \
3570283f9a5SMark Charlebois 	static inline type __always_unused *__check_##name(void) { return(p); }
3581da177e4SLinus Torvalds 
359*91f9d330SJani Nikula /**
360*91f9d330SJani Nikula  * param_check_unsafe - Warn and taint the kernel if setting dangerous options.
361*91f9d330SJani Nikula  *
362*91f9d330SJani Nikula  * This gets called from all the standard param setters, but can be used from
363*91f9d330SJani Nikula  * custom setters as well.
364*91f9d330SJani Nikula  */
365*91f9d330SJani Nikula static inline void
366*91f9d330SJani Nikula param_check_unsafe(const struct kernel_param *kp)
367*91f9d330SJani Nikula {
368*91f9d330SJani Nikula 	if (kp->flags & KERNEL_PARAM_FL_UNSAFE) {
369*91f9d330SJani Nikula 		pr_warn("Setting dangerous option %s - tainting kernel\n",
370*91f9d330SJani Nikula 			kp->name);
371*91f9d330SJani Nikula 		add_taint(TAINT_USER, LOCKDEP_STILL_OK);
372*91f9d330SJani Nikula 	}
373*91f9d330SJani Nikula }
374*91f9d330SJani Nikula 
3759bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_byte;
3769bbb9e5aSRusty Russell extern int param_set_byte(const char *val, const struct kernel_param *kp);
3779bbb9e5aSRusty Russell extern int param_get_byte(char *buffer, const struct kernel_param *kp);
3781da177e4SLinus Torvalds #define param_check_byte(name, p) __param_check(name, p, unsigned char)
3791da177e4SLinus Torvalds 
3809bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_short;
3819bbb9e5aSRusty Russell extern int param_set_short(const char *val, const struct kernel_param *kp);
3829bbb9e5aSRusty Russell extern int param_get_short(char *buffer, const struct kernel_param *kp);
3831da177e4SLinus Torvalds #define param_check_short(name, p) __param_check(name, p, short)
3841da177e4SLinus Torvalds 
3859bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ushort;
3869bbb9e5aSRusty Russell extern int param_set_ushort(const char *val, const struct kernel_param *kp);
3879bbb9e5aSRusty Russell extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
3881da177e4SLinus Torvalds #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
3891da177e4SLinus Torvalds 
3909bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_int;
3919bbb9e5aSRusty Russell extern int param_set_int(const char *val, const struct kernel_param *kp);
3929bbb9e5aSRusty Russell extern int param_get_int(char *buffer, const struct kernel_param *kp);
3931da177e4SLinus Torvalds #define param_check_int(name, p) __param_check(name, p, int)
3941da177e4SLinus Torvalds 
3959bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_uint;
3969bbb9e5aSRusty Russell extern int param_set_uint(const char *val, const struct kernel_param *kp);
3979bbb9e5aSRusty Russell extern int param_get_uint(char *buffer, const struct kernel_param *kp);
3981da177e4SLinus Torvalds #define param_check_uint(name, p) __param_check(name, p, unsigned int)
3991da177e4SLinus Torvalds 
4009bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_long;
4019bbb9e5aSRusty Russell extern int param_set_long(const char *val, const struct kernel_param *kp);
4029bbb9e5aSRusty Russell extern int param_get_long(char *buffer, const struct kernel_param *kp);
4031da177e4SLinus Torvalds #define param_check_long(name, p) __param_check(name, p, long)
4041da177e4SLinus Torvalds 
4059bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ulong;
4069bbb9e5aSRusty Russell extern int param_set_ulong(const char *val, const struct kernel_param *kp);
4079bbb9e5aSRusty Russell extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
4081da177e4SLinus Torvalds #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
4091da177e4SLinus Torvalds 
410b4210b81SHannes Reinecke extern struct kernel_param_ops param_ops_ullong;
411b4210b81SHannes Reinecke extern int param_set_ullong(const char *val, const struct kernel_param *kp);
412b4210b81SHannes Reinecke extern int param_get_ullong(char *buffer, const struct kernel_param *kp);
413b4210b81SHannes Reinecke #define param_check_ullong(name, p) __param_check(name, p, unsigned long long)
414b4210b81SHannes Reinecke 
4159bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_charp;
4169bbb9e5aSRusty Russell extern int param_set_charp(const char *val, const struct kernel_param *kp);
4179bbb9e5aSRusty Russell extern int param_get_charp(char *buffer, const struct kernel_param *kp);
4181da177e4SLinus Torvalds #define param_check_charp(name, p) __param_check(name, p, char *)
4191da177e4SLinus Torvalds 
42072db395fSRusty Russell /* We used to allow int as well as bool.  We're taking that away! */
4219bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_bool;
4229bbb9e5aSRusty Russell extern int param_set_bool(const char *val, const struct kernel_param *kp);
4239bbb9e5aSRusty Russell extern int param_get_bool(char *buffer, const struct kernel_param *kp);
42472db395fSRusty Russell #define param_check_bool(name, p) __param_check(name, p, bool)
4251da177e4SLinus Torvalds 
4269bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_invbool;
4279bbb9e5aSRusty Russell extern int param_set_invbool(const char *val, const struct kernel_param *kp);
4289bbb9e5aSRusty Russell extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
4299a71af2cSRusty Russell #define param_check_invbool(name, p) __param_check(name, p, bool)
4301da177e4SLinus Torvalds 
43169116f27SRusty Russell /* An int, which can only be set like a bool (though it shows as an int). */
43269116f27SRusty Russell extern struct kernel_param_ops param_ops_bint;
43369116f27SRusty Russell extern int param_set_bint(const char *val, const struct kernel_param *kp);
43469116f27SRusty Russell #define param_get_bint param_get_int
43569116f27SRusty Russell #define param_check_bint param_check_int
43669116f27SRusty Russell 
437546970bcSRusty Russell /**
438546970bcSRusty Russell  * module_param_array - a parameter which is an array of some type
439546970bcSRusty Russell  * @name: the name of the array variable
440546970bcSRusty Russell  * @type: the type, as per module_param()
441546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
442546970bcSRusty Russell  * @perm: visibility in sysfs
443546970bcSRusty Russell  *
444546970bcSRusty Russell  * Input and output are as comma-separated values.  Commas inside values
445546970bcSRusty Russell  * don't work properly (eg. an array of charp).
446546970bcSRusty Russell  *
447546970bcSRusty Russell  * ARRAY_SIZE(@name) is used to determine the number of elements in the
448546970bcSRusty Russell  * array, so the definition must be visible.
449546970bcSRusty Russell  */
450546970bcSRusty Russell #define module_param_array(name, type, nump, perm)		\
451546970bcSRusty Russell 	module_param_array_named(name, name, type, nump, perm)
452546970bcSRusty Russell 
453546970bcSRusty Russell /**
454546970bcSRusty Russell  * module_param_array_named - renamed parameter which is an array of some type
455546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name
456546970bcSRusty Russell  * @array: the name of the array variable
457546970bcSRusty Russell  * @type: the type, as per module_param()
458546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
459546970bcSRusty Russell  * @perm: visibility in sysfs
460546970bcSRusty Russell  *
461546970bcSRusty Russell  * This exposes a different name than the actual variable name.  See
462546970bcSRusty Russell  * module_param_named() for why this might be necessary.
463546970bcSRusty Russell  */
4641da177e4SLinus Torvalds #define module_param_array_named(name, array, type, nump, perm)		\
465bafeafeaSRusty Russell 	param_check_##type(name, &(array)[0]);				\
46622e48eafSJan Beulich 	static const struct kparam_array __param_arr_##name		\
467c5be0b2eSRichard Kennedy 	= { .max = ARRAY_SIZE(array), .num = nump,                      \
468c5be0b2eSRichard Kennedy 	    .ops = &param_ops_##type,					\
469c5be0b2eSRichard Kennedy 	    .elemsize = sizeof(array[0]), .elem = array };		\
470fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
4719bbb9e5aSRusty Russell 			    &param_array_ops,				\
472fddd5201SRusty Russell 			    .arr = &__param_arr_##name,			\
473*91f9d330SJani Nikula 			    perm, -1, 0);				\
4741da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "array of " #type)
4751da177e4SLinus Torvalds 
4769bbb9e5aSRusty Russell extern struct kernel_param_ops param_array_ops;
4771da177e4SLinus Torvalds 
4789bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_string;
4799bbb9e5aSRusty Russell extern int param_set_copystring(const char *val, const struct kernel_param *);
4809bbb9e5aSRusty Russell extern int param_get_string(char *buffer, const struct kernel_param *kp);
4811da177e4SLinus Torvalds 
482b634d130SJean Delvare /* for exporting parameters in /sys/module/.../parameters */
4831da177e4SLinus Torvalds 
4841da177e4SLinus Torvalds struct module;
4851da177e4SLinus Torvalds 
486ef665c1aSRandy Dunlap #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
4871da177e4SLinus Torvalds extern int module_param_sysfs_setup(struct module *mod,
4889bbb9e5aSRusty Russell 				    const struct kernel_param *kparam,
4891da177e4SLinus Torvalds 				    unsigned int num_params);
4901da177e4SLinus Torvalds 
4911da177e4SLinus Torvalds extern void module_param_sysfs_remove(struct module *mod);
492ef665c1aSRandy Dunlap #else
493ef665c1aSRandy Dunlap static inline int module_param_sysfs_setup(struct module *mod,
4949bbb9e5aSRusty Russell 			     const struct kernel_param *kparam,
495ef665c1aSRandy Dunlap 			     unsigned int num_params)
496ef665c1aSRandy Dunlap {
497ef665c1aSRandy Dunlap 	return 0;
498ef665c1aSRandy Dunlap }
499ef665c1aSRandy Dunlap 
500ef665c1aSRandy Dunlap static inline void module_param_sysfs_remove(struct module *mod)
501ef665c1aSRandy Dunlap { }
502ef665c1aSRandy Dunlap #endif
5031da177e4SLinus Torvalds 
5041da177e4SLinus Torvalds #endif /* _LINUX_MODULE_PARAMS_H */
505