Skip to contentSkip to conversation

x86/kaslr: simplify the code in mem_avoid_memmap()

PATCH In review Qian Cai 2 participants 3 messages Aug 22, 2019 – Sep 5, 2019 x86

lore
Share & tools
lore

Qian Cai

author
#0 lore raw

PATCH 1/1 x86/kaslr: simplify the code in mem_avoid_memmap()

If "i >= MAX_MEMMAP_REGIONS" already when entering mem_avoid_memmap(), even without the return statement the loop will not run anyway. The only time it needs to set "memmap_too_large = true" in this situation is "memmap_too_large" is "false" currently. Hence, the code could be simplified.

---
 arch/x86/boot/compressed/kaslr.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/boot/compressed/kaslr.c +1 -4
index 2e53c056ba20..35c6942fb95b 100644
@@ -176,9 +176,6 @@ static void mem_avoid_memmap(char *str)
 {
 	static int i;
 
-	if (i >= MAX_MEMMAP_REGIONS)
-		return;
-
 	while (str && (i < MAX_MEMMAP_REGIONS)) {
 		int rc;
 		unsigned long long start, size;
@@ -206,7 +203,7 @@ static void mem_avoid_memmap(char *str)
 	}
 
 	/* More than 4 memmaps, fail kaslr */
-	if ((i >= MAX_MEMMAP_REGIONS) && str)
+	if (i >= MAX_MEMMAP_REGIONS && !memmap_too_large)
 		memmap_too_large = true;
 }
 
Signature · 1 line
1.8.3.1
author
#1 lore raw

Ping. Please take a look at this trivial patch.

Quoted 35 lines · Qian Cai

If "i >= MAX_MEMMAP_REGIONS" already when entering mem_avoid_memmap(), even without the return statement the loop will not run anyway. The only time it needs to set "memmap_too_large = true" in this situation is "memmap_too_large" is "false" currently. Hence, the code could be simplified.

---
 arch/x86/boot/compressed/kaslr.c | 5 +----

 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/boot/compressed/kaslr.c +0 -0
index 2e53c056ba20..35c6942fb95b 100644
@@ -176,9 +176,6 @@ static void mem_avoid_memmap(char *str)
  {
  	static int i;

arch/x86/boot/compressed/kaslr.c +0 -3
-	if (i >= MAX_MEMMAP_REGIONS)
-		return;
-

  while (str && (i < MAX_MEMMAP_REGIONS)) {
  int rc;
  unsigned long long start, size;

arch/x86/boot/compressed/kaslr.c +0 -0
@@ -206,7 +203,7 @@ static void mem_avoid_memmap(char *str)
  	}


  /* More than 4 memmaps, fail kaslr */

arch/x86/boot/compressed/kaslr.c +1 -1
-	if ((i >= MAX_MEMMAP_REGIONS) && str)
+	if (i >= MAX_MEMMAP_REGIONS && !memmap_too_large)

  memmap_too_large = true;
 }

#2 lore raw
In reply to Qian Cai
Quoted 5 lines · Qian Cai

If "i >= MAX_MEMMAP_REGIONS" already when entering mem_avoid_memmap(), even without the return statement the loop will not run anyway. The only time it needs to set "memmap_too_large = true" in this situation is "memmap_too_large" is "false" currently. Hence, the code could be simplified.

It seems not improved much. If far more than MAX_MEMMAP_REGIONS 'memmap=' specified, the if condition checking looks more straightforward. Anyway, it's not simplifying much, in my opinion.

Thanks
Baoquan

Quoted 32 lines
---
 arch/x86/boot/compressed/kaslr.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/boot/compressed/kaslr.c +1 -4
index 2e53c056ba20..35c6942fb95b 100644
@@ -176,9 +176,6 @@ static void mem_avoid_memmap(char *str)
 {
 	static int i;
 
-	if (i >= MAX_MEMMAP_REGIONS)
-		return;
-
 	while (str && (i < MAX_MEMMAP_REGIONS)) {
 		int rc;
 		unsigned long long start, size;
@@ -206,7 +203,7 @@ static void mem_avoid_memmap(char *str)
 	}
 
 	/* More than 4 memmaps, fail kaslr */
-	if ((i >= MAX_MEMMAP_REGIONS) && str)
+	if (i >= MAX_MEMMAP_REGIONS && !memmap_too_large)
 		memmap_too_large = true;
 }
 
Signature · 1 line
1.8.3.1