X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fkobject.c;h=718e5101c263596224f7f35b523cea27e093ecd6;hb=a05fe0389b72f43b9e29d6fbfc5885084be2f96f;hp=d784daeb8571692e0fed288f17df60651a04366c;hpb=8976b6fd7a0060f72e20d5cec833c03d50874cd1;p=linux-2.6-omap-h63xx.git diff --git a/lib/kobject.c b/lib/kobject.c index d784daeb857..718e5101c26 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -58,11 +58,6 @@ static int create_dir(struct kobject *kobj) return error; } -static inline struct kobject *to_kobj(struct list_head *entry) -{ - return container_of(entry, struct kobject, entry); -} - static int get_kobj_path_length(struct kobject *kobj) { int length = 1; @@ -95,7 +90,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length) } pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj), - kobj, __FUNCTION__, path); + kobj, __func__, path); } /** @@ -153,6 +148,10 @@ static void kobject_init_internal(struct kobject *kobj) return; kref_init(&kobj->kref); INIT_LIST_HEAD(&kobj->entry); + kobj->state_in_sysfs = 0; + kobj->state_add_uevent_sent = 0; + kobj->state_remove_uevent_sent = 0; + kobj->state_initialized = 1; } @@ -182,7 +181,7 @@ static int kobject_add_internal(struct kobject *kobj) } pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n", - kobject_name(kobj), kobj, __FUNCTION__, + kobject_name(kobj), kobj, __func__, parent ? kobject_name(parent) : "", kobj->kset ? kobject_name(&kobj->kset->kobj) : ""); @@ -197,10 +196,10 @@ static int kobject_add_internal(struct kobject *kobj) printk(KERN_ERR "%s failed for %s with " "-EEXIST, don't try to register things with " "the same name in the same directory.\n", - __FUNCTION__, kobject_name(kobj)); + __func__, kobject_name(kobj)); else printk(KERN_ERR "%s failed for %s (%d)\n", - __FUNCTION__, kobject_name(kobj), error); + __func__, kobject_name(kobj), error); dump_stack(); } else kobj->state_in_sysfs = 1; @@ -217,21 +216,12 @@ static int kobject_add_internal(struct kobject *kobj) static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list vargs) { - va_list aq; - char *name; - - va_copy(aq, vargs); - name = kvasprintf(GFP_KERNEL, fmt, vargs); - va_end(aq); - - if (!name) - return -ENOMEM; - /* Free the old name, if necessary. */ kfree(kobj->name); - /* Now, set the new name */ - kobj->name = name; + kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs); + if (!kobj->name) + return -ENOMEM; return 0; } @@ -247,12 +237,12 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, */ int kobject_set_name(struct kobject *kobj, const char *fmt, ...) { - va_list args; + va_list vargs; int retval; - va_start(args, fmt); - retval = kobject_set_name_vargs(kobj, fmt, args); - va_end(args); + va_start(vargs, fmt); + retval = kobject_set_name_vargs(kobj, fmt, vargs); + va_end(vargs); return retval; } @@ -289,13 +279,8 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype) dump_stack(); } - kref_init(&kobj->kref); - INIT_LIST_HEAD(&kobj->entry); + kobject_init_internal(kobj); kobj->ktype = ktype; - kobj->state_in_sysfs = 0; - kobj->state_add_uevent_sent = 0; - kobj->state_remove_uevent_sent = 0; - kobj->state_initialized = 1; return; error: @@ -307,12 +292,9 @@ EXPORT_SYMBOL(kobject_init); static int kobject_add_varg(struct kobject *kobj, struct kobject *parent, const char *fmt, va_list vargs) { - va_list aq; int retval; - va_copy(aq, vargs); - retval = kobject_set_name_vargs(kobj, fmt, aq); - va_end(aq); + retval = kobject_set_name_vargs(kobj, fmt, vargs); if (retval) { printk(KERN_ERR "kobject: can not set name properly!\n"); return retval; @@ -546,7 +528,7 @@ static void kobject_cleanup(struct kobject *kobj) const char *name = kobj->name; pr_debug("kobject: '%s' (%p): %s\n", - kobject_name(kobj), kobj, __FUNCTION__); + kobject_name(kobj), kobj, __func__); if (t && !t->release) pr_debug("kobject: '%s' (%p): does not have a release() " @@ -593,13 +575,20 @@ static void kobject_release(struct kref *kref) */ void kobject_put(struct kobject *kobj) { - if (kobj) + if (kobj) { + if (!kobj->state_initialized) { + printk(KERN_WARNING "kobject: '%s' (%p): is not " + "initialized, yet kobject_put() is being " + "called.\n", kobject_name(kobj), kobj); + WARN_ON(1); + } kref_put(&kobj->kref, kobject_release); + } } static void dynamic_kobj_release(struct kobject *kobj) { - pr_debug("kobject: (%p): %s\n", kobj, __FUNCTION__); + pr_debug("kobject: (%p): %s\n", kobj, __func__); kfree(kobj); } @@ -656,7 +645,7 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent) retval = kobject_add(kobj, parent, "%s", name); if (retval) { printk(KERN_WARNING "%s: kobject_add error: %d\n", - __FUNCTION__, retval); + __func__, retval); kobject_put(kobj); kobj = NULL; } @@ -746,12 +735,11 @@ void kset_unregister(struct kset *k) */ struct kobject *kset_find_obj(struct kset *kset, const char *name) { - struct list_head *entry; + struct kobject *k; struct kobject *ret = NULL; spin_lock(&kset->list_lock); - list_for_each(entry, &kset->list) { - struct kobject *k = to_kobj(entry); + list_for_each_entry(k, &kset->list, entry) { if (kobject_name(k) && !strcmp(kobject_name(k), name)) { ret = kobject_get(k); break; @@ -765,7 +753,7 @@ static void kset_release(struct kobject *kobj) { struct kset *kset = container_of(kobj, struct kset, kobj); pr_debug("kobject: '%s' (%p): %s\n", - kobject_name(kobj), kobj, __FUNCTION__); + kobject_name(kobj), kobj, __func__); kfree(kset); }