Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Thorsten Blum and committed by
Christian Brauner
e60625e7 84f1766b

+2 -1
+2 -1
init/initramfs.c
··· 19 19 #include <linux/init_syscalls.h> 20 20 #include <linux/umh.h> 21 21 #include <linux/security.h> 22 + #include <linux/overflow.h> 22 23 23 24 #include "do_mounts.h" 24 25 #include "initramfs_internal.h" ··· 153 152 { 154 153 struct dir_entry *de; 155 154 156 - de = kmalloc(sizeof(struct dir_entry) + nlen, GFP_KERNEL); 155 + de = kmalloc(struct_size(de, name, nlen), GFP_KERNEL); 157 156 if (!de) 158 157 panic_show_mem("can't allocate dir_entry buffer"); 159 158 INIT_LIST_HEAD(&de->list);