aboutsummaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorThorsten Blum <thorsten.blum@linux.dev>2025-09-12 08:52:57 +0200
committerChristian Brauner <brauner@kernel.org>2025-09-15 14:42:56 +0200
commite60625e7ce10f696690d9e36a9f32fc7c1897f79 (patch)
treea685e9ed4caf0b9fc268d2b3655b0c1b076043d3 /init
parentinitrd: Fix unused variable warning in rd_load_image() on s390 (diff)
downloadlinux-e60625e7ce10f696690d9e36a9f32fc7c1897f79.tar.gz
linux-e60625e7ce10f696690d9e36a9f32fc7c1897f79.zip
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@linux.dev> Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'init')
-rw-r--r--init/initramfs.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/init/initramfs.c b/init/initramfs.c
index 097673b97784..c607f4d681ef 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);