public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracefs: Simplify get_dname() with kmemdup_nul()
@ 2026-02-27 19:44 AnishMulay
  2026-02-27 20:18 ` Al Viro
  0 siblings, 1 reply; 8+ messages in thread
From: AnishMulay @ 2026-02-27 19:44 UTC (permalink / raw)
  To: rostedt, mhiramat
  Cc: mathieu.desnoyers, linux-trace-kernel, linux-kernel, AnishMulay

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 <anishm7030@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-03-06 21:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 19:44 [PATCH] tracefs: Simplify get_dname() with kmemdup_nul() AnishMulay
2026-02-27 20:18 ` Al Viro
2026-02-27 20:42   ` Steven Rostedt
2026-02-27 21:15     ` [PATCH v2] tracefs: Use dentry name snapshots instead of heap allocation AnishMulay
2026-03-05 18:12       ` Steven Rostedt
2026-03-05 21:52       ` Steven Rostedt
2026-03-06 20:04         ` [PATCH v3] " AnishMulay
2026-03-06 21:41           ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox