From 65a2746bb3c71af5bd19097ec3a9a2ecb6f6aa63 Mon Sep 17 00:00:00 2001 From: Jun'ichi Nomura Date: Mon, 13 Mar 2006 17:14:25 -0500 Subject: [PATCH] --- yaml --- r: 22014 b: refs/heads/master c: 7423172a50968de1905a61413c52bb070a62f5ce h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/include/linux/kobject.h | 2 ++ trunk/lib/kobject.c | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 501737f91600..efe432c547f8 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: dd308bc355a1aa4f202fe9a3133b6c676cb9606c +refs/heads/master: 7423172a50968de1905a61413c52bb070a62f5ce diff --git a/trunk/include/linux/kobject.h b/trunk/include/linux/kobject.h index 7ece63f8abbd..4cb1214ec290 100644 --- a/trunk/include/linux/kobject.h +++ b/trunk/include/linux/kobject.h @@ -80,6 +80,8 @@ extern void kobject_unregister(struct kobject *); extern struct kobject * kobject_get(struct kobject *); extern void kobject_put(struct kobject *); +extern struct kobject *kobject_add_dir(struct kobject *, const char *); + extern char * kobject_get_path(struct kobject *, gfp_t); struct kobj_type { diff --git a/trunk/lib/kobject.c b/trunk/lib/kobject.c index 36668c8c3ea1..25204a41a9b0 100644 --- a/trunk/lib/kobject.c +++ b/trunk/lib/kobject.c @@ -385,6 +385,44 @@ void kobject_put(struct kobject * kobj) } +static void dir_release(struct kobject *kobj) +{ + kfree(kobj); +} + +static struct kobj_type dir_ktype = { + .release = dir_release, + .sysfs_ops = NULL, + .default_attrs = NULL, +}; + +/** + * kobject_add_dir - add sub directory of object. + * @parent: object in which a directory is created. + * @name: directory name. + * + * Add a plain directory object as child of given object. + */ +struct kobject *kobject_add_dir(struct kobject *parent, const char *name) +{ + struct kobject *k; + + if (!parent) + return NULL; + + k = kzalloc(sizeof(*k), GFP_KERNEL); + if (!k) + return NULL; + + k->parent = parent; + k->ktype = &dir_ktype; + kobject_set_name(k, name); + kobject_register(k); + + return k; +} +EXPORT_SYMBOL_GPL(kobject_add_dir); + /** * kset_init - initialize a kset for use * @k: kset