diff options
Diffstat (limited to 'lib/kobject.c')
-rw-r--r-- | lib/kobject.c | 66 |
1 files changed, 66 insertions, 0 deletions
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 | } |
325 | EXPORT_SYMBOL(kobject_init_ng); | 325 | EXPORT_SYMBOL(kobject_init_ng); |
326 | 326 | ||
327 | static 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 | */ | ||
376 | int 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 | } | ||
391 | EXPORT_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. |