From a2c308ea8f8193403ebbc9108d367bd87f5ad3b2 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 3 Dec 2007 21:31:08 -0800 Subject: [PATCH] --- yaml --- r: 75727 b: refs/heads/master c: e86000d042d23904bbb609af2f8618a541cf129b h: refs/heads/master i: 75725: b05118226cb05198ea454dfc119276709e02dea0 75723: 9d5e0b88ae6a8e85bcb72704ee17666809b89603 75719: d261e836704c37573f15b992b9d0f2f4a9d601d1 75711: 0e421ea459fa135362fe6d314006161074fff745 v: v3 --- [refs] | 2 +- trunk/include/linux/kobject.h | 1 + trunk/lib/kobject.c | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 02f66d178831..78759a2f3401 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 18041f4775688af073d9b3ab0ffc262c1847e60b +refs/heads/master: e86000d042d23904bbb609af2f8618a541cf129b diff --git a/trunk/include/linux/kobject.h b/trunk/include/linux/kobject.h index 2d19a079ee79..bdf4f7c45f19 100644 --- a/trunk/include/linux/kobject.h +++ b/trunk/include/linux/kobject.h @@ -79,6 +79,7 @@ static inline const char * kobject_name(const struct kobject * kobj) } extern void kobject_init(struct kobject *); +extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype); extern int __must_check kobject_add(struct kobject *); extern void kobject_del(struct kobject *); diff --git a/trunk/lib/kobject.c b/trunk/lib/kobject.c index a152036db006..60586bcc7a71 100644 --- a/trunk/lib/kobject.c +++ b/trunk/lib/kobject.c @@ -282,6 +282,48 @@ int kobject_set_name(struct kobject *kobj, const char *fmt, ...) } EXPORT_SYMBOL(kobject_set_name); +/** + * kobject_init_ng - initialize a kobject structure + * @kobj: pointer to the kobject to initialize + * @ktype: pointer to the ktype for this kobject. + * + * This function will properly initialize a kobject such that it can then + * be passed to the kobject_add() call. + * + * After this function is called, the kobject MUST be cleaned up by a call + * to kobject_put(), not by a call to kfree directly to ensure that all of + * the memory is cleaned up properly. + */ +void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype) +{ + char *err_str; + + if (!kobj) { + err_str = "invalid kobject pointer!"; + goto error; + } + if (!ktype) { + err_str = "must have a ktype to be initialized properly!\n"; + goto error; + } + if (atomic_read(&kobj->kref.refcount)) { + /* do not error out as sometimes we can recover */ + printk(KERN_ERR "kobject: reference count is already set, " + "something is seriously wrong.\n"); + dump_stack(); + } + + kref_init(&kobj->kref); + INIT_LIST_HEAD(&kobj->entry); + kobj->ktype = ktype; + return; + +error: + printk(KERN_ERR "kobject: %s\n", err_str); + dump_stack(); +} +EXPORT_SYMBOL(kobject_init_ng); + /** * kobject_rename - change the name of an object * @kobj: object in question.