[syslinux:elflink] ldlinux: Don't alloc initramfs unless initrd= is specified

syslinux-bot for Matt Fleming matt.fleming at intel.com
Mon Mar 26 15:36:07 PDT 2012


Commit-ID:  9f6b6b08feb709ba8af0571ffec0b008b5d255d9
Gitweb:     http://www.syslinux.org/commit/9f6b6b08feb709ba8af0571ffec0b008b5d255d9
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Fri, 9 Mar 2012 12:49:50 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Fri, 23 Mar 2012 16:56:16 +0000

ldlinux: Don't alloc initramfs unless initrd= is specified

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++;


More information about the Syslinux-commits mailing list