mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [Patch -mm 2/3] RFC: Expose module->mkobj reference count.
@ 2007-04-16 17:36 Cornelia Huck
  0 siblings, 0 replies; only message 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

Expose module->mkobj.kobj refcounting to drivers. Wait with deleting
the module until the refcount has dropped to 0.

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

---
 include/linux/module.h |    4 ++++
 kernel/module.c        |   30 +++++++++++++++++++++++++++++-
 kernel/params.c        |    8 ++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)

--- linux-2.6.orig/include/linux/module.h
+++ linux-2.6/include/linux/module.h
@@ -59,6 +59,7 @@ struct module_kobject
 	struct kobject kobj;
 	struct module *mod;
 	struct kobject *drivers_dir;
+	struct completion completion;
 };
 
 /* These are either module local, or the kernel's dummy ones. */
@@ -591,6 +592,9 @@ int mod_sysfs_init(struct module *mod);
 int mod_sysfs_setup(struct module *mod,
 			   struct kernel_param *kparam,
 			   unsigned int num_params);
+struct kobject * mod_kobject_get(struct module *);
+void mod_kobject_put(struct module *);
+
 #ifdef CONFIG_SYSFS
 int module_add_modinfo_attrs(struct module *mod);
 void module_remove_modinfo_attrs(struct module *mod);
--- linux-2.6.orig/kernel/module.c
+++ linux-2.6/kernel/module.c
@@ -1403,7 +1403,7 @@ int mod_sysfs_init(struct module *mod)
 		goto out;
 	kobj_set_kset_s(&mod->mkobj, module_subsys);
 	mod->mkobj.mod = mod;
-
+	init_completion(&mod->mkobj.completion);
 	kobject_init(&mod->mkobj.kobj);
 
 out:
@@ -1456,6 +1456,32 @@ static void mod_kobject_remove(struct mo
 	kobject_unregister(&mod->mkobj.kobj);
 }
 
+/**
+ * mod_kobject_get - get reference on a module's kobject
+ * @mod: module to work on
+ *
+ * Returns a pointer to the kobject embedded in @mod if a reference
+ * could be taken; %NULL else.
+ */
+struct kobject * mod_kobject_get(struct module *mod)
+{
+	if (!mod)
+		return NULL;
+	return kobject_get(&mod->mkobj.kobj);
+}
+EXPORT_SYMBOL_GPL(mod_kobject_get);
+
+/**
+ * mod_kobject_put - give up reference on a module's kobject
+ * @mod: module to work on
+ */
+void mod_kobject_put(struct module *mod)
+{
+	if (mod)
+		kobject_put(&mod->mkobj.kobj);
+}
+EXPORT_SYMBOL_GPL(mod_kobject_put);
+
 /*
  * unlink the module with the whole machine is stopped with interrupts off
  * - this defends against kallsyms not taking locks
@@ -1483,6 +1509,8 @@ static void free_module(struct module *m
 	/* Module unload stuff */
 	module_unload_free(mod);
 
+	wait_for_completion(&mod->mkobj.completion);
+
 	/* This may be NULL, but that's OK */
 	module_free(mod, mod->module_init);
 	kfree(mod->args);
--- linux-2.6.orig/kernel/params.c
+++ linux-2.6/kernel/params.c
@@ -692,8 +692,16 @@ static struct kset_uevent_ops module_uev
 
 decl_subsys(module, &module_ktype, &module_uevent_ops);
 
+static void module_kobj_release(struct kobject *kobj)
+{
+	struct module_kobject *mkobj = container_of(kobj, struct module_kobject,
+						    kobj);
+	complete(&mkobj->completion);
+}
+
 static struct kobj_type module_ktype = {
 	.sysfs_ops =	&module_sysfs_ops,
+	.release = module_kobj_release,
 };
 
 /*

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-04-16 17:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-16 17:36 [Patch -mm 2/3] RFC: Expose module->mkobj reference count Cornelia Huck

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

all inboxes | Powered by JetHome®