mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [Patch -mm 3/3] RFC: Introduce kobject->owner for refcounting.
@ 2007-04-16 17:36 Cornelia Huck
  2007-04-16 18:05 ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Cornelia Huck @ 2007-04-16 17:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: Alan Stern, Greg K-H, Tejun Heo, Rusty Russell

Grab and release the module kobject refcount if kobj->owner is set.
This prevents calls to the release function after the module has
been unloaded.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>

---
 include/linux/kobject.h |    1 +
 lib/kobject.c           |    6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

--- linux-2.6.orig/include/linux/kobject.h
+++ linux-2.6/include/linux/kobject.h
@@ -51,6 +51,7 @@ enum kobject_action {
 };
 
 struct kobject {
+	struct module		* owner;
 	const char		* k_name;
 	char			name[KOBJ_NAME_LEN];
 	struct kref		kref;
--- linux-2.6.orig/lib/kobject.c
+++ linux-2.6/lib/kobject.c
@@ -177,6 +177,8 @@ void kobject_init(struct kobject * kobj)
 	INIT_LIST_HEAD(&kobj->entry);
 	init_waitqueue_head(&kobj->poll);
 	kobj->kset = kset_get(kobj->kset);
+	/* Attempt to grab reference of owning module's kobject. */
+	mod_kobject_get(kobj->owner);
 }
 
 
@@ -254,6 +256,7 @@ int kobject_shadow_add(struct kobject * 
 			printk("kobject_add failed for %s (%d)\n",
 			       kobject_name(kobj), error);
 		 dump_stack();
+		 mod_kobject_put(kobj->owner);
 	}
 
 	return error;
@@ -491,6 +494,7 @@ void kobject_cleanup(struct kobject * ko
 	struct kobj_type * t = get_ktype(kobj);
 	struct kset * s = kobj->kset;
 	struct kobject * parent = kobj->parent;
+	struct module * owner = kobj->owner;
 
 	pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
 	if (kobj->k_name != kobj->name)
@@ -503,7 +507,7 @@ void kobject_cleanup(struct kobject * ko
 			"if this is not a directory kobject, it is broken "
 			"and must be fixed.\n",
 			kobj->name);
-
+	mod_kobject_put(owner);
 	if (s)
 		kset_put(s);
 	kobject_put(parent);

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

end of thread, other threads:[~2007-04-19  0:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-16 17:36 [Patch -mm 3/3] RFC: Introduce kobject->owner for refcounting Cornelia Huck
2007-04-16 18:05 ` Greg KH
2007-04-16 19:53   ` Alan Stern
2007-04-17  2:53     ` Rusty Russell
2007-04-17  7:16       ` Cornelia Huck
2007-04-17 16:08         ` Alan Stern
2007-04-17 23:55           ` Rusty Russell
2007-04-18 15:20             ` Alan Stern
2007-04-19  0:46               ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome