[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250912065256.1486112-3-thorsten.blum@linux.dev>
Date: Fri, 12 Sep 2025 08:52:57 +0200
From: Thorsten Blum <thorsten.blum@...ux.dev>
To: Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>,
Jan Kara <jack@...e.cz>
Cc: Thorsten Blum <thorsten.blum@...ux.dev>,
linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] initramfs: Use struct_size() helper to improve dir_add()
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@...ux.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
Powered by blists - more mailing lists