Commit f30c53a8 authored by Kay Sievers's avatar Kay Sievers Committed by Greg Kroah-Hartman

MODULES: add the module name for built in kernel drivers

Signed-off-by: default avatarKay Sievers <kay.sievers@vrfy.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent c744aeae
...@@ -126,6 +126,7 @@ struct device_driver { ...@@ -126,6 +126,7 @@ struct device_driver {
struct klist_node knode_bus; struct klist_node knode_bus;
struct module * owner; struct module * owner;
const char * mod_name; /* used for built-in modules */
int (*probe) (struct device * dev); int (*probe) (struct device * dev);
int (*remove) (struct device * dev); int (*remove) (struct device * dev);
......
...@@ -58,6 +58,7 @@ struct module_kobject ...@@ -58,6 +58,7 @@ struct module_kobject
{ {
struct kobject kobj; struct kobject kobj;
struct module *mod; struct module *mod;
struct kobject *drivers_dir;
}; };
/* These are either module local, or the kernel's dummy ones. */ /* These are either module local, or the kernel's dummy ones. */
...@@ -263,7 +264,6 @@ struct module ...@@ -263,7 +264,6 @@ struct module
struct module_attribute *modinfo_attrs; struct module_attribute *modinfo_attrs;
const char *version; const char *version;
const char *srcversion; const char *srcversion;
struct kobject *drivers_dir;
/* Exported symbols */ /* Exported symbols */
const struct kernel_symbol *syms; const struct kernel_symbol *syms;
......
...@@ -1131,8 +1131,8 @@ static int mod_sysfs_setup(struct module *mod, ...@@ -1131,8 +1131,8 @@ static int mod_sysfs_setup(struct module *mod,
if (err) if (err)
goto out; goto out;
mod->drivers_dir = kobject_add_dir(&mod->mkobj.kobj, "drivers"); mod->mkobj.drivers_dir = kobject_add_dir(&mod->mkobj.kobj, "drivers");
if (!mod->drivers_dir) { if (!mod->mkobj.drivers_dir) {
err = -ENOMEM; err = -ENOMEM;
goto out_unreg; goto out_unreg;
} }
...@@ -1151,7 +1151,7 @@ static int mod_sysfs_setup(struct module *mod, ...@@ -1151,7 +1151,7 @@ static int mod_sysfs_setup(struct module *mod,
out_unreg_param: out_unreg_param:
module_param_sysfs_remove(mod); module_param_sysfs_remove(mod);
out_unreg_drivers: out_unreg_drivers:
kobject_unregister(mod->drivers_dir); kobject_unregister(mod->mkobj.drivers_dir);
out_unreg: out_unreg:
kobject_del(&mod->mkobj.kobj); kobject_del(&mod->mkobj.kobj);
kobject_put(&mod->mkobj.kobj); kobject_put(&mod->mkobj.kobj);
...@@ -1163,7 +1163,7 @@ static void mod_kobject_remove(struct module *mod) ...@@ -1163,7 +1163,7 @@ static void mod_kobject_remove(struct module *mod)
{ {
module_remove_modinfo_attrs(mod); module_remove_modinfo_attrs(mod);
module_param_sysfs_remove(mod); module_param_sysfs_remove(mod);
kobject_unregister(mod->drivers_dir); kobject_unregister(mod->mkobj.drivers_dir);
kobject_unregister(&mod->mkobj.kobj); kobject_unregister(&mod->mkobj.kobj);
} }
...@@ -2344,15 +2344,30 @@ void module_add_driver(struct module *mod, struct device_driver *drv) ...@@ -2344,15 +2344,30 @@ void module_add_driver(struct module *mod, struct device_driver *drv)
{ {
char *driver_name; char *driver_name;
int no_warn; int no_warn;
struct module_kobject *mk = NULL;
if (!mod || !drv) if (!drv)
return;
if (mod)
mk = &mod->mkobj;
else if (drv->mod_name) {
struct kobject *mkobj;
/* Lookup built-in module entry in /sys/modules */
mkobj = kset_find_obj(&module_subsys.kset, drv->mod_name);
if (mkobj)
mk = container_of(mkobj, struct module_kobject, kobj);
}
if (!mk)
return; return;
/* Don't check return codes; these calls are idempotent */ /* Don't check return codes; these calls are idempotent */
no_warn = sysfs_create_link(&drv->kobj, &mod->mkobj.kobj, "module"); no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module");
driver_name = make_driver_name(drv); driver_name = make_driver_name(drv);
if (driver_name) { if (driver_name) {
no_warn = sysfs_create_link(mod->drivers_dir, &drv->kobj, no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj,
driver_name); driver_name);
kfree(driver_name); kfree(driver_name);
} }
...@@ -2367,10 +2382,10 @@ void module_remove_driver(struct device_driver *drv) ...@@ -2367,10 +2382,10 @@ void module_remove_driver(struct device_driver *drv)
return; return;
sysfs_remove_link(&drv->kobj, "module"); sysfs_remove_link(&drv->kobj, "module");
if (drv->owner && drv->owner->drivers_dir) { if (drv->owner && drv->owner->mkobj.drivers_dir) {
driver_name = make_driver_name(drv); driver_name = make_driver_name(drv);
if (driver_name) { if (driver_name) {
sysfs_remove_link(drv->owner->drivers_dir, sysfs_remove_link(drv->owner->mkobj.drivers_dir,
driver_name); driver_name);
kfree(driver_name); kfree(driver_name);
} }
......
...@@ -561,14 +561,12 @@ static void __init kernel_param_sysfs_setup(const char *name, ...@@ -561,14 +561,12 @@ static void __init kernel_param_sysfs_setup(const char *name,
mk->mod = THIS_MODULE; mk->mod = THIS_MODULE;
kobj_set_kset_s(mk, module_subsys); kobj_set_kset_s(mk, module_subsys);
kobject_set_name(&mk->kobj, name); kobject_set_name(&mk->kobj, name);
ret = kobject_register(&mk->kobj); kobject_init(&mk->kobj);
ret = kobject_add(&mk->kobj);
BUG_ON(ret < 0); BUG_ON(ret < 0);
param_sysfs_setup(mk, kparam, num_params, name_skip);
/* no need to keep the kobject if no parameter is exported */ mk->drivers_dir = kobject_add_dir(&mk->kobj, "drivers");
if (!param_sysfs_setup(mk, kparam, num_params, name_skip)) { kobject_uevent(&mk->kobj, KOBJ_ADD);
kobject_unregister(&mk->kobj);
kfree(mk);
}
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment