]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - lib/kobject.c
powerpc/rtas_flash: Update return token comments
[karo-tx-linux.git] / lib / kobject.c
index aeefa8bc8b1c2dac1493703ff2f209ce894938f9..a65486613d79775bf87918b390d8edd608d55cef 100644 (file)
@@ -47,13 +47,11 @@ static int populate_dir(struct kobject *kobj)
 static int create_dir(struct kobject *kobj)
 {
        int error = 0;
-       if (kobject_name(kobj)) {
-               error = sysfs_create_dir(kobj);
-               if (!error) {
-                       error = populate_dir(kobj);
-                       if (error)
-                               sysfs_remove_dir(kobj);
-               }
+       error = sysfs_create_dir(kobj);
+       if (!error) {
+               error = populate_dir(kobj);
+               if (error)
+                       sysfs_remove_dir(kobj);
        }
        return error;
 }
@@ -531,6 +529,13 @@ struct kobject *kobject_get(struct kobject *kobj)
        return kobj;
 }
 
+static struct kobject *kobject_get_unless_zero(struct kobject *kobj)
+{
+       if (!kref_get_unless_zero(&kobj->kref))
+               kobj = NULL;
+       return kobj;
+}
+
 /*
  * kobject_cleanup - free kobject resources.
  * @kobj: object to cleanup
@@ -634,7 +639,7 @@ struct kobject *kobject_create(void)
 /**
  * kobject_create_and_add - create a struct kobject dynamically and register it with sysfs
  *
- * @name: the name for the kset
+ * @name: the name for the kobject
  * @parent: the parent kobject of this kobject, if any.
  *
  * This function creates a kobject structure dynamically and registers it
@@ -753,7 +758,7 @@ struct kobject *kset_find_obj(struct kset *kset, const char *name)
 
        list_for_each_entry(k, &kset->list, entry) {
                if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
-                       ret = kobject_get(k);
+                       ret = kobject_get_unless_zero(k);
                        break;
                }
        }