Merge branch 'for-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata
[linux-2.6-microblaze.git] / fs / sysfs / group.c
index c7a716c..1eb2d63 100644 (file)
@@ -124,13 +124,22 @@ static int internal_create_group(struct kobject *kobj, int update,
        }
        kobject_get_ownership(kobj, &uid, &gid);
        if (grp->name) {
-               kn = kernfs_create_dir_ns(kobj->sd, grp->name,
-                                         S_IRWXU | S_IRUGO | S_IXUGO,
-                                         uid, gid, kobj, NULL);
-               if (IS_ERR(kn)) {
-                       if (PTR_ERR(kn) == -EEXIST)
-                               sysfs_warn_dup(kobj->sd, grp->name);
-                       return PTR_ERR(kn);
+               if (update) {
+                       kn = kernfs_find_and_get(kobj->sd, grp->name);
+                       if (!kn) {
+                               pr_warn("Can't update unknown attr grp name: %s/%s\n",
+                                       kobj->name, grp->name);
+                               return -EINVAL;
+                       }
+               } else {
+                       kn = kernfs_create_dir_ns(kobj->sd, grp->name,
+                                                 S_IRWXU | S_IRUGO | S_IXUGO,
+                                                 uid, gid, kobj, NULL);
+                       if (IS_ERR(kn)) {
+                               if (PTR_ERR(kn) == -EEXIST)
+                                       sysfs_warn_dup(kobj->sd, grp->name);
+                               return PTR_ERR(kn);
+                       }
                }
        } else
                kn = kobj->sd;
@@ -141,6 +150,10 @@ static int internal_create_group(struct kobject *kobj, int update,
                        kernfs_remove(kn);
        }
        kernfs_put(kn);
+
+       if (grp->name && update)
+               kernfs_put(kn);
+
        return error;
 }
 
@@ -205,7 +218,8 @@ EXPORT_SYMBOL_GPL(sysfs_create_groups);
  * of the attribute files being created already exist.  Furthermore,
  * if the visibility of the files has changed through the is_visible()
  * callback, it will update the permissions and add or remove the
- * relevant files.
+ * relevant files. Changing a group's name (subdirectory name under
+ * kobj's directory in sysfs) is not allowed.
  *
  * The primary use for this function is to call it after making a change
  * that affects group visibility.