Skip to content

Commit 3929527

Browse files
committed
Merge tag 'modules-6.15-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux
Pull modules fixes from Petr Pavlu: "A single series to properly handle the module_kobject creation. This fixes a problem with missing /sys/module/<module>/drivers for built-in modules" * tag 'modules-6.15-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux: drivers: base: handle module_kobject creation kernel: globalize lookup_or_create_module_kobject() kernel: refactor lookup_or_create_module_kobject() kernel: param: rename locate_module_kobject
2 parents b6ea168 + f95bbfe commit 3929527

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

drivers/base/module.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,13 @@ int module_add_driver(struct module *mod, const struct device_driver *drv)
4242
if (mod)
4343
mk = &mod->mkobj;
4444
else if (drv->mod_name) {
45-
struct kobject *mkobj;
46-
47-
/* Lookup built-in module entry in /sys/modules */
48-
mkobj = kset_find_obj(module_kset, drv->mod_name);
49-
if (mkobj) {
50-
mk = container_of(mkobj, struct module_kobject, kobj);
45+
/* Lookup or create built-in module entry in /sys/modules */
46+
mk = lookup_or_create_module_kobject(drv->mod_name);
47+
if (mk) {
5148
/* remember our module structure */
5249
drv->p->mkobj = mk;
53-
/* kset_find_obj took a reference */
54-
kobject_put(mkobj);
50+
/* lookup_or_create_module_kobject took a reference */
51+
kobject_put(&mk->kobj);
5552
}
5653
}
5754

include/linux/module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ extern void cleanup_module(void);
162162
#define __INITRODATA_OR_MODULE __INITRODATA
163163
#endif /*CONFIG_MODULES*/
164164

165+
struct module_kobject *lookup_or_create_module_kobject(const char *name);
166+
165167
/* Generic info of form tag = "info" */
166168
#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
167169

kernel/params.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -760,38 +760,35 @@ void destroy_params(const struct kernel_param *params, unsigned num)
760760
params[i].ops->free(params[i].arg);
761761
}
762762

763-
static struct module_kobject * __init locate_module_kobject(const char *name)
763+
struct module_kobject __modinit * lookup_or_create_module_kobject(const char *name)
764764
{
765765
struct module_kobject *mk;
766766
struct kobject *kobj;
767767
int err;
768768

769769
kobj = kset_find_obj(module_kset, name);
770-
if (kobj) {
771-
mk = to_module_kobject(kobj);
772-
} else {
773-
mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL);
774-
BUG_ON(!mk);
775-
776-
mk->mod = THIS_MODULE;
777-
mk->kobj.kset = module_kset;
778-
err = kobject_init_and_add(&mk->kobj, &module_ktype, NULL,
779-
"%s", name);
780-
#ifdef CONFIG_MODULES
781-
if (!err)
782-
err = sysfs_create_file(&mk->kobj, &module_uevent.attr);
783-
#endif
784-
if (err) {
785-
kobject_put(&mk->kobj);
786-
pr_crit("Adding module '%s' to sysfs failed (%d), the system may be unstable.\n",
787-
name, err);
788-
return NULL;
789-
}
770+
if (kobj)
771+
return to_module_kobject(kobj);
790772

791-
/* So that we hold reference in both cases. */
792-
kobject_get(&mk->kobj);
773+
mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL);
774+
if (!mk)
775+
return NULL;
776+
777+
mk->mod = THIS_MODULE;
778+
mk->kobj.kset = module_kset;
779+
err = kobject_init_and_add(&mk->kobj, &module_ktype, NULL, "%s", name);
780+
if (IS_ENABLED(CONFIG_MODULES) && !err)
781+
err = sysfs_create_file(&mk->kobj, &module_uevent.attr);
782+
if (err) {
783+
kobject_put(&mk->kobj);
784+
pr_crit("Adding module '%s' to sysfs failed (%d), the system may be unstable.\n",
785+
name, err);
786+
return NULL;
793787
}
794788

789+
/* So that we hold reference in both cases. */
790+
kobject_get(&mk->kobj);
791+
795792
return mk;
796793
}
797794

@@ -802,7 +799,7 @@ static void __init kernel_add_sysfs_param(const char *name,
802799
struct module_kobject *mk;
803800
int err;
804801

805-
mk = locate_module_kobject(name);
802+
mk = lookup_or_create_module_kobject(name);
806803
if (!mk)
807804
return;
808805

@@ -873,7 +870,7 @@ static void __init version_sysfs_builtin(void)
873870
int err;
874871

875872
for (vattr = __start___modver; vattr < __stop___modver; vattr++) {
876-
mk = locate_module_kobject(vattr->module_name);
873+
mk = lookup_or_create_module_kobject(vattr->module_name);
877874
if (mk) {
878875
err = sysfs_create_file(&mk->kobj, &vattr->mattr.attr);
879876
WARN_ON_ONCE(err);

0 commit comments

Comments
 (0)