719 lines · 16.7 KB · C
RawDownload
 * @mod: module * @kparam: module parameters (array) * @num_params: number of module parameters * * Adds sysfs entries for module parameters, and creates a link from * /sys/module/[mod->name]/parameters to /sys/parameters/[mod->name]/ */int module_param_sysfs_setup(struct module *mod,			     struct kernel_param *kparam,			     unsigned int num_params){	struct module_param_attrs *mp; 	mp = param_sysfs_setup(&mod->mkobj, kparam, num_params, 0);	if (IS_ERR(mp))		return PTR_ERR(mp); 	mod->param_attrs = mp;	return 0;} /* * module_param_sysfs_remove - remove sysfs support for one module * @mod: module * * Remove sysfs entries for module parameters and the corresponding * kobject. */void module_param_sysfs_remove(struct module *mod){	if (mod->param_attrs) {		sysfs_remove_group(&mod->mkobj.kobj,				   &mod->param_attrs->grp);		/* We are positive that no one is using any param		 * attrs at this point.  Deallocate immediately. */		kfree(mod->param_attrs);		mod->param_attrs = NULL;	}}#endif /* * kernel_param_sysfs_setup - wrapper for built-in params support */static void __init kernel_param_sysfs_setup(const char *name,					    struct kernel_param *kparam,					    unsigned int num_params,					    unsigned int name_skip){	struct module_kobject *mk; 	mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL);	BUG_ON(!mk); 	mk->mod = THIS_MODULE;	kobj_set_kset_s(mk, module_subsys);	kobject_set_name(&mk->kobj, name);	kobject_register(&mk->kobj); 	/* no need to keep the kobject if no parameter is exported */	if (!param_sysfs_setup(mk, kparam, num_params, name_skip)) {		kobject_unregister(&mk->kobj);		kfree(mk);	}} /* * param_sysfs_builtin - add contents in /sys/parameters for built-in modules * * Add module_parameters to sysfs for "modules" built into the kernel. * * The "module" name (KBUILD_MODNAME) is stored before a dot, the * "parameter" name is stored behind a dot in kernel_param->name. So, * extract the "module" name for all built-in kernel_param-eters, * and for all who have the same, call kernel_param_sysfs_setup. */static void __init param_sysfs_builtin(void){	struct kernel_param *kp, *kp_begin = NULL;	unsigned int i, name_len, count = 0;	char modname[MAX_KBUILD_MODNAME + 1] = ""; 	for (i=0; i < __stop___param - __start___param; i++) {		char *dot; 		kp = &__start___param[i]; 		/* We do not handle args without periods. */		dot = memchr(kp->name, '.', MAX_KBUILD_MODNAME);		if (!dot) {			DEBUGP("couldn't find period in %s\n", kp->name);			continue;		}		name_len = dot - kp->name;  		/* new kbuild_modname? */		if (strlen(modname) != name_len		    || strncmp(modname, kp->name, name_len) != 0) {			/* add a new kobject for previous kernel_params. */			if (count)				kernel_param_sysfs_setup(modname,							 kp_begin,							 count,							 strlen(modname)+1); 			strncpy(modname, kp->name, name_len);			modname[name_len] = '\0';			count = 0;			kp_begin = kp;		}		count++;	} 	/* last kernel_params need to be registered as well */	if (count)		kernel_param_sysfs_setup(modname, kp_begin, count,					 strlen(modname)+1);}  /* module-related sysfs stuff */#ifdef CONFIG_SYSFS #define to_module_attr(n) container_of(n, struct module_attribute, attr);#define to_module_kobject(n) container_of(n, struct module_kobject, kobj); static ssize_t module_attr_show(struct kobject *kobj,				struct attribute *attr,				char *buf){	struct module_attribute *attribute;	struct module_kobject *mk;	int ret; 	attribute = to_module_attr(attr);	mk = to_module_kobject(kobj); 	if (!attribute->show)		return -EIO; 	ret = attribute->show(attribute, mk->mod, buf); 	return ret;} static ssize_t module_attr_store(struct kobject *kobj,				struct attribute *attr,				const char *buf, size_t len){	struct module_attribute *attribute;	struct module_kobject *mk;	int ret; 	attribute = to_module_attr(attr);	mk = to_module_kobject(kobj); 	if (!attribute->store)		return -EIO; 	ret = attribute->store(attribute, mk->mod, buf, len); 	return ret;} static struct sysfs_ops module_sysfs_ops = {	.show = module_attr_show,	.store = module_attr_store,}; #elsestatic struct sysfs_ops module_sysfs_ops = {	.show = NULL,	.store = NULL,};#endif static struct kobj_type module_ktype = {	.sysfs_ops =	&module_sysfs_ops,}; decl_subsys(module, &module_ktype, NULL); /* * param_sysfs_init - wrapper for built-in params support */static int __init param_sysfs_init(void){	subsystem_register(&module_subsys); 	param_sysfs_builtin(); 	return 0;}__initcall(param_sysfs_init); EXPORT_SYMBOL(param_set_byte);EXPORT_SYMBOL(param_get_byte);EXPORT_SYMBOL(param_set_short);EXPORT_SYMBOL(param_get_short);EXPORT_SYMBOL(param_set_ushort);EXPORT_SYMBOL(param_get_ushort);EXPORT_SYMBOL(param_set_int);EXPORT_SYMBOL(param_get_int);EXPORT_SYMBOL(param_set_uint);EXPORT_SYMBOL(param_get_uint);EXPORT_SYMBOL(param_set_long);EXPORT_SYMBOL(param_get_long);EXPORT_SYMBOL(param_set_ulong);EXPORT_SYMBOL(param_get_ulong);EXPORT_SYMBOL(param_set_charp);EXPORT_SYMBOL(param_get_charp);EXPORT_SYMBOL(param_set_bool);EXPORT_SYMBOL(param_get_bool);EXPORT_SYMBOL(param_set_invbool);EXPORT_SYMBOL(param_get_invbool);EXPORT_SYMBOL(param_array_set);EXPORT_SYMBOL(param_array_get);EXPORT_SYMBOL(param_set_copystring);EXPORT_SYMBOL(param_get_string);

Lines 501–719 of 719. Previous lines

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t