From: Greg Kroah-Hartman Date: Tue, 4 Dec 2007 05:31:08 +0000 (-0800) Subject: kobject: add kobject_init_ng function X-Git-Tag: v2.6.25-rc1~1243^2~157 X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=e86000d042d23904bbb609af2f8618a541cf129b;p=linux-2.6-omap-h63xx.git kobject: add kobject_init_ng function This is what the kobject_init function is going to become. Add this to the kernel and then we can convert the tree over to use it. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 2d19a079ee7..bdf4f7c45f1 100644 --- a/include/linux/kobject.h +++ b/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/lib/kobject.c b/lib/kobject.c index a152036db00..60586bcc7a7 100644 --- a/lib/kobject.c +++ b/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.