aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2007-12-04 00:31:08 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-24 23:40:09 -0500
commit244f6cee9a928103132a722292bfa0eb84114b07 (patch)
tree4ef3d80c4bd29533dcf5479c51376aa16c36b670
parente86000d042d23904bbb609af2f8618a541cf129b (diff)
kobject: add kobject_add_ng function
This is what the kobject_add 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>
-rw-r--r--include/linux/kobject.h3
-rw-r--r--lib/kobject.c66
2 files changed, 69 insertions, 0 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index bdf4f7c45f19..57eea4cb940d 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -81,6 +81,9 @@ static inline const char * kobject_name(const struct kobject * kobj)
81extern void kobject_init(struct kobject *); 81extern void kobject_init(struct kobject *);
82extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype); 82extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype);
83extern int __must_check kobject_add(struct kobject *); 83extern int __must_check kobject_add(struct kobject *);
84extern int __must_check kobject_add_ng(struct kobject *kobj,
85 struct kobject *parent,
86 const char *fmt, ...);
84extern void kobject_del(struct kobject *); 87extern void kobject_del(struct kobject *);
85 88
86extern int __must_check kobject_rename(struct kobject *, const char *new_name); 89extern int __must_check kobject_rename(struct kobject *, const char *new_name);
diff --git a/lib/kobject.c b/lib/kobject.c
index 60586bcc7a71..329fd1126b3f 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -324,6 +324,72 @@ error:
324} 324}
325EXPORT_SYMBOL(kobject_init_ng); 325EXPORT_SYMBOL(kobject_init_ng);
326 326
327static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
328 const char *fmt, va_list vargs)
329{
330 va_list aq;
331 int retval;
332
333 va_copy(aq, vargs);
334 retval = kobject_set_name_vargs(kobj, fmt, aq);
335 va_end(aq);
336 if (retval) {
337 printk(KERN_ERR "kobject: can not set name properly!\n");
338 return retval;
339 }
340 kobj->parent = parent;
341 return kobject_add(kobj);
342}
343
344/**
345 * kobject_add_ng - the main kobject add function
346 * @kobj: the kobject to add
347 * @parent: pointer to the parent of the kobject.
348 * @fmt: format to name the kobject with.
349 *
350 * The kobject name is set and added to the kobject hierarchy in this
351 * function.
352 *
353 * If @parent is set, then the parent of the @kobj will be set to it.
354 * If @parent is NULL, then the parent of the @kobj will be set to the
355 * kobject associted with the kset assigned to this kobject. If no kset
356 * is assigned to the kobject, then the kobject will be located in the
357 * root of the sysfs tree.
358 *
359 * If this function returns an error, kobject_put() must be called to
360 * properly clean up the memory associated with the object.
361 *
362 * If the function is successful, the only way to properly clean up the
363 * memory is with a call to kobject_del(), in which case, a call to
364 * kobject_put() is not necessary (kobject_del() does the final
365 * kobject_put() to call the release function in the ktype's release
366 * pointer.)
367 *
368 * Under no instance should the kobject that is passed to this function
369 * be directly freed with a call to kfree(), that can leak memory.
370 *
371 * Note, no uevent will be created with this call, the caller should set
372 * up all of the necessary sysfs files for the object and then call
373 * kobject_uevent() with the UEVENT_ADD parameter to ensure that
374 * userspace is properly notified of this kobject's creation.
375 */
376int kobject_add_ng(struct kobject *kobj, struct kobject *parent,
377 const char *fmt, ...)
378{
379 va_list args;
380 int retval;
381
382 if (!kobj)
383 return -EINVAL;
384
385 va_start(args, fmt);
386 retval = kobject_add_varg(kobj, parent, fmt, args);
387 va_end(args);
388
389 return retval;
390}
391EXPORT_SYMBOL(kobject_add_ng);
392
327/** 393/**
328 * kobject_rename - change the name of an object 394 * kobject_rename - change the name of an object
329 * @kobj: object in question. 395 * @kobj: object in question.