1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Helpers for initial module or kernel cmdline parsing
3 Copyright (C) 2001 Rusty Russell.
6 #include <linux/kernel.h>
7 #include <linux/string.h>
8 #include <linux/errno.h>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/device.h>
12 #include <linux/err.h>
13 #include <linux/slab.h>
14 #include <linux/ctype.h>
17 /* Protects all built-in parameters, modules use their own param_lock */
18 static DEFINE_MUTEX(param_lock
);
20 /* Use the module's mutex, or if built-in use the built-in mutex */
22 #define KPARAM_MUTEX(mod) ((mod) ? &(mod)->param_lock : ¶m_lock)
24 #define KPARAM_MUTEX(mod) (¶m_lock)
27 static inline void check_kparam_locked(struct module
*mod
)
29 BUG_ON(!mutex_is_locked(KPARAM_MUTEX(mod
)));
32 static inline void check_kparam_locked(struct module
*mod
)
35 #endif /* !CONFIG_SYSFS */
37 /* This just allows us to keep track of which parameters are kmalloced. */
38 struct kmalloced_param
{
39 struct list_head list
;
42 static LIST_HEAD(kmalloced_params
);
43 static DEFINE_SPINLOCK(kmalloced_params_lock
);
45 static void *kmalloc_parameter(unsigned int size
)
47 struct kmalloced_param
*p
;
49 p
= kmalloc(sizeof(*p
) + size
, GFP_KERNEL
);
53 spin_lock(&kmalloced_params_lock
);
54 list_add(&p
->list
, &kmalloced_params
);
55 spin_unlock(&kmalloced_params_lock
);
60 /* Does nothing if parameter wasn't kmalloced above. */
61 static void maybe_kfree_parameter(void *param
)
63 struct kmalloced_param
*p
;
65 spin_lock(&kmalloced_params_lock
);
66 list_for_each_entry(p
, &kmalloced_params
, list
) {
67 if (p
->val
== param
) {
73 spin_unlock(&kmalloced_params_lock
);
76 static char dash2underscore(char c
)
83 bool parameqn(const char *a
, const char *b
, size_t n
)
87 for (i
= 0; i
< n
; i
++) {
88 if (dash2underscore(a
[i
]) != dash2underscore(b
[i
]))
94 bool parameq(const char *a
, const char *b
)
96 return parameqn(a
, b
, strlen(a
)+1);
99 static bool param_check_unsafe(const struct kernel_param
*kp
,
102 if (kp
->flags
& KERNEL_PARAM_FL_UNSAFE
) {
103 pr_notice("Setting dangerous option %s - tainting kernel\n",
105 add_taint(TAINT_USER
, LOCKDEP_STILL_OK
);
108 if (kp
->flags
& KERNEL_PARAM_FL_HWPARAM
&&
109 kernel_is_locked_down("Command line-specified device addresses, irqs and dma channels"))
114 static int parse_one(char *param
,
117 const struct kernel_param
*params
,
122 int (*handle_unknown
)(char *param
, char *val
,
123 const char *doing
, void *arg
))
129 for (i
= 0; i
< num_params
; i
++) {
130 if (parameq(param
, params
[i
].name
)) {
131 if (params
[i
].level
< min_level
132 || params
[i
].level
> max_level
)
134 /* No one handled NULL, so do it here. */
136 !(params
[i
].ops
->flags
& KERNEL_PARAM_OPS_FL_NOARG
))
138 pr_debug("handling %s with %p\n", param
,
140 kernel_param_lock(params
[i
].mod
);
141 if (param_check_unsafe(¶ms
[i
], doing
))
142 err
= params
[i
].ops
->set(val
, ¶ms
[i
]);
145 kernel_param_unlock(params
[i
].mod
);
150 if (handle_unknown
) {
151 pr_debug("doing %s: %s='%s'\n", doing
, param
, val
);
152 return handle_unknown(param
, val
, doing
, arg
);
155 pr_debug("Unknown argument '%s'\n", param
);
159 /* Args looks like "foo=bar,bar2 baz=fuz wiz". */
160 char *parse_args(const char *doing
,
162 const struct kernel_param
*params
,
167 int (*unknown
)(char *param
, char *val
,
168 const char *doing
, void *arg
))
170 char *param
, *val
, *err
= NULL
;
172 /* Chew leading spaces */
173 args
= skip_spaces(args
);
176 pr_debug("doing %s, parsing ARGS: '%s'\n", doing
, args
);
180 int irq_was_disabled
;
182 args
= next_arg(args
, ¶m
, &val
);
184 if (!val
&& strcmp(param
, "--") == 0)
186 irq_was_disabled
= irqs_disabled();
187 ret
= parse_one(param
, val
, doing
, params
, num
,
188 min_level
, max_level
, arg
, unknown
);
189 if (irq_was_disabled
&& !irqs_disabled())
190 pr_warn("%s: option '%s' enabled irq's!\n",
197 pr_err("%s: Unknown parameter `%s'\n", doing
, param
);
200 pr_err("%s: `%s' too large for parameter `%s'\n",
201 doing
, val
?: "", param
);
204 pr_err("%s: `%s' invalid for parameter `%s'\n",
205 doing
, val
?: "", param
);
215 /* Lazy bastard, eh? */
216 #define STANDARD_PARAM_DEF(name, type, format, strtolfn) \
217 int param_set_##name(const char *val, const struct kernel_param *kp) \
219 return strtolfn(val, 0, (type *)kp->arg); \
221 int param_get_##name(char *buffer, const struct kernel_param *kp) \
223 return scnprintf(buffer, PAGE_SIZE, format "\n", \
224 *((type *)kp->arg)); \
226 const struct kernel_param_ops param_ops_##name = { \
227 .set = param_set_##name, \
228 .get = param_get_##name, \
230 EXPORT_SYMBOL(param_set_##name); \
231 EXPORT_SYMBOL(param_get_##name); \
232 EXPORT_SYMBOL(param_ops_##name)
235 STANDARD_PARAM_DEF(byte
, unsigned char, "%hhu", kstrtou8
);
236 STANDARD_PARAM_DEF(short, short, "%hi", kstrtos16
);
237 STANDARD_PARAM_DEF(ushort
, unsigned short, "%hu", kstrtou16
);
238 STANDARD_PARAM_DEF(int, int, "%i", kstrtoint
);
239 STANDARD_PARAM_DEF(uint
, unsigned int, "%u", kstrtouint
);
240 STANDARD_PARAM_DEF(long, long, "%li", kstrtol
);
241 STANDARD_PARAM_DEF(ulong
, unsigned long, "%lu", kstrtoul
);
242 STANDARD_PARAM_DEF(ullong
, unsigned long long, "%llu", kstrtoull
);
244 int param_set_charp(const char *val
, const struct kernel_param
*kp
)
246 if (strlen(val
) > 1024) {
247 pr_err("%s: string parameter too long\n", kp
->name
);
251 maybe_kfree_parameter(*(char **)kp
->arg
);
253 /* This is a hack. We can't kmalloc in early boot, and we
254 * don't need to; this mangled commandline is preserved. */
255 if (slab_is_available()) {
256 *(char **)kp
->arg
= kmalloc_parameter(strlen(val
)+1);
257 if (!*(char **)kp
->arg
)
259 strcpy(*(char **)kp
->arg
, val
);
261 *(const char **)kp
->arg
= val
;
265 EXPORT_SYMBOL(param_set_charp
);
267 int param_get_charp(char *buffer
, const struct kernel_param
*kp
)
269 return scnprintf(buffer
, PAGE_SIZE
, "%s\n", *((char **)kp
->arg
));
271 EXPORT_SYMBOL(param_get_charp
);
273 void param_free_charp(void *arg
)
275 maybe_kfree_parameter(*((char **)arg
));
277 EXPORT_SYMBOL(param_free_charp
);
279 const struct kernel_param_ops param_ops_charp
= {
280 .set
= param_set_charp
,
281 .get
= param_get_charp
,
282 .free
= param_free_charp
,
284 EXPORT_SYMBOL(param_ops_charp
);
286 /* Actually could be a bool or an int, for historical reasons. */
287 int param_set_bool(const char *val
, const struct kernel_param
*kp
)
289 /* No equals means "set"... */
292 /* One of =[yYnN01] */
293 return strtobool(val
, kp
->arg
);
295 EXPORT_SYMBOL(param_set_bool
);
297 int param_get_bool(char *buffer
, const struct kernel_param
*kp
)
299 /* Y and N chosen as being relatively non-coder friendly */
300 return sprintf(buffer
, "%c\n", *(bool *)kp
->arg
? 'Y' : 'N');
302 EXPORT_SYMBOL(param_get_bool
);
304 const struct kernel_param_ops param_ops_bool
= {
305 .flags
= KERNEL_PARAM_OPS_FL_NOARG
,
306 .set
= param_set_bool
,
307 .get
= param_get_bool
,
309 EXPORT_SYMBOL(param_ops_bool
);
311 int param_set_bool_enable_only(const char *val
, const struct kernel_param
*kp
)
315 bool orig_value
= *(bool *)kp
->arg
;
316 struct kernel_param dummy_kp
= *kp
;
318 dummy_kp
.arg
= &new_value
;
320 err
= param_set_bool(val
, &dummy_kp
);
324 /* Don't let them unset it once it's set! */
325 if (!new_value
&& orig_value
)
329 err
= param_set_bool(val
, kp
);
333 EXPORT_SYMBOL_GPL(param_set_bool_enable_only
);
335 const struct kernel_param_ops param_ops_bool_enable_only
= {
336 .flags
= KERNEL_PARAM_OPS_FL_NOARG
,
337 .set
= param_set_bool_enable_only
,
338 .get
= param_get_bool
,
340 EXPORT_SYMBOL_GPL(param_ops_bool_enable_only
);
342 /* This one must be bool. */
343 int param_set_invbool(const char *val
, const struct kernel_param
*kp
)
347 struct kernel_param dummy
;
349 dummy
.arg
= &boolval
;
350 ret
= param_set_bool(val
, &dummy
);
352 *(bool *)kp
->arg
= !boolval
;
355 EXPORT_SYMBOL(param_set_invbool
);
357 int param_get_invbool(char *buffer
, const struct kernel_param
*kp
)
359 return sprintf(buffer
, "%c\n", (*(bool *)kp
->arg
) ? 'N' : 'Y');
361 EXPORT_SYMBOL(param_get_invbool
);
363 const struct kernel_param_ops param_ops_invbool
= {
364 .set
= param_set_invbool
,
365 .get
= param_get_invbool
,
367 EXPORT_SYMBOL(param_ops_invbool
);
369 int param_set_bint(const char *val
, const struct kernel_param
*kp
)
371 /* Match bool exactly, by re-using it. */
372 struct kernel_param boolkp
= *kp
;
378 ret
= param_set_bool(val
, &boolkp
);
383 EXPORT_SYMBOL(param_set_bint
);
385 const struct kernel_param_ops param_ops_bint
= {
386 .flags
= KERNEL_PARAM_OPS_FL_NOARG
,
387 .set
= param_set_bint
,
388 .get
= param_get_int
,
390 EXPORT_SYMBOL(param_ops_bint
);
392 /* We break the rule and mangle the string. */
393 static int param_array(struct module
*mod
,
396 unsigned int min
, unsigned int max
,
397 void *elem
, int elemsize
,
398 int (*set
)(const char *, const struct kernel_param
*kp
),
403 struct kernel_param kp
;
406 /* Get the name right for errors. */
412 /* We expect a comma-separated list of values. */
417 pr_err("%s: can only take %i arguments\n", name
, max
);
420 len
= strcspn(val
, ",");
422 /* nul-terminate and parse */
424 ((char *)val
)[len
] = '\0';
425 check_kparam_locked(mod
);
433 } while (save
== ',');
436 pr_err("%s: needs at least %i arguments\n", name
, min
);
442 static int param_array_set(const char *val
, const struct kernel_param
*kp
)
444 const struct kparam_array
*arr
= kp
->arr
;
445 unsigned int temp_num
;
447 return param_array(kp
->mod
, kp
->name
, val
, 1, arr
->max
, arr
->elem
,
448 arr
->elemsize
, arr
->ops
->set
, kp
->level
,
449 arr
->num
?: &temp_num
);
452 static int param_array_get(char *buffer
, const struct kernel_param
*kp
)
455 const struct kparam_array
*arr
= kp
->arr
;
456 struct kernel_param p
= *kp
;
458 for (i
= off
= 0; i
< (arr
->num
? *arr
->num
: arr
->max
); i
++) {
459 /* Replace \n with comma */
461 buffer
[off
- 1] = ',';
462 p
.arg
= arr
->elem
+ arr
->elemsize
* i
;
463 check_kparam_locked(p
.mod
);
464 ret
= arr
->ops
->get(buffer
+ off
, &p
);
473 static void param_array_free(void *arg
)
476 const struct kparam_array
*arr
= arg
;
479 for (i
= 0; i
< (arr
->num
? *arr
->num
: arr
->max
); i
++)
480 arr
->ops
->free(arr
->elem
+ arr
->elemsize
* i
);
483 const struct kernel_param_ops param_array_ops
= {
484 .set
= param_array_set
,
485 .get
= param_array_get
,
486 .free
= param_array_free
,
488 EXPORT_SYMBOL(param_array_ops
);
490 int param_set_copystring(const char *val
, const struct kernel_param
*kp
)
492 const struct kparam_string
*kps
= kp
->str
;
494 if (strlen(val
)+1 > kps
->maxlen
) {
495 pr_err("%s: string doesn't fit in %u chars.\n",
496 kp
->name
, kps
->maxlen
-1);
499 strcpy(kps
->string
, val
);
502 EXPORT_SYMBOL(param_set_copystring
);
504 int param_get_string(char *buffer
, const struct kernel_param
*kp
)
506 const struct kparam_string
*kps
= kp
->str
;
507 return scnprintf(buffer
, PAGE_SIZE
, "%s\n", kps
->string
);
509 EXPORT_SYMBOL(param_get_string
);
511 const struct kernel_param_ops param_ops_string
= {
512 .set
= param_set_copystring
,
513 .get
= param_get_string
,
515 EXPORT_SYMBOL(param_ops_string
);
517 /* sysfs output in /sys/modules/XYZ/parameters/ */
518 #define to_module_attr(n) container_of(n, struct module_attribute, attr)
519 #define to_module_kobject(n) container_of(n, struct module_kobject, kobj)
521 struct param_attribute
523 struct module_attribute mattr
;
524 const struct kernel_param
*param
;
527 struct module_param_attrs
530 struct attribute_group grp
;
531 struct param_attribute attrs
[0];
535 #define to_param_attr(n) container_of(n, struct param_attribute, mattr)
537 static ssize_t
param_attr_show(struct module_attribute
*mattr
,
538 struct module_kobject
*mk
, char *buf
)
541 struct param_attribute
*attribute
= to_param_attr(mattr
);
543 if (!attribute
->param
->ops
->get
)
546 kernel_param_lock(mk
->mod
);
547 count
= attribute
->param
->ops
->get(buf
, attribute
->param
);
548 kernel_param_unlock(mk
->mod
);
552 #ifdef CONFIG_MODULES
553 #define mod_name(mod) (mod)->name
555 #define mod_name(mod) "unknown"
558 /* sysfs always hands a nul-terminated string in buf. We rely on that. */
559 static ssize_t
param_attr_store(struct module_attribute
*mattr
,
560 struct module_kobject
*mk
,
561 const char *buf
, size_t len
)
564 struct param_attribute
*attribute
= to_param_attr(mattr
);
566 if (!attribute
->param
->ops
->set
)
569 kernel_param_lock(mk
->mod
);
570 if (param_check_unsafe(attribute
->param
, mod_name(mk
->mod
)))
571 err
= attribute
->param
->ops
->set(buf
, attribute
->param
);
574 kernel_param_unlock(mk
->mod
);
581 #ifdef CONFIG_MODULES
584 #define __modinit __init
588 void kernel_param_lock(struct module
*mod
)
590 mutex_lock(KPARAM_MUTEX(mod
));
593 void kernel_param_unlock(struct module
*mod
)
595 mutex_unlock(KPARAM_MUTEX(mod
));
598 EXPORT_SYMBOL(kernel_param_lock
);
599 EXPORT_SYMBOL(kernel_param_unlock
);
602 * add_sysfs_param - add a parameter to sysfs
603 * @mk: struct module_kobject
604 * @kp: the actual parameter definition to add to sysfs
605 * @name: name of parameter
607 * Create a kobject if for a (per-module) parameter if mp NULL, and
608 * create file in sysfs. Returns an error on out of memory. Always cleans up
609 * if there's an error.
611 static __modinit
int add_sysfs_param(struct module_kobject
*mk
,
612 const struct kernel_param
*kp
,
615 struct module_param_attrs
*new_mp
;
616 struct attribute
**new_attrs
;
619 /* We don't bother calling this with invisible parameters. */
623 /* First allocation. */
624 mk
->mp
= kzalloc(sizeof(*mk
->mp
), GFP_KERNEL
);
627 mk
->mp
->grp
.name
= "parameters";
628 /* NULL-terminated attribute array. */
629 mk
->mp
->grp
.attrs
= kzalloc(sizeof(mk
->mp
->grp
.attrs
[0]),
631 /* Caller will cleanup via free_module_param_attrs */
632 if (!mk
->mp
->grp
.attrs
)
636 /* Enlarge allocations. */
637 new_mp
= krealloc(mk
->mp
,
639 sizeof(mk
->mp
->attrs
[0]) * (mk
->mp
->num
+ 1),
645 /* Extra pointer for NULL terminator */
646 new_attrs
= krealloc(mk
->mp
->grp
.attrs
,
647 sizeof(mk
->mp
->grp
.attrs
[0]) * (mk
->mp
->num
+ 2),
651 mk
->mp
->grp
.attrs
= new_attrs
;
653 /* Tack new one on the end. */
654 memset(&mk
->mp
->attrs
[mk
->mp
->num
], 0, sizeof(mk
->mp
->attrs
[0]));
655 sysfs_attr_init(&mk
->mp
->attrs
[mk
->mp
->num
].mattr
.attr
);
656 mk
->mp
->attrs
[mk
->mp
->num
].param
= kp
;
657 mk
->mp
->attrs
[mk
->mp
->num
].mattr
.show
= param_attr_show
;
658 /* Do not allow runtime DAC changes to make param writable. */
659 if ((kp
->perm
& (S_IWUSR
| S_IWGRP
| S_IWOTH
)) != 0)
660 mk
->mp
->attrs
[mk
->mp
->num
].mattr
.store
= param_attr_store
;
662 mk
->mp
->attrs
[mk
->mp
->num
].mattr
.store
= NULL
;
663 mk
->mp
->attrs
[mk
->mp
->num
].mattr
.attr
.name
= (char *)name
;
664 mk
->mp
->attrs
[mk
->mp
->num
].mattr
.attr
.mode
= kp
->perm
;
667 /* Fix up all the pointers, since krealloc can move us */
668 for (i
= 0; i
< mk
->mp
->num
; i
++)
669 mk
->mp
->grp
.attrs
[i
] = &mk
->mp
->attrs
[i
].mattr
.attr
;
670 mk
->mp
->grp
.attrs
[mk
->mp
->num
] = NULL
;
674 #ifdef CONFIG_MODULES
675 static void free_module_param_attrs(struct module_kobject
*mk
)
678 kfree(mk
->mp
->grp
.attrs
);
684 * module_param_sysfs_setup - setup sysfs support for one module
686 * @kparam: module parameters (array)
687 * @num_params: number of module parameters
689 * Adds sysfs entries for module parameters under
690 * /sys/module/[mod->name]/parameters/
692 int module_param_sysfs_setup(struct module
*mod
,
693 const struct kernel_param
*kparam
,
694 unsigned int num_params
)
699 for (i
= 0; i
< num_params
; i
++) {
700 if (kparam
[i
].perm
== 0)
702 err
= add_sysfs_param(&mod
->mkobj
, &kparam
[i
], kparam
[i
].name
);
704 free_module_param_attrs(&mod
->mkobj
);
713 /* Create the param group. */
714 err
= sysfs_create_group(&mod
->mkobj
.kobj
, &mod
->mkobj
.mp
->grp
);
716 free_module_param_attrs(&mod
->mkobj
);
721 * module_param_sysfs_remove - remove sysfs support for one module
724 * Remove sysfs entries for module parameters and the corresponding
727 void module_param_sysfs_remove(struct module
*mod
)
730 sysfs_remove_group(&mod
->mkobj
.kobj
, &mod
->mkobj
.mp
->grp
);
731 /* We are positive that no one is using any param
732 * attrs at this point. Deallocate immediately. */
733 free_module_param_attrs(&mod
->mkobj
);
738 void destroy_params(const struct kernel_param
*params
, unsigned num
)
742 for (i
= 0; i
< num
; i
++)
743 if (params
[i
].ops
->free
)
744 params
[i
].ops
->free(params
[i
].arg
);
747 static struct module_kobject
* __init
locate_module_kobject(const char *name
)
749 struct module_kobject
*mk
;
750 struct kobject
*kobj
;
753 kobj
= kset_find_obj(module_kset
, name
);
755 mk
= to_module_kobject(kobj
);
757 mk
= kzalloc(sizeof(struct module_kobject
), GFP_KERNEL
);
760 mk
->mod
= THIS_MODULE
;
761 mk
->kobj
.kset
= module_kset
;
762 err
= kobject_init_and_add(&mk
->kobj
, &module_ktype
, NULL
,
764 #ifdef CONFIG_MODULES
766 err
= sysfs_create_file(&mk
->kobj
, &module_uevent
.attr
);
769 kobject_put(&mk
->kobj
);
770 pr_crit("Adding module '%s' to sysfs failed (%d), the system may be unstable.\n",
775 /* So that we hold reference in both cases. */
776 kobject_get(&mk
->kobj
);
782 static void __init
kernel_add_sysfs_param(const char *name
,
783 const struct kernel_param
*kparam
,
784 unsigned int name_skip
)
786 struct module_kobject
*mk
;
789 mk
= locate_module_kobject(name
);
793 /* We need to remove old parameters before adding more. */
795 sysfs_remove_group(&mk
->kobj
, &mk
->mp
->grp
);
797 /* These should not fail at boot. */
798 err
= add_sysfs_param(mk
, kparam
, kparam
->name
+ name_skip
);
800 err
= sysfs_create_group(&mk
->kobj
, &mk
->mp
->grp
);
802 kobject_uevent(&mk
->kobj
, KOBJ_ADD
);
803 kobject_put(&mk
->kobj
);
807 * param_sysfs_builtin - add sysfs parameters for built-in modules
809 * Add module_parameters to sysfs for "modules" built into the kernel.
811 * The "module" name (KBUILD_MODNAME) is stored before a dot, the
812 * "parameter" name is stored behind a dot in kernel_param->name. So,
813 * extract the "module" name for all built-in kernel_param-eters,
814 * and for all who have the same, call kernel_add_sysfs_param.
816 static void __init
param_sysfs_builtin(void)
818 const struct kernel_param
*kp
;
819 unsigned int name_len
;
820 char modname
[MODULE_NAME_LEN
];
822 for (kp
= __start___param
; kp
< __stop___param
; kp
++) {
828 dot
= strchr(kp
->name
, '.');
830 /* This happens for core_param() */
831 strcpy(modname
, "kernel");
834 name_len
= dot
- kp
->name
+ 1;
835 strlcpy(modname
, kp
->name
, name_len
);
837 kernel_add_sysfs_param(modname
, kp
, name_len
);
841 ssize_t
__modver_version_show(struct module_attribute
*mattr
,
842 struct module_kobject
*mk
, char *buf
)
844 struct module_version_attribute
*vattr
=
845 container_of(mattr
, struct module_version_attribute
, mattr
);
847 return scnprintf(buf
, PAGE_SIZE
, "%s\n", vattr
->version
);
850 extern const struct module_version_attribute
*__start___modver
[];
851 extern const struct module_version_attribute
*__stop___modver
[];
853 static void __init
version_sysfs_builtin(void)
855 const struct module_version_attribute
**p
;
856 struct module_kobject
*mk
;
859 for (p
= __start___modver
; p
< __stop___modver
; p
++) {
860 const struct module_version_attribute
*vattr
= *p
;
862 mk
= locate_module_kobject(vattr
->module_name
);
864 err
= sysfs_create_file(&mk
->kobj
, &vattr
->mattr
.attr
);
866 kobject_uevent(&mk
->kobj
, KOBJ_ADD
);
867 kobject_put(&mk
->kobj
);
872 /* module-related sysfs stuff */
874 static ssize_t
module_attr_show(struct kobject
*kobj
,
875 struct attribute
*attr
,
878 struct module_attribute
*attribute
;
879 struct module_kobject
*mk
;
882 attribute
= to_module_attr(attr
);
883 mk
= to_module_kobject(kobj
);
885 if (!attribute
->show
)
888 ret
= attribute
->show(attribute
, mk
, buf
);
893 static ssize_t
module_attr_store(struct kobject
*kobj
,
894 struct attribute
*attr
,
895 const char *buf
, size_t len
)
897 struct module_attribute
*attribute
;
898 struct module_kobject
*mk
;
901 attribute
= to_module_attr(attr
);
902 mk
= to_module_kobject(kobj
);
904 if (!attribute
->store
)
907 ret
= attribute
->store(attribute
, mk
, buf
, len
);
912 static const struct sysfs_ops module_sysfs_ops
= {
913 .show
= module_attr_show
,
914 .store
= module_attr_store
,
917 static int uevent_filter(struct kset
*kset
, struct kobject
*kobj
)
919 struct kobj_type
*ktype
= get_ktype(kobj
);
921 if (ktype
== &module_ktype
)
926 static const struct kset_uevent_ops module_uevent_ops
= {
927 .filter
= uevent_filter
,
930 struct kset
*module_kset
;
931 int module_sysfs_initialized
;
933 static void module_kobj_release(struct kobject
*kobj
)
935 struct module_kobject
*mk
= to_module_kobject(kobj
);
936 complete(mk
->kobj_completion
);
939 struct kobj_type module_ktype
= {
940 .release
= module_kobj_release
,
941 .sysfs_ops
= &module_sysfs_ops
,
945 * param_sysfs_init - wrapper for built-in params support
947 static int __init
param_sysfs_init(void)
949 module_kset
= kset_create_and_add("module", &module_uevent_ops
, NULL
);
951 printk(KERN_WARNING
"%s (%d): error creating kset\n",
955 module_sysfs_initialized
= 1;
957 version_sysfs_builtin();
958 param_sysfs_builtin();
962 subsys_initcall(param_sysfs_init
);
964 #endif /* CONFIG_SYSFS */