]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
tracefs: Use dentry name snapshots instead of heap allocation
authorAnishMulay <anishm7030@gmail.com>
Fri, 6 Mar 2026 20:04:58 +0000 (15:04 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 24 Mar 2026 21:04:58 +0000 (17:04 -0400)
commit676540d02b2ca4c3a8e550156c72b760c08e387e
tree59ab70af5acd9d56d646526480907470fb75207c
parent4d9b262031ffef203243e53577a90ae6e1090e67
tracefs: Use dentry name snapshots instead of heap allocation

In fs/tracefs/inode.c, tracefs_syscall_mkdir() and tracefs_syscall_rmdir()
previously used a local helper, get_dname(), which allocated a temporary
buffer on the heap via kmalloc() to hold the dentry name. This introduced
unnecessary overhead, an ENOMEM failure path, and required manual memory
cleanup via kfree().

As suggested by Al Viro, replace this heap allocation with the VFS dentry
name snapshot API. By stack-allocating a `struct name_snapshot` and using
take_dentry_name_snapshot() and release_dentry_name_snapshot(), we safely
capture the dentry name locklessly, eliminate the heap allocation entirely,
and remove the now-obsolete error handling paths. The get_dname() helper
is completely removed.

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.

Link: https://patch.msgid.link/20260306200458.2264-1-anishm7030@gmail.com
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: AnishMulay <anishm7030@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
fs/tracefs/inode.c