sysfs: Fix internal_create_group() for named group updates
commitc855cf2759d27142f771173d9fd8e7fdf9cf5138
authorRajat Jain <rajatja@google.com>
Sat, 16 Jun 2018 17:49:46 +0000 (16 10:49 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 7 Jul 2018 15:54:46 +0000 (7 17:54 +0200)
treebdca38399864bfa1900851f1ef1f6248b9debf5a
parent319b11ef5719a2f0ae65ce5f665f263a5e7a06c3
sysfs: Fix internal_create_group() for named group updates

There are a couple of problems with named group updates in the code
today:

* sysfs_update_group() will always fail for a named group, because
  internal_create_group() will try to create a new sysfs directory
  unconditionally, which will ofcourse fail with -EEXIST.

* We can leak the kernfs_node for grp->name if some one tries to:
  - rename a group (change grp->name), or
  - update a named group, to an unnamed group

It appears that the whole purpose of sysfs_update_group() was to
allow changing the permissions or visibility of attributes and not
the names. So make it clear in the comments, and allow it to update
an existing named group.

Signed-off-by: Rajat Jain <rajatja@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/sysfs/group.c