* [PATCH] fs: combine __d_alloc's allocations into one
@ 2025-03-13 6:45 Ahmad Fatoum
2025-03-14 15:54 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-03-13 6:45 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Instead of doing two allocations, one for the struct dentry and one for
the full name, just do one allocation and place them after each other.
This has the extra benefit of fixing a leak of the dentry allocation
when the second allocation for the file name fails.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 13 ++++---------
include/linux/dcache.h | 2 +-
2 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 96ca60341ea4..f8b7340d809d 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -795,7 +795,6 @@ static void dentry_kill(struct dentry *dentry)
dput(dentry->d_parent);
list_del(&dentry->d_child);
- free(dentry->name);
free(dentry);
}
@@ -1427,15 +1426,11 @@ static struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
{
struct dentry *dentry;
- dentry = xzalloc(sizeof(*dentry));
- if (!dentry)
- return NULL;
-
if (!name)
name = &slash_name;
- dentry->name = malloc(name->len + 1);
- if (!dentry->name)
+ dentry = xzalloc(struct_size(dentry, name, name->len + 1));
+ if (!dentry)
return NULL;
memcpy(dentry->name, name->name, name->len);
@@ -3006,9 +3001,9 @@ static char *__dpath(struct dentry *dentry, struct dentry *root)
ppath = __dpath(dentry->d_parent, root);
if (ppath)
- res = basprintf("%s/%s", ppath, dentry->name);
+ res = basprintf("%s/%s", ppath, dentry->d_name.name);
else
- res = basprintf("/%s", dentry->name);
+ res = basprintf("/%s", dentry->d_name.name);
free(ppath);
return res;
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index ed7e5c2cbcff..1b51a5656703 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -80,7 +80,7 @@ struct dentry {
struct dcookie_struct *d_cookie; /* cookie, if any */
#endif
int d_mounted;
- unsigned char *name; /* all names */
+ unsigned char name[]; /* all names */
};
struct dentry_operations {
--
2.39.5
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-14 15:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-13 6:45 [PATCH] fs: combine __d_alloc's allocations into one Ahmad Fatoum
2025-03-14 15:54 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox