Commit 7423172a50968de1905a61413c52bb070a62f5ce
Committed by
Greg Kroah-Hartman
1 parent
dd308bc355
Exists in
master
and in
7 other branches
[PATCH] kobject_add_dir
Adding kobject_add_dir() function which creates a subdirectory for a given kobject. Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 2 changed files with 40 additions and 0 deletions Side-by-side Diff
include/linux/kobject.h
... | ... | @@ -80,6 +80,8 @@ |
80 | 80 | extern struct kobject * kobject_get(struct kobject *); |
81 | 81 | extern void kobject_put(struct kobject *); |
82 | 82 | |
83 | +extern struct kobject *kobject_add_dir(struct kobject *, const char *); | |
84 | + | |
83 | 85 | extern char * kobject_get_path(struct kobject *, gfp_t); |
84 | 86 | |
85 | 87 | struct kobj_type { |
lib/kobject.c
... | ... | @@ -385,6 +385,44 @@ |
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 | 427 | * kset_init - initialize a kset for use |
390 | 428 | * @k: kset |