LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Re: [PATCH 8/28] Modules: only add drivers/ direcory if needed
@ 2007-02-14 20:03 Mariusz Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Mariusz Kozlowski @ 2007-02-14 20:03 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel

Hello, 

> @@ -1163,7 +1155,8 @@ static void mod_kobject_remove(struct module *mod)
>  {
>         module_remove_modinfo_attrs(mod);
>         module_param_sysfs_remove(mod);
> -       kobject_unregister(mod->mkobj.drivers_dir);
> +       if (mod->mkobj.drivers_dir)
> +               kobject_unregister(mod->mkobj.drivers_dir);
>  
>         kobject_unregister(&mod->mkobj.kobj);
>  }

This change looks superfluous on top of patch 1/28 where you'll find

 void kobject_unregister(struct kobject * kobj)
 {
+       if (!kobj)
+               return;

I went a bit further and prepared a patch removing all redundant
kobject_unregister argument checks.



Signed-off-by: Mariusz Kozlowski <m.kozlowski@tuxland.pl>

 drivers/base/class.c  |    3 +--
 fs/partitions/check.c |    9 +++------
 kernel/module.c       |    8 ++------
 3 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 96def1d..1417e5c 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -163,8 +163,7 @@ int class_register(struct class * cls)
 void class_unregister(struct class * cls)
 {
 	pr_debug("device class '%s': unregistering\n", cls->name);
-	if (cls->virtual_dir)
-		kobject_unregister(cls->virtual_dir);
+	kobject_unregister(cls->virtual_dir);
 	remove_class_attrs(cls);
 	subsystem_unregister(&cls->subsys);
 }
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index ac32a2e..22d38ff 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -358,8 +358,7 @@ void delete_partition(struct gendisk *disk, int part)
 	p->ios[0] = p->ios[1] = 0;
 	p->sectors[0] = p->sectors[1] = 0;
 	sysfs_remove_link(&p->kobj, "subsystem");
-	if (p->holder_dir)
-		kobject_unregister(p->holder_dir);
+	kobject_unregister(p->holder_dir);
 	kobject_uevent(&p->kobj, KOBJ_REMOVE);
 	kobject_del(&p->kobj);
 	kobject_put(&p->kobj);
@@ -603,10 +602,8 @@ void del_gendisk(struct gendisk *disk)
 	disk->stamp = 0;

 	kobject_uevent(&disk->kobj, KOBJ_REMOVE);
-	if (disk->holder_dir)
-		kobject_unregister(disk->holder_dir);
-	if (disk->slave_dir)
-		kobject_unregister(disk->slave_dir);
+	kobject_unregister(disk->holder_dir);
+	kobject_unregister(disk->slave_dir);
 	if (disk->driverfs_dev) {
 		char *disk_name = make_block_name(disk);
 		sysfs_remove_link(&disk->kobj, "device");
diff --git a/kernel/module.c b/kernel/module.c
index 8a94e05..53f10e8 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1174,11 +1174,8 @@ static void mod_kobject_remove(struct module *mod)
 {
 	module_remove_modinfo_attrs(mod);
 	module_param_sysfs_remove(mod);
-	if (mod->mkobj.drivers_dir)
-		kobject_unregister(mod->mkobj.drivers_dir);
-	if (mod->holders_dir)
-		kobject_unregister(mod->holders_dir);
-
+	kobject_unregister(mod->mkobj.drivers_dir);
+	kobject_unregister(mod->holders_dir);
 	kobject_unregister(&mod->mkobj.kobj);
 }

--
1.4.4.4

Regards,

	Mariusz Kozłowski

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 8/28] Modules: only add drivers/ direcory if needed
  2007-02-08  0:29             ` [PATCH 7/28] MODULES: add the module name for built in kernel drivers Greg KH
@ 2007-02-08  0:29               ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2007-02-08  0:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman

From: Greg Kroah-Hartman <gregkh@suse.de>

This changes the module core to only create the drivers/ directory if we
are going to put something in it.

Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 kernel/module.c |   20 +++++++++++---------
 kernel/params.c |    1 -
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 0f4489a..9de4209 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1131,12 +1131,6 @@ static int mod_sysfs_setup(struct module *mod,
 	if (err)
 		goto out;
 
-	mod->mkobj.drivers_dir = kobject_add_dir(&mod->mkobj.kobj, "drivers");
-	if (!mod->mkobj.drivers_dir) {
-		err = -ENOMEM;
-		goto out_unreg;
-	}
-
 	err = module_param_sysfs_setup(mod, kparam, num_params);
 	if (err)
 		goto out_unreg_drivers;
@@ -1151,8 +1145,6 @@ static int mod_sysfs_setup(struct module *mod,
 out_unreg_param:
 	module_param_sysfs_remove(mod);
 out_unreg_drivers:
-	kobject_unregister(mod->mkobj.drivers_dir);
-out_unreg:
 	kobject_del(&mod->mkobj.kobj);
 	kobject_put(&mod->mkobj.kobj);
 out:
@@ -1163,7 +1155,8 @@ static void mod_kobject_remove(struct module *mod)
 {
 	module_remove_modinfo_attrs(mod);
 	module_param_sysfs_remove(mod);
-	kobject_unregister(mod->mkobj.drivers_dir);
+	if (mod->mkobj.drivers_dir)
+		kobject_unregister(mod->mkobj.drivers_dir);
 
 	kobject_unregister(&mod->mkobj.kobj);
 }
@@ -2340,6 +2333,14 @@ static char *make_driver_name(struct device_driver *drv)
 	return driver_name;
 }
 
+static void module_create_drivers_dir(struct module_kobject *mk)
+{
+	if (!mk || mk->drivers_dir)
+		return;
+
+	mk->drivers_dir = kobject_add_dir(&mk->kobj, "drivers");
+}
+
 void module_add_driver(struct module *mod, struct device_driver *drv)
 {
 	char *driver_name;
@@ -2367,6 +2368,7 @@ void module_add_driver(struct module *mod, struct device_driver *drv)
 	no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module");
 	driver_name = make_driver_name(drv);
 	if (driver_name) {
+		module_create_drivers_dir(mk);
 		no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj,
 					    driver_name);
 		kfree(driver_name);
diff --git a/kernel/params.c b/kernel/params.c
index 737b7c5..cbaac85 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -565,7 +565,6 @@ static void __init kernel_param_sysfs_setup(const char *name,
 	ret = kobject_add(&mk->kobj);
 	BUG_ON(ret < 0);
 	param_sysfs_setup(mk, kparam, num_params, name_skip);
-	mk->drivers_dir = kobject_add_dir(&mk->kobj, "drivers");
 	kobject_uevent(&mk->kobj, KOBJ_ADD);
 }
 
-- 
1.4.4.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-02-14 20:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-14 20:03 [PATCH 8/28] Modules: only add drivers/ direcory if needed Mariusz Kozlowski
  -- strict thread matches above, loose matches on Subject: below --
2007-02-08  0:29 [GIT PATCH] Driver core patches for 2.6.20 Greg KH
2007-02-08  0:29 ` [PATCH 1/28] Kobject: make kobject apis more robust in handling NULL pointers Greg KH
2007-02-08  0:29   ` [PATCH 2/28] Driver core: convert pcmcia code to use struct device Greg KH
2007-02-08  0:29     ` [PATCH 3/28] Driver core: convert SPI " Greg KH
2007-02-08  0:29       ` [PATCH 4/28] Network: convert network devices to use struct device instead of class_device Greg KH
2007-02-08  0:29         ` [PATCH 5/28] driver core: Remove device_is_registered() in device_move() Greg KH
2007-02-08  0:29           ` [PATCH 6/28] driver core: Allow device_move(dev, NULL) Greg KH
2007-02-08  0:29             ` [PATCH 7/28] MODULES: add the module name for built in kernel drivers Greg KH
2007-02-08  0:29               ` [PATCH 8/28] Modules: only add drivers/ direcory if needed Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).