]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
configfs_mkdir(): use take_dentry_name_snapshot()
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 9 May 2026 16:41:46 +0000 (12:41 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 8 Jun 2026 18:53:09 +0000 (14:53 -0400)
Note that neither ->make_group() nor ->make_item() are allowed to modify
the string passed to them - the argument is const char *.

Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/configfs/dir.c

index eb991b2a9c341f8b14a750e5dedd41b5ad84f9e7..8181771c8a58f3b78fb6e6ad947f9dd73c41e51d 100644 (file)
@@ -1329,7 +1329,11 @@ static struct dentry *configfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
        const struct config_item_type *type;
        struct module *subsys_owner = NULL, *new_item_owner = NULL;
        struct configfs_fragment *frag;
-       char *name;
+       struct name_snapshot n;
+       const char *name;
+
+       take_dentry_name_snapshot(&n, dentry);
+       name = n.name.name;
 
        sd = dentry->d_parent->d_fsdata;
 
@@ -1381,14 +1385,6 @@ static struct dentry *configfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
                goto out_put;
        }
 
-       name = kmalloc(dentry->d_name.len + 1, GFP_KERNEL);
-       if (!name) {
-               ret = -ENOMEM;
-               goto out_subsys_put;
-       }
-
-       snprintf(name, dentry->d_name.len + 1, "%s", dentry->d_name.name);
-
        mutex_lock(&subsys->su_mutex);
        if (type->ct_group_ops->make_group) {
                group = type->ct_group_ops->make_group(to_config_group(parent_item), name);
@@ -1410,7 +1406,6 @@ static struct dentry *configfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
        }
        mutex_unlock(&subsys->su_mutex);
 
-       kfree(name);
        if (ret) {
                /*
                 * If ret != 0, then link_obj() was never called.
@@ -1497,6 +1492,7 @@ out_put:
        put_fragment(frag);
 
 out:
+       release_dentry_name_snapshot(&n);
        return ERR_PTR(ret);
 }