diff options
-rw-r--r-- | include/linux/kobject.h | 2 | ||||
-rw-r--r-- | lib/kobject.c | 38 |
2 files changed, 40 insertions, 0 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 7ece63f8abbd..4cb1214ec290 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h | |||
@@ -80,6 +80,8 @@ extern void kobject_unregister(struct kobject *); | |||
80 | extern struct kobject * kobject_get(struct kobject *); | 80 | extern struct kobject * kobject_get(struct kobject *); |
81 | extern void kobject_put(struct kobject *); | 81 | extern void kobject_put(struct kobject *); |
82 | 82 | ||
83 | extern struct kobject *kobject_add_dir(struct kobject *, const char *); | ||
84 | |||
83 | extern char * kobject_get_path(struct kobject *, gfp_t); | 85 | extern char * kobject_get_path(struct kobject *, gfp_t); |
84 | 86 | ||
85 | struct kobj_type { | 87 | struct kobj_type { |
diff --git a/lib/kobject.c b/lib/kobject.c index 36668c8c3ea1..25204a41a9b0 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -385,6 +385,44 @@ void kobject_put(struct kobject * kobj) | |||
385 | } | 385 | } |
386 | 386 | ||
387 | 387 | ||
388 | static void dir_release(struct kobject *kobj) | ||
389 | { | ||
390 | kfree(kobj); | ||
391 | } | ||
392 | |||
393 | static struct kobj_type dir_ktype = { | ||
394 | .release = dir_release, | ||
395 | .sysfs_ops = NULL, | ||
396 | .default_attrs = NULL, | ||
397 | }; | ||
398 | |||
399 | /** | ||
400 | * kobject_add_dir - add sub directory of object. | ||
401 | * @parent: object in which a directory is created. | ||
402 | * @name: directory name. | ||
403 | * | ||
404 | * Add a plain directory object as child of given object. | ||
405 | */ | ||
406 | struct kobject *kobject_add_dir(struct kobject *parent, const char *name) | ||
407 | { | ||
408 | struct kobject *k; | ||
409 | |||
410 | if (!parent) | ||
411 | return NULL; | ||
412 | |||
413 | k = kzalloc(sizeof(*k), GFP_KERNEL); | ||
414 | if (!k) | ||
415 | return NULL; | ||
416 | |||
417 | k->parent = parent; | ||
418 | k->ktype = &dir_ktype; | ||
419 | kobject_set_name(k, name); | ||
420 | kobject_register(k); | ||
421 | |||
422 | return k; | ||
423 | } | ||
424 | EXPORT_SYMBOL_GPL(kobject_add_dir); | ||
425 | |||
388 | /** | 426 | /** |
389 | * kset_init - initialize a kset for use | 427 | * kset_init - initialize a kset for use |
390 | * @k: kset | 428 | * @k: kset |