[RFC PATCH 6/6] initramfs: avoid static buffer for error message

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



With cpio_buf now allocated / freed by the unpack_to_rootfs() caller,
FSM-exit error messages can now be stashed in cpio_buf instead of in a
static buffer.

Before:
   text    data     bss     dec     hex filename
   7423    1062       8    8493    212d ./init/initramfs.o

After:
   text    data     bss     dec     hex filename
   7423     966       8    8397    20cd ./init/initramfs.o

Signed-off-by: David Disseldorp <ddiss@xxxxxxx>
---
 init/initramfs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index 7594a176d8d91..815a5daaa27ce 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -484,7 +484,6 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len)
 	long written;
 	decompress_fn decompress;
 	const char *compress_name;
-	static __initdata char msg_buf[64];
 
 	state = Start;
 	this_header = 0;
@@ -514,10 +513,12 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len)
 				error("decompressor failed");
 		} else if (compress_name) {
 			if (!message) {
-				snprintf(msg_buf, sizeof msg_buf,
+				/* FSM exit: cpio_buf reuse is safe */
+				snprintf(cpio_buf,
+					 N_ALIGN(PATH_MAX) + PATH_MAX + 1,
 					 "compression method %s not configured",
 					 compress_name);
-				message = msg_buf;
+				message = cpio_buf;
 			}
 		} else
 			error("invalid magic at start of compressed archive");
@@ -684,6 +685,7 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
 	 * 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.
+	 * On error, @err may point to a @cpio_buf backed error message.
 	 */
 	cpio_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL);
 	if (!cpio_buf)
-- 
2.43.0





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux