aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kobject.c')
-rw-r--r--lib/kobject.c63
1 files changed, 26 insertions, 37 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 0d03252f87a8..718e5101c263 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -58,11 +58,6 @@ static int create_dir(struct kobject *kobj)
58 return error; 58 return error;
59} 59}
60 60
61static inline struct kobject *to_kobj(struct list_head *entry)
62{
63 return container_of(entry, struct kobject, entry);
64}
65
66static int get_kobj_path_length(struct kobject *kobj) 61static int get_kobj_path_length(struct kobject *kobj)
67{ 62{
68 int length = 1; 63 int length = 1;
@@ -95,7 +90,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length)
95 } 90 }
96 91
97 pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj), 92 pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
98 kobj, __FUNCTION__, path); 93 kobj, __func__, path);
99} 94}
100 95
101/** 96/**
@@ -186,7 +181,7 @@ static int kobject_add_internal(struct kobject *kobj)
186 } 181 }
187 182
188 pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n", 183 pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
189 kobject_name(kobj), kobj, __FUNCTION__, 184 kobject_name(kobj), kobj, __func__,
190 parent ? kobject_name(parent) : "<NULL>", 185 parent ? kobject_name(parent) : "<NULL>",
191 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>"); 186 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>");
192 187
@@ -201,10 +196,10 @@ static int kobject_add_internal(struct kobject *kobj)
201 printk(KERN_ERR "%s failed for %s with " 196 printk(KERN_ERR "%s failed for %s with "
202 "-EEXIST, don't try to register things with " 197 "-EEXIST, don't try to register things with "
203 "the same name in the same directory.\n", 198 "the same name in the same directory.\n",
204 __FUNCTION__, kobject_name(kobj)); 199 __func__, kobject_name(kobj));
205 else 200 else
206 printk(KERN_ERR "%s failed for %s (%d)\n", 201 printk(KERN_ERR "%s failed for %s (%d)\n",
207 __FUNCTION__, kobject_name(kobj), error); 202 __func__, kobject_name(kobj), error);
208 dump_stack(); 203 dump_stack();
209 } else 204 } else
210 kobj->state_in_sysfs = 1; 205 kobj->state_in_sysfs = 1;
@@ -221,21 +216,12 @@ static int kobject_add_internal(struct kobject *kobj)
221static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, 216static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
222 va_list vargs) 217 va_list vargs)
223{ 218{
224 va_list aq;
225 char *name;
226
227 va_copy(aq, vargs);
228 name = kvasprintf(GFP_KERNEL, fmt, vargs);
229 va_end(aq);
230
231 if (!name)
232 return -ENOMEM;
233
234 /* Free the old name, if necessary. */ 219 /* Free the old name, if necessary. */
235 kfree(kobj->name); 220 kfree(kobj->name);
236 221
237 /* Now, set the new name */ 222 kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
238 kobj->name = name; 223 if (!kobj->name)
224 return -ENOMEM;
239 225
240 return 0; 226 return 0;
241} 227}
@@ -251,12 +237,12 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
251 */ 237 */
252int kobject_set_name(struct kobject *kobj, const char *fmt, ...) 238int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
253{ 239{
254 va_list args; 240 va_list vargs;
255 int retval; 241 int retval;
256 242
257 va_start(args, fmt); 243 va_start(vargs, fmt);
258 retval = kobject_set_name_vargs(kobj, fmt, args); 244 retval = kobject_set_name_vargs(kobj, fmt, vargs);
259 va_end(args); 245 va_end(vargs);
260 246
261 return retval; 247 return retval;
262} 248}
@@ -306,12 +292,9 @@ EXPORT_SYMBOL(kobject_init);
306static int kobject_add_varg(struct kobject *kobj, struct kobject *parent, 292static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
307 const char *fmt, va_list vargs) 293 const char *fmt, va_list vargs)
308{ 294{
309 va_list aq;
310 int retval; 295 int retval;
311 296
312 va_copy(aq, vargs); 297 retval = kobject_set_name_vargs(kobj, fmt, vargs);
313 retval = kobject_set_name_vargs(kobj, fmt, aq);
314 va_end(aq);
315 if (retval) { 298 if (retval) {
316 printk(KERN_ERR "kobject: can not set name properly!\n"); 299 printk(KERN_ERR "kobject: can not set name properly!\n");
317 return retval; 300 return retval;
@@ -545,7 +528,7 @@ static void kobject_cleanup(struct kobject *kobj)
545 const char *name = kobj->name; 528 const char *name = kobj->name;
546 529
547 pr_debug("kobject: '%s' (%p): %s\n", 530 pr_debug("kobject: '%s' (%p): %s\n",
548 kobject_name(kobj), kobj, __FUNCTION__); 531 kobject_name(kobj), kobj, __func__);
549 532
550 if (t && !t->release) 533 if (t && !t->release)
551 pr_debug("kobject: '%s' (%p): does not have a release() " 534 pr_debug("kobject: '%s' (%p): does not have a release() "
@@ -592,13 +575,20 @@ static void kobject_release(struct kref *kref)
592 */ 575 */
593void kobject_put(struct kobject *kobj) 576void kobject_put(struct kobject *kobj)
594{ 577{
595 if (kobj) 578 if (kobj) {
579 if (!kobj->state_initialized) {
580 printk(KERN_WARNING "kobject: '%s' (%p): is not "
581 "initialized, yet kobject_put() is being "
582 "called.\n", kobject_name(kobj), kobj);
583 WARN_ON(1);
584 }
596 kref_put(&kobj->kref, kobject_release); 585 kref_put(&kobj->kref, kobject_release);
586 }
597} 587}
598 588
599static void dynamic_kobj_release(struct kobject *kobj) 589static void dynamic_kobj_release(struct kobject *kobj)
600{ 590{
601 pr_debug("kobject: (%p): %s\n", kobj, __FUNCTION__); 591 pr_debug("kobject: (%p): %s\n", kobj, __func__);
602 kfree(kobj); 592 kfree(kobj);
603} 593}
604 594
@@ -655,7 +645,7 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
655 retval = kobject_add(kobj, parent, "%s", name); 645 retval = kobject_add(kobj, parent, "%s", name);
656 if (retval) { 646 if (retval) {
657 printk(KERN_WARNING "%s: kobject_add error: %d\n", 647 printk(KERN_WARNING "%s: kobject_add error: %d\n",
658 __FUNCTION__, retval); 648 __func__, retval);
659 kobject_put(kobj); 649 kobject_put(kobj);
660 kobj = NULL; 650 kobj = NULL;
661 } 651 }
@@ -745,12 +735,11 @@ void kset_unregister(struct kset *k)
745 */ 735 */
746struct kobject *kset_find_obj(struct kset *kset, const char *name) 736struct kobject *kset_find_obj(struct kset *kset, const char *name)
747{ 737{
748 struct list_head *entry; 738 struct kobject *k;
749 struct kobject *ret = NULL; 739 struct kobject *ret = NULL;
750 740
751 spin_lock(&kset->list_lock); 741 spin_lock(&kset->list_lock);
752 list_for_each(entry, &kset->list) { 742 list_for_each_entry(k, &kset->list, entry) {
753 struct kobject *k = to_kobj(entry);
754 if (kobject_name(k) && !strcmp(kobject_name(k), name)) { 743 if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
755 ret = kobject_get(k); 744 ret = kobject_get(k);
756 break; 745 break;
@@ -764,7 +753,7 @@ static void kset_release(struct kobject *kobj)
764{ 753{
765 struct kset *kset = container_of(kobj, struct kset, kobj); 754 struct kset *kset = container_of(kobj, struct kset, kobj);
766 pr_debug("kobject: '%s' (%p): %s\n", 755 pr_debug("kobject: '%s' (%p): %s\n",
767 kobject_name(kobj), kobj, __FUNCTION__); 756 kobject_name(kobj), kobj, __func__);
768 kfree(kset); 757 kfree(kset);
769} 758}
770 759