[syslinux] [PATCH 17/19] ldlinux: Don't alloc initramfs unless initrd= is specified

Matt Fleming matt at console-pimps.org
Fri Mar 23 11:02:51 PDT 2012


From: Matt Fleming <matt.fleming at intel.com>

It only makes sense to allocate memory for 'initramfs' if an initrd=
argument was on the command line, otherwise we're wasting memory.

Furthermore needlessly allocating 'initramfs' actually caused old
kernels, such as memtest86, to fail to run because of the following
check in syslinux_boot_kernel(),

    if (initramfs && hdr.version < 0x0200)
        goto bail;              /* initrd/initramfs not supported */

Move the allocation after we've checked for and found an initrd=
argument.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>
---
 com32/elflink/ldlinux/kernel.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/com32/elflink/ldlinux/kernel.c b/com32/elflink/ldlinux/kernel.c
index ed91b76..6cda659 100644
--- a/com32/elflink/ldlinux/kernel.c
+++ b/com32/elflink/ldlinux/kernel.c
@@ -16,7 +16,7 @@ const char *append = NULL;
 int new_linux_kernel(char *okernel, char *ocmdline)
 {
 	const char *kernel_name;
-	struct initramfs *initramfs;
+	struct initramfs *initramfs = NULL;
 	char *temp;
 	void *kernel_data;
 	size_t kernel_len;
@@ -99,16 +99,16 @@ int new_linux_kernel(char *okernel, char *ocmdline)
 	if (!opt_quiet)
 		printf("ok\n");
 
-	/* Initialize the initramfs chain */
-	initramfs = initramfs_init();
-	if (!initramfs)
-		goto bail;
-
 	/* Find and load initramfs */
 	temp = strstr(cmdline, "initrd=");
 	if (temp) {
 		i = 0;
 
+		/* Initialize the initramfs chain */
+		initramfs = initramfs_init();
+		if (!initramfs)
+			goto bail;
+
 		temp += strlen("initrd=");
 		while (*temp != ' ' && *temp)
 			initrd_name[i++] = *temp++;
-- 
1.7.4.4




More information about the Syslinux mailing list