In fs/tracefs/inode.c, get_dname() allocates a buffer with kmalloc() to hold a dentry name, followed by a memcpy() and manual null-termination.
Replace this open-coded pattern with the standard kmemdup_nul() helper. Additionally, remove the now single-use local variables `dname` and `len`. This simplifies the function to a single line, reducing visual clutter and making the memory-safety intent immediately obvious without changing any functional behavior. Testing: Booted a custom kernel natively in virtme-ng (ARM64). Triggered tracefs inode and dentry allocation by creating and removing a custom directory under a temporary tracefs mount. Verified that the instance is created successfully and that no memory errors or warnings are emitted in dmesg. Signed-off-by: AnishMulay <[email protected]> --- fs/tracefs/inode.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c 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); } static struct dentry *tracefs_syscall_mkdir(struct mnt_idmap *idmap, -- 2.51.0
