summaryrefslogtreecommitdiffstats
path: root/lib/kobject.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2007-12-03 21:31:08 -0800
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-24 20:40:09 -0800
commite86000d042d23904bbb609af2f8618a541cf129b (patch)
treef31e28280e33248a3cd82ae2bcfa5b51c12d9984 /lib/kobject.c
parent18041f4775688af073d9b3ab0ffc262c1847e60b (diff)
downloadop-kernel-dev-e86000d042d23904bbb609af2f8618a541cf129b.zip
op-kernel-dev-e86000d042d23904bbb609af2f8618a541cf129b.tar.gz
kobject: add kobject_init_ng function
This is what the kobject_init function is going to become. Add this to the kernel and then we can convert the tree over to use it. Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'lib/kobject.c')
-rw-r--r--lib/kobject.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index a152036..60586bc 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -283,6 +283,48 @@ int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
EXPORT_SYMBOL(kobject_set_name);
/**
+ * kobject_init_ng - initialize a kobject structure
+ * @kobj: pointer to the kobject to initialize
+ * @ktype: pointer to the ktype for this kobject.
+ *
+ * This function will properly initialize a kobject such that it can then
+ * be passed to the kobject_add() call.
+ *
+ * After this function is called, the kobject MUST be cleaned up by a call
+ * to kobject_put(), not by a call to kfree directly to ensure that all of
+ * the memory is cleaned up properly.
+ */
+void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype)
+{
+ char *err_str;
+
+ if (!kobj) {
+ err_str = "invalid kobject pointer!";
+ goto error;
+ }
+ if (!ktype) {
+ err_str = "must have a ktype to be initialized properly!\n";
+ goto error;
+ }
+ if (atomic_read(&kobj->kref.refcount)) {
+ /* do not error out as sometimes we can recover */
+ printk(KERN_ERR "kobject: reference count is already set, "
+ "something is seriously wrong.\n");
+ dump_stack();
+ }
+
+ kref_init(&kobj->kref);
+ INIT_LIST_HEAD(&kobj->entry);
+ kobj->ktype = ktype;
+ return;
+
+error:
+ printk(KERN_ERR "kobject: %s\n", err_str);
+ dump_stack();
+}
+EXPORT_SYMBOL(kobject_init_ng);
+
+/**
* kobject_rename - change the name of an object
* @kobj: object in question.
* @new_name: object's new name
OpenPOWER on IntegriCloud