Re: [PATCH] tracefs: Simplify get_dname() with kmemdup_nul()

From: Al Viro

Date: Fri Feb 27 2026 - 15:22:13 EST


On Fri, Feb 27, 2026 at 02:44:53PM -0500, AnishMulay wrote:
> index d9d8932a7b9c9..86ba8dc25aaef 100644
> --- a/fs/tracefs/inode.c
> +++ b/fs/tracefs/inode.c
> @@ -96,17 +96,7 @@ static struct tracefs_dir_ops {
>
> static char *get_dname(struct dentry *dentry)
> {
> - const char *dname;
> - char *name;
> - int len = dentry->d_name.len;
> -
> - dname = dentry->d_name.name;
> - name = kmalloc(len + 1, GFP_KERNEL);
> - if (!name)
> - return NULL;
> - memcpy(name, dname, len);
> - name[len] = 0;
> - return name;
> + return kmemdup_nul(dentry->d_name.name, dentry->d_name.len, GFP_KERNEL);
> }

Why not have the callers use {take,release}_dentry_name_snapshot()
instead of doing any allocations at all?

I mean,
static struct dentry *tracefs_syscall_mkdir(struct mnt_idmap *idmap,
struct inode *inode, struct dentry *dentry,
umode_t mode)
{
struct tracefs_inode *ti;
struct name_snapshot s;
int ret;

take_dentry_name_snapshot(&s, dentry);
...
ret = tracefs_ops.mkdir(s.name.name);
release_dentry_name_snapshot(&s);
...
}

and similar on the rmdir side. Then remove get_dname()...