summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2007-12-04 08:31:08 +0300
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-25 07:40:10 +0300
commitc11c4154e7ff4cebfadad849b1e22689d759c3f4 (patch)
tree2038ed1677f55d3dafca6faac4a7155fb1e19166 /lib
parent244f6cee9a928103132a722292bfa0eb84114b07 (diff)
downloadlinux-c11c4154e7ff4cebfadad849b1e22689d759c3f4.tar.xz
kobject: add kobject_init_and_add function
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/kobject.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 329fd1126b3f..8f249408b2ec 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -391,6 +391,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.
* @new_name: object's new name