aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
authorThorsten Blum <thorsten.blum@linux.dev>2026-04-17 11:42:40 +0200
committerChristian Brauner <brauner@kernel.org>2026-05-21 09:32:47 +0200
commit0447533faeeefc02c2979abf46c4dcbbbe6d9871 (patch)
treeabce5c751606722e5c2da3a38d5a4eee062432de /fs
parent80008c75f4523076a0ada0ac883ad8890b830ec9 (diff)
downloadlinux-next-history-0447533faeeefc02c2979abf46c4dcbbbe6d9871.tar.gz
dcache: use kmalloc_flex() in __d_alloc
Use kmalloc_flex() when allocating a new 'struct external_name' in __d_alloc() to replace offsetof() and the open-coded size arithmetic, and to keep the size type-safe. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Link: https://patch.msgid.link/20260417094238.551114-3-thorsten.blum@linux.dev Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Jori Koolstra <jkoolstra@xs4all.nl> Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/dcache.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index 2c61aeea41f45..8ffc4ef79bbab 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1820,10 +1820,10 @@ static struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
name = &slash_name;
dname = dentry->d_shortname.string;
} else if (name->len > DNAME_INLINE_LEN-1) {
- size_t size = offsetof(struct external_name, name[1]);
- struct external_name *p = kmalloc(size + name->len,
- GFP_KERNEL_ACCOUNT |
- __GFP_RECLAIMABLE);
+ struct external_name *p;
+
+ p = kmalloc_flex(*p, name, name->len + 1,
+ GFP_KERNEL_ACCOUNT | __GFP_RECLAIMABLE);
if (!p) {
kmem_cache_free(dentry_cache, dentry);
return NULL;