kobject: add kobject_init_and_add function
authorGreg Kroah-Hartman <gregkh@suse.de>
Tue, 4 Dec 2007 05:31:08 +0000 (21:31 -0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 25 Jan 2008 04:40:10 +0000 (20:40 -0800)
Also add a kobject_init_and_add function which bundles up what a lot of
the current callers want to do all at once, and it properly handles the
memory usages, unlike kobject_register();

Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/linux/kobject.h
lib/kobject.c

index 57eea4cb940d3593bb58429d55df6f9cdecb1156..e2b8c3dae425ca64ff5d5c458b2e071db053ff9a 100644 (file)
@@ -84,6 +84,11 @@ extern int __must_check kobject_add(struct kobject *);
 extern int __must_check kobject_add_ng(struct kobject *kobj,
                                       struct kobject *parent,
                                       const char *fmt, ...);
+extern int __must_check kobject_init_and_add(struct kobject *kobj,
+                                            struct kobj_type *ktype,
+                                            struct kobject *parent,
+                                            const char *fmt, ...);
+
 extern void kobject_del(struct kobject *);
 
 extern int __must_check kobject_rename(struct kobject *, const char *new_name);
index 329fd1126b3f116ed6e0dd6d62ba2c82ebc6cfc1..8f249408b2ece28956ab95c09e1912dcd8dadb94 100644 (file)
@@ -390,6 +390,33 @@ int kobject_add_ng(struct kobject *kobj, struct kobject *parent,
 }
 EXPORT_SYMBOL(kobject_add_ng);
 
+/**
+ * kobject_init_and_add - initialize a kobject structure and add it to the kobject hierarchy
+ * @kobj: pointer to the kobject to initialize
+ * @ktype: pointer to the ktype for this kobject.
+ * @parent: pointer to the parent of this kobject.
+ * @fmt: the name of the kobject.
+ *
+ * This function combines the call to kobject_init_ng() and
+ * kobject_add_ng().  The same type of error handling after a call to
+ * kobject_add_ng() and kobject lifetime rules are the same here.
+ */
+int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
+                        struct kobject *parent, const char *fmt, ...)
+{
+       va_list args;
+       int retval;
+
+       kobject_init_ng(kobj, ktype);
+
+       va_start(args, fmt);
+       retval = kobject_add_varg(kobj, parent, fmt, args);
+       va_end(args);
+
+       return retval;
+}
+EXPORT_SYMBOL_GPL(kobject_init_and_add);
+
 /**
  *     kobject_rename - change the name of an object
  *     @kobj:  object in question.