From: David Disseldorp <ddiss@suse.de>
To: linux-fsdevel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
David Disseldorp <ddiss@suse.de>
Subject: [RFC PATCH 5/6] initramfs: reuse buf for built-in and bootloader initramfs
Date: Tue, 15 Oct 2024 13:12:02 +0000 [thread overview]
Message-ID: <20241015133016.23468-6-ddiss@suse.de> (raw)
In-Reply-To: <20241015133016.23468-1-ddiss@suse.de>
cpio_buf is allocated and freed within unpack_to_rootfs(), while the
do_populate_rootfs() parent function may call it twice to unpack both
built-in and bootloader-provided cpio archives.
Move allocation out into the caller and reuse cpio_buf.
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
init/initramfs.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/init/initramfs.c b/init/initramfs.c
index c0aea453d2792..7594a176d8d91 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -486,16 +486,6 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len)
const char *compress_name;
static __initdata char msg_buf[64];
- /*
- * @cpio_buf is first used for staging the 110 byte newc/crc cpio
- * header, after which parse_header() converts and stashes fields into
- * corresponding types. The same buffer is then reused for file path
- * staging. 2 x PATH_MAX covers any possible symlink target.
- */
- cpio_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL);
- if (!cpio_buf)
- panic_show_mem("can't allocate buffers");
-
state = Start;
this_header = 0;
message = NULL;
@@ -538,7 +528,6 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len)
len -= my_inptr;
}
dir_utime();
- kfree(cpio_buf);
return message;
}
@@ -688,8 +677,20 @@ static void __init populate_initrd_image(char *err)
static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
{
+ char *err;
+
+ /*
+ * @cpio_buf is first used for staging the 110 byte newc/crc cpio
+ * header, after which parse_header() converts and stashes fields into
+ * corresponding types. The same buffer is then reused for file path
+ * staging. 2 x PATH_MAX covers any possible symlink target.
+ */
+ cpio_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL);
+ if (!cpio_buf)
+ panic_show_mem("can't allocate buffers");
+
/* Load the built in initramfs */
- char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
+ err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
if (err)
panic_show_mem("%s", err); /* Failed to decompress INTERNAL initramfs */
@@ -711,6 +712,7 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
}
done:
+ kfree(cpio_buf);
security_initramfs_populated();
/*
--
2.43.0
next prev parent reply other threads:[~2024-10-15 13:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 13:11 [RFC PATCH 0/6] initramfs: reduce buffer footprint David Disseldorp
2024-10-15 13:11 ` [RFC PATCH 1/6] vsprintf: add simple_strntoul David Disseldorp
2024-10-15 13:11 ` [RFC PATCH 2/6] initramfs: avoid memcpy for hex header fields David Disseldorp
2024-10-15 13:12 ` [RFC PATCH 3/6] initramfs: remove extra symlink path buffer David Disseldorp
2024-10-15 13:12 ` [RFC PATCH 4/6] initramfs: merge header_buf and name_buf David Disseldorp
2024-10-15 13:12 ` David Disseldorp [this message]
2024-10-15 13:12 ` [RFC PATCH 6/6] initramfs: avoid static buffer for error message David Disseldorp
2024-10-15 23:34 ` [RFC PATCH 0/6] initramfs: reduce buffer footprint Al Viro
2024-10-16 2:42 ` David Disseldorp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241015133016.23468-6-ddiss@suse.de \
--to=ddiss@suse.de \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.