public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] initramfs: Use struct_size() helper to improve dir_add()
@ 2025-09-12  6:52 Thorsten Blum
  2025-09-15 12:43 ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-09-12  6:52 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara
  Cc: Thorsten Blum, linux-fsdevel, linux-kernel

Use struct_size() to calculate the number of bytes to allocate for a new
directory entry.  No functional changes.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 init/initramfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index 6745e3fbc7ab..6ddbfb17fb8f 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -19,6 +19,7 @@
 #include <linux/init_syscalls.h>
 #include <linux/umh.h>
 #include <linux/security.h>
+#include <linux/overflow.h>
 
 #include "do_mounts.h"
 #include "initramfs_internal.h"
@@ -152,7 +153,7 @@ static void __init dir_add(const char *name, size_t nlen, time64_t mtime)
 {
 	struct dir_entry *de;
 
-	de = kmalloc(sizeof(struct dir_entry) + nlen, GFP_KERNEL);
+	de = kmalloc(struct_size(de, name, nlen), GFP_KERNEL);
 	if (!de)
 		panic_show_mem("can't allocate dir_entry buffer");
 	INIT_LIST_HEAD(&de->list);
-- 
2.51.0


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

* Re: [PATCH] initramfs: Use struct_size() helper to improve dir_add()
  2025-09-12  6:52 [PATCH] initramfs: Use struct_size() helper to improve dir_add() Thorsten Blum
@ 2025-09-15 12:43 ` Christian Brauner
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2025-09-15 12:43 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Christian Brauner, linux-fsdevel, linux-kernel, Alexander Viro,
	Jan Kara

On Fri, 12 Sep 2025 08:52:57 +0200, Thorsten Blum wrote:
> Use struct_size() to calculate the number of bytes to allocate for a new
> directory entry.  No functional changes.
> 
> 

Applied to the vfs-6.18.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.18.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-6.18.misc

[1/1] initramfs: Use struct_size() helper to improve dir_add()
      https://git.kernel.org/vfs/vfs/c/e60625e7ce10

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

end of thread, other threads:[~2025-09-15 12:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-12  6:52 [PATCH] initramfs: Use struct_size() helper to improve dir_add() Thorsten Blum
2025-09-15 12:43 ` Christian Brauner

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