* [PATCH] dcache: use kmalloc_flex() in __d_alloc
@ 2026-04-17 9:42 Thorsten Blum
2026-04-17 12:00 ` Jori Koolstra
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-04-17 9:42 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: Thorsten Blum, linux-fsdevel, linux-kernel
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>
---
fs/dcache.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index dbcbd0affb26..4568f9530166 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1753,10 +1753,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;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] dcache: use kmalloc_flex() in __d_alloc
2026-04-17 9:42 [PATCH] dcache: use kmalloc_flex() in __d_alloc Thorsten Blum
@ 2026-04-17 12:00 ` Jori Koolstra
2026-04-18 10:30 ` Jan Kara
2026-04-21 11:35 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Jori Koolstra @ 2026-04-17 12:00 UTC (permalink / raw)
To: Thorsten Blum
Cc: Alexander Viro, Christian Brauner, Jan Kara, linux-fsdevel,
linux-kernel
On Fri, Apr 17, 2026 at 11:42:40AM +0200, Thorsten Blum wrote:
> 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>
> ---
> fs/dcache.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/dcache.c b/fs/dcache.c
> index dbcbd0affb26..4568f9530166 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -1753,10 +1753,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;
Looks reasonable to me. Is the idea to completely outphase this old way
of requesting memory for structs with flexible array members?
Feel free to add:
Reviewed-by: Jori Koolstra <jkoolstra@xs4all.nl>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dcache: use kmalloc_flex() in __d_alloc
2026-04-17 9:42 [PATCH] dcache: use kmalloc_flex() in __d_alloc Thorsten Blum
2026-04-17 12:00 ` Jori Koolstra
@ 2026-04-18 10:30 ` Jan Kara
2026-04-21 11:35 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2026-04-18 10:30 UTC (permalink / raw)
To: Thorsten Blum
Cc: Alexander Viro, Christian Brauner, Jan Kara, linux-fsdevel,
linux-kernel
On Fri 17-04-26 11:42:40, Thorsten Blum wrote:
> 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>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/dcache.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/dcache.c b/fs/dcache.c
> index dbcbd0affb26..4568f9530166 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -1753,10 +1753,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;
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dcache: use kmalloc_flex() in __d_alloc
2026-04-17 9:42 [PATCH] dcache: use kmalloc_flex() in __d_alloc Thorsten Blum
2026-04-17 12:00 ` Jori Koolstra
2026-04-18 10:30 ` Jan Kara
@ 2026-04-21 11:35 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2026-04-21 11:35 UTC (permalink / raw)
To: Thorsten Blum
Cc: Christian Brauner, linux-fsdevel, linux-kernel, Alexander Viro,
Jan Kara
On Fri, 17 Apr 2026 11:42:40 +0200, Thorsten Blum wrote:
> 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.
Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree.
Patches in the vfs-7.2.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.2.misc
[1/1] dcache: use kmalloc_flex() in __d_alloc
https://git.kernel.org/vfs/vfs/c/4f521e4554a7
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-21 11:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-17 9:42 [PATCH] dcache: use kmalloc_flex() in __d_alloc Thorsten Blum
2026-04-17 12:00 ` Jori Koolstra
2026-04-18 10:30 ` Jan Kara
2026-04-21 11:35 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox