kernfs: update kernfs_rename_ns() to consider KERNFS_STATIC_NAME
authorTejun Heo <tj@kernel.org>
Wed, 11 Dec 2013 21:02:58 +0000 (16:02 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 17 Dec 2013 16:59:15 +0000 (08:59 -0800)
kernfs_rename_ns() currently assumes that the target sysfs_dirent has
a copied name.  This has been okay because sysfs supports rename only
for directories which always have copied names; however, there's
nothing in kernfs interface which calls for such restriction and
currently invoking kernfs_rename_ns() on a regular file leads to oops
because it ends up trying to kfree() a static name.

This patch updates kernfs_rename_ns() so that it skips kfree() of the
old name if it's static.  This allows it to be used for all node
types.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/kernfs/dir.c

index e1681775abd561c4dd7ed37744307e451f73ae54..d33af95321fbd88384421a8570f9b59c6f4b2696 100644 (file)
@@ -886,7 +886,11 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
                if (!new_name)
                        goto out;
 
-               kfree(kn->name);
+               if (kn->flags & KERNFS_STATIC_NAME)
+                       kn->flags &= ~KERNFS_STATIC_NAME;
+               else
+                       kfree(kn->name);
+
                kn->name = new_name;
        }