diff options
author | David Disseldorp <ddiss@suse.de> | 2022-05-09 18:29:19 -0700 |
---|---|---|
committer | akpm <akpm@linux-foundation.org> | 2022-05-09 18:29:19 -0700 |
commit | fcb7aedd2e90c4ad43f7f01827014df8c6f034a5 (patch) | |
tree | b77b3b6303bd2074a0e1e75a6aaa96168b3a6d11 /init/initramfs.c | |
parent | da028e4c4b0279eb49f80220d8f7cc62b4a57ccb (diff) | |
download | linux-fcb7aedd2e90c4ad43f7f01827014df8c6f034a5.tar.gz linux-fcb7aedd2e90c4ad43f7f01827014df8c6f034a5.tar.bz2 linux-fcb7aedd2e90c4ad43f7f01827014df8c6f034a5.zip |
initramfs: make dir_entry.name a flexible array member
dir_entry.name is currently allocated via a separate kstrdup(). Change it
to a flexible array member and allocate it along with struct dir_entry.
Link: https://lkml.kernel.org/r/20220404093429.27570-3-ddiss@suse.de
Signed-off-by: David Disseldorp <ddiss@suse.de>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Martin Wilck <mwilck@suse.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'init/initramfs.c')
-rw-r--r-- | init/initramfs.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/init/initramfs.c b/init/initramfs.c index 2f79b3ec0b40..656d2d71349f 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -130,17 +130,20 @@ static long __init do_utime(char *filename, time64_t mtime) static __initdata LIST_HEAD(dir_list); struct dir_entry { struct list_head list; - char *name; time64_t mtime; + char name[]; }; static void __init dir_add(const char *name, time64_t mtime) { - struct dir_entry *de = kmalloc(sizeof(struct dir_entry), GFP_KERNEL); + size_t nlen = strlen(name) + 1; + struct dir_entry *de; + + de = kmalloc(sizeof(struct dir_entry) + nlen, GFP_KERNEL); if (!de) panic_show_mem("can't allocate dir_entry buffer"); INIT_LIST_HEAD(&de->list); - de->name = kstrdup(name, GFP_KERNEL); + strscpy(de->name, name, nlen); de->mtime = mtime; list_add(&de->list, &dir_list); } @@ -151,7 +154,6 @@ static void __init dir_utime(void) list_for_each_entry_safe(de, tmp, &dir_list, list) { list_del(&de->list); do_utime(de->name, de->mtime); - kfree(de->name); kfree(de); } } |