From: Thorsten Blum Date: Fri, 12 Sep 2025 06:52:57 +0000 (+0200) Subject: initramfs: Use struct_size() helper to improve dir_add() X-Git-Tag: v6.18-rc1~242^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e60625e7ce10f696690d9e36a9f32fc7c1897f79;p=thirdparty%2Flinux.git 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 Signed-off-by: Christian Brauner --- diff --git a/init/initramfs.c b/init/initramfs.c index 097673b97784d..c607f4d681ef6 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -19,6 +19,7 @@ #include #include #include +#include #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);