diff options
-rw-r--r-- | include/linux/kobject.h | 5 | ||||
-rw-r--r-- | lib/kobject.c | 27 |
2 files changed, 32 insertions, 0 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 57eea4cb940d..e2b8c3dae425 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h | |||
@@ -84,6 +84,11 @@ extern int __must_check kobject_add(struct kobject *); | |||
84 | extern int __must_check kobject_add_ng(struct kobject *kobj, | 84 | extern int __must_check kobject_add_ng(struct kobject *kobj, |
85 | struct kobject *parent, | 85 | struct kobject *parent, |
86 | const char *fmt, ...); | 86 | const char *fmt, ...); |
87 | extern int __must_check kobject_init_and_add(struct kobject *kobj, | ||
88 | struct kobj_type *ktype, | ||
89 | struct kobject *parent, | ||
90 | const char *fmt, ...); | ||
91 | |||
87 | extern void kobject_del(struct kobject *); | 92 | extern void kobject_del(struct kobject *); |
88 | 93 | ||
89 | extern int __must_check kobject_rename(struct kobject *, const char *new_name); | 94 | extern int __must_check kobject_rename(struct kobject *, const char *new_name); |
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, | |||
391 | EXPORT_SYMBOL(kobject_add_ng); | 391 | EXPORT_SYMBOL(kobject_add_ng); |
392 | 392 | ||
393 | /** | 393 | /** |
394 | * kobject_init_and_add - initialize a kobject structure and add it to the kobject hierarchy | ||
395 | * @kobj: pointer to the kobject to initialize | ||
396 | * @ktype: pointer to the ktype for this kobject. | ||
397 | * @parent: pointer to the parent of this kobject. | ||
398 | * @fmt: the name of the kobject. | ||
399 | * | ||
400 | * This function combines the call to kobject_init_ng() and | ||
401 | * kobject_add_ng(). The same type of error handling after a call to | ||
402 | * kobject_add_ng() and kobject lifetime rules are the same here. | ||
403 | */ | ||
404 | int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, | ||
405 | struct kobject *parent, const char *fmt, ...) | ||
406 | { | ||
407 | va_list args; | ||
408 | int retval; | ||
409 | |||
410 | kobject_init_ng(kobj, ktype); | ||
411 | |||
412 | va_start(args, fmt); | ||
413 | retval = kobject_add_varg(kobj, parent, fmt, args); | ||
414 | va_end(args); | ||
415 | |||
416 | return retval; | ||
417 | } | ||
418 | EXPORT_SYMBOL_GPL(kobject_init_and_add); | ||
419 | |||
420 | /** | ||
394 | * kobject_rename - change the name of an object | 421 | * kobject_rename - change the name of an object |
395 | * @kobj: object in question. | 422 | * @kobj: object in question. |
396 | * @new_name: object's new name | 423 | * @new_name: object's new name |