Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.6.26-rc7 /lib/kobject.c

Filename:/lib/kobject.c
Lines Added:26
Lines Deleted:37
Also changed in: (Previous) 2.6.26-rc6  2.6.26-rc5  2.6.26-rc4  2.6.26-rc3  2.6.26-rc2  2.6.26-rc1 
(Following) 2.6.26-rc8  2.6.26-rc9  2.6.26  2.6.26-git5  2.6.26-git6  2.6.26-git7 

Location
[  2.6.26-rc7
  [  lib
     o  kobject.c

Patch

diff --git a/lib/kobject.c b/lib/kobject.c
index 0d03252..718e510 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);
 }
 
 /**
@@ -186,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) : "<NULL>",
        kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>");
 
@@ -201,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;
@@ -221,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;
 }
@@ -251,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;
 }
@@ -306,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;
@@ -545,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() "
@@ -592,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);
 }
 
@@ -655,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;
    }
@@ -745,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;
@@ -764,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);
 }
 


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.