From: Kay Sievers <[email protected]> Show the drivers, which belong to the module: $ ls -l /sys/module/usbcore/drivers/ hub -> ../../../bus/usb/drivers/hub usb -> ../../../bus/usb/drivers/usb usbfs -> ../../../bus/usb/drivers/usbfs Signed-off-by: Kay Sievers <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> --- include/linux/module.h | 1 + kernel/module.c | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index d1d00ce..9258ffd 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -264,6 +264,7 @@ struct module struct module_attribute *modinfo_attrs; const char *version; const char *srcversion; + struct kobject *drivers_dir; /* Exported symbols */ const struct kernel_symbol *syms; diff --git a/kernel/module.c b/kernel/module.c index f016656..45e01cb 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1086,22 +1086,35 @@ static int mod_sysfs_setup(struct module goto out; kobj_set_kset_s(&mod->mkobj, module_subsys); mod->mkobj.mod = mod; - err = kobject_register(&mod->mkobj.kobj); + + /* delay uevent until full sysfs population */ + kobject_init(&mod->mkobj.kobj); + err = kobject_add(&mod->mkobj.kobj); if (err) goto out; + mod->drivers_dir = kobject_add_dir(&mod->mkobj.kobj, "drivers"); + if (!mod->drivers_dir) + goto out_unreg; + err = module_param_sysfs_setup(mod, kparam, num_params); if (err) - goto out_unreg; + goto out_unreg_drivers; err = module_add_modinfo_attrs(mod); if (err) - goto out_unreg; + goto out_unreg_param; + kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); return 0; +out_unreg_drivers: + kobject_unregister(mod->drivers_dir); +out_unreg_param: + module_param_sysfs_remove(mod); out_unreg: - kobject_unregister(&mod->mkobj.kobj); + kobject_del(&mod->mkobj.kobj); + kobject_put(&mod->mkobj.kobj); out: return err; } @@ -1110,6 +1123,7 @@ static void mod_kobject_remove(struct mo { module_remove_modinfo_attrs(mod); module_param_sysfs_remove(mod); + kobject_unregister(mod->drivers_dir); kobject_unregister(&mod->mkobj.kobj); } @@ -2275,11 +2289,14 @@ void print_modules(void) void module_add_driver(struct module *mod, struct device_driver *drv) { + int no_warn; + if (!mod || !drv) return; - /* Don't check return code; this call is idempotent */ - sysfs_create_link(&drv->kobj, &mod->mkobj.kobj, "module"); + /* 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(mod->drivers_dir, &drv->kobj, drv->name); } EXPORT_SYMBOL(module_add_driver); @@ -2288,6 +2305,8 @@ void module_remove_driver(struct device_ if (!drv) return; sysfs_remove_link(&drv->kobj, "module"); + if (drv->owner && drv->owner->drivers_dir) + sysfs_remove_link(drv->owner->drivers_dir, drv->name); } EXPORT_SYMBOL(module_remove_driver); -- 1.4.4.1 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
- References:
- [GIT PATCH] Driver core patches for 2.6.19
- From: Greg KH <[email protected]>
- [PATCH 1/36] Driver core: add notification of bus events
- From: Greg KH <[email protected]>
- [PATCH 2/36] Driver core: fix "driver" symlink timing
- From: Greg KH <[email protected]>
- [PATCH 3/36] Driver Core: Move virtual_device_parent() to core.c
- From: Greg KH <[email protected]>
- [PATCH 4/36] CONFIG_SYSFS_DEPRECATED
- From: Greg KH <[email protected]>
- [PATCH 5/36] Driver core: make old versions of udev work properly
- From: Greg KH <[email protected]>
- [PATCH 6/36] CONFIG_SYSFS_DEPRECATED - bus symlinks
- From: Greg KH <[email protected]>
- [PATCH 7/36] CONFIG_SYSFS_DEPRECATED - device symlinks
- From: Greg KH <[email protected]>
- [PATCH 8/36] CONFIG_SYSFS_DEPRECATED - PHYSDEV* uevent variables
- From: Greg KH <[email protected]>
- [PATCH 9/36] CONFIG_SYSFS_DEPRECATED - class symlinks
- From: Greg KH <[email protected]>
- [PATCH 10/36] Driver core: convert vt code to use struct device
- From: Greg KH <[email protected]>
- [PATCH 11/36] Driver core: convert vc code to use struct device
- From: Greg KH <[email protected]>
- [PATCH 12/36] Driver core: change misc class_devices to be real devices
- From: Greg KH <[email protected]>
- [PATCH 13/36] Driver core: convert tty core to use struct device
- From: Greg KH <[email protected]>
- [PATCH 14/36] Driver core: convert raw device code to use struct device
- From: Greg KH <[email protected]>
- [PATCH 15/36] I2C: convert i2c-dev to use struct device instead of struct class_device
- From: Greg KH <[email protected]>
- [PATCH 16/36] Driver core: convert msr code to use struct device
- From: Greg KH <[email protected]>
- [PATCH 17/36] Driver core: convert cpuid code to use struct device
- From: Greg KH <[email protected]>
- [PATCH 18/36] Driver core: convert PPP code to use struct device
- From: Greg KH <[email protected]>
- [PATCH 19/36] Driver core: convert ppdev code to use struct device
- From: Greg KH <[email protected]>
- [PATCH 20/36] Driver core: convert mmc code to use struct device
- From: Greg KH <[email protected]>
- [PATCH 22/36] Driver core: convert fb code to use struct device
- From: Greg KH <[email protected]>
- [PATCH 23/36] Driver core: change mem class_devices to be real devices
- From: Greg KH <[email protected]>
- [PATCH 24/36] Driver core: convert sound core to use struct device
- From: Greg KH <[email protected]>
- [PATCH 25/36] Driver core: add dev_archdata to struct device
- From: Greg KH <[email protected]>
- [PATCH 26/36] ACPI: Change ACPI to use dev_archdata instead of firmware_data
- From: Greg KH <[email protected]>
- [PATCH 27/36] Driver core: Call platform_notify_remove later
- From: Greg KH <[email protected]>
- [PATCH 28/36] cpu topology: consider sysfs_create_group return value
- From: Greg KH <[email protected]>
- [PATCH 29/36] sysfs: sysfs_write_file() writes zero terminated data
- From: Greg KH <[email protected]>
- [PATCH 30/36] driver core: Introduce device_find_child().
- From: Greg KH <[email protected]>
- [PATCH 31/36] Driver core: make drivers/base/core.c:setup_parent() static
- From: Greg KH <[email protected]>
- [PATCH 32/36] driver core: Introduce device_move(): move a device to a new parent.
- From: Greg KH <[email protected]>
- [PATCH 33/36] driver core: Use klist_remove() in device_move()
- From: Greg KH <[email protected]>
- [PATCH 34/36] Driver core: platform_driver_probe(), can save codespace
- From: Greg KH <[email protected]>
- [PATCH 35/36] Documentation/driver-model/platform.txt update/rewrite
- From: Greg KH <[email protected]>
- [GIT PATCH] Driver core patches for 2.6.19
- Prev by Date: [PATCH 14/36] Driver core: convert raw device code to use struct device
- Next by Date: [PATCH 29/36] sysfs: sysfs_write_file() writes zero terminated data
- Previous by thread: [PATCH 35/36] Documentation/driver-model/platform.txt update/rewrite
- Next by thread: Re: [PATCH 32/36] driver core: Introduce device_move(): move a device to a new parent.
- Index(es):