Blame SOURCES/kexec-tools-2.0.4-kexec-i386-Add-cmdline_add_memmap_internal-to-reduce.patch

ab224c
From dc607e4d43308140b4cee6c4503ee71f32b827ad Mon Sep 17 00:00:00 2001
ab224c
Message-Id: <dc607e4d43308140b4cee6c4503ee71f32b827ad.1380269355.git.bhe@redhat.com>
ab224c
From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
ab224c
Date: Thu, 28 Mar 2013 21:09:59 +0800
ab224c
Subject: [PATCH] kexec: i386: Add cmdline_add_memmap_internal() to reduce the
ab224c
 code duplication
ab224c
ab224c
Functions:
ab224c
- cmdline_add_memmap()
ab224c
- cmdline_add_memmap_acpi()
ab224c
- cmdline_add_memmap_reserved()
ab224c
is kind of similar, So add a new function cmdline_add_memmap_internal() to
ab224c
hold the common codes, reducing the duplication.
ab224c
ab224c
Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
ab224c
Signed-off-by: Simon Horman <horms@verge.net.au>
ab224c
Signed-off-by: Baoquan He <bhe@redhat.com>
ab224c
---
ab224c
 kexec/arch/i386/crashdump-x86.c | 74 ++++++++++++++++++-----------------------
ab224c
 1 file changed, 33 insertions(+), 41 deletions(-)
ab224c
ab224c
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
ab224c
index 5462f8b..9ab648b 100644
ab224c
--- a/kexec/arch/i386/crashdump-x86.c
ab224c
+++ b/kexec/arch/i386/crashdump-x86.c
ab224c
@@ -685,13 +685,40 @@ static void ultoa(unsigned long i, char *str)
ab224c
 	}
ab224c
 }
ab224c
 
ab224c
+static void cmdline_add_memmap_internal(char *cmdline, unsigned long startk,
ab224c
+					unsigned long endk, int type)
ab224c
+{
ab224c
+	int cmdlen, len;
ab224c
+	char str_mmap[256], str_tmp[20];
ab224c
+
ab224c
+	strcpy (str_mmap, " memmap=");
ab224c
+	ultoa((endk-startk), str_tmp);
ab224c
+	strcat (str_mmap, str_tmp);
ab224c
+
ab224c
+	if (type == RANGE_RAM)
ab224c
+		strcat (str_mmap, "K@");
ab224c
+	else if (type == RANGE_RESERVED)
ab224c
+		strcat (str_mmap, "K$");
ab224c
+	else if (type == RANGE_ACPI || type == RANGE_ACPI_NVS)
ab224c
+		strcat (str_mmap, "K#");
ab224c
+
ab224c
+	ultoa(startk, str_tmp);
ab224c
+	strcat (str_mmap, str_tmp);
ab224c
+	strcat (str_mmap, "K");
ab224c
+	len = strlen(str_mmap);
ab224c
+	cmdlen = strlen(cmdline) + len;
ab224c
+	if (cmdlen > (COMMAND_LINE_SIZE - 1))
ab224c
+		die("Command line overflow\n");
ab224c
+	strcat(cmdline, str_mmap);
ab224c
+}
ab224c
+
ab224c
 /* Adds the appropriate memmap= options to command line, indicating the
ab224c
  * memory regions the new kernel can use to boot into. */
ab224c
 static int cmdline_add_memmap(char *cmdline, struct memory_range *memmap_p)
ab224c
 {
ab224c
 	int i, cmdlen, len;
ab224c
 	unsigned long min_sizek = 100;
ab224c
-	char str_mmap[256], str_tmp[20];
ab224c
+	char str_mmap[256];
ab224c
 
ab224c
 	/* Exact map */
ab224c
 	strcpy(str_mmap, " memmap=exactmap");
ab224c
@@ -713,18 +740,7 @@ static int cmdline_add_memmap(char *cmdline, struct memory_range *memmap_p)
ab224c
 		 * up precious command line length. */
ab224c
 		if ((endk - startk) < min_sizek)
ab224c
 			continue;
ab224c
-		strcpy (str_mmap, " memmap=");
ab224c
-		ultoa((endk-startk), str_tmp);
ab224c
-		strcat (str_mmap, str_tmp);
ab224c
-		strcat (str_mmap, "K@");
ab224c
-		ultoa(startk, str_tmp);
ab224c
-		strcat (str_mmap, str_tmp);
ab224c
-		strcat (str_mmap, "K");
ab224c
-		len = strlen(str_mmap);
ab224c
-		cmdlen = strlen(cmdline) + len;
ab224c
-		if (cmdlen > (COMMAND_LINE_SIZE - 1))
ab224c
-			die("Command line overflow\n");
ab224c
-		strcat(cmdline, str_mmap);
ab224c
+		cmdline_add_memmap_internal(cmdline, startk, endk, RANGE_RAM);
ab224c
 	}
ab224c
 
ab224c
 	dbgprintf("Command line after adding memmap\n");
ab224c
@@ -817,27 +833,15 @@ static enum coretype get_core_type(struct crash_elf_info *elf_info,
ab224c
 static int cmdline_add_memmap_acpi(char *cmdline, unsigned long start,
ab224c
 					unsigned long end)
ab224c
 {
ab224c
-	int cmdlen, len, align = 1024;
ab224c
+	int align = 1024;
ab224c
 	unsigned long startk, endk;
ab224c
-	char str_mmap[256], str_tmp[20];
ab224c
 
ab224c
 	if (!(end - start))
ab224c
 		return 0;
ab224c
 
ab224c
 	startk = start/1024;
ab224c
 	endk = (end + align - 1)/1024;
ab224c
-	strcpy (str_mmap, " memmap=");
ab224c
-	ultoa((endk - startk), str_tmp);
ab224c
-	strcat (str_mmap, str_tmp);
ab224c
-	strcat (str_mmap, "K#");
ab224c
-	ultoa(startk, str_tmp);
ab224c
-	strcat (str_mmap, str_tmp);
ab224c
-	strcat (str_mmap, "K");
ab224c
-	len = strlen(str_mmap);
ab224c
-	cmdlen = strlen(cmdline) + len;
ab224c
-	if (cmdlen > (COMMAND_LINE_SIZE - 1))
ab224c
-		die("Command line overflow\n");
ab224c
-	strcat(cmdline, str_mmap);
ab224c
+	cmdline_add_memmap_internal(cmdline, startk, endk, RANGE_ACPI);
ab224c
 
ab224c
 	dbgprintf("Command line after adding acpi memmap\n");
ab224c
 	dbgprintf("%s\n", cmdline);
ab224c
@@ -907,27 +911,15 @@ static void get_backup_area(struct kexec_info *info,
ab224c
 static int cmdline_add_memmap_reserved(char *cmdline, unsigned long start,
ab224c
 					unsigned long end)
ab224c
 {
ab224c
-	int cmdlen, len, align = 1024;
ab224c
+	int align = 1024;
ab224c
 	unsigned long startk, endk;
ab224c
-	char str_mmap[256], str_tmp[20];
ab224c
 
ab224c
 	if (!(end - start))
ab224c
 		return 0;
ab224c
 
ab224c
 	startk = start/1024;
ab224c
 	endk = (end + align - 1)/1024;
ab224c
-	strcpy (str_mmap, " memmap=");
ab224c
-	ultoa((endk - startk), str_tmp);
ab224c
-	strcat (str_mmap, str_tmp);
ab224c
-	strcat (str_mmap, "K$");
ab224c
-	ultoa(startk, str_tmp);
ab224c
-	strcat (str_mmap, str_tmp);
ab224c
-	strcat (str_mmap, "K");
ab224c
-	len = strlen(str_mmap);
ab224c
-	cmdlen = strlen(cmdline) + len;
ab224c
-	if (cmdlen > (COMMAND_LINE_SIZE - 1))
ab224c
-		die("Command line overflow\n");
ab224c
-	strcat(cmdline, str_mmap);
ab224c
+	cmdline_add_memmap_internal(cmdline, startk, endk, RANGE_RESERVED);
ab224c
 
ab224c
 #ifdef DEBUG
ab224c
 		printf("Command line after adding reserved memmap\n");
ab224c
-- 
ab224c
1.8.3.1
ab224c