Skip to contentSkip to conversation

x86/kaslr: remove useless code in mem_avoid_memmap

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

lore
Share & tools
lore

Qian Cai

author
#0 lore raw

PATCH 1/1 x86/kaslr: remove useless code in mem_avoid_memmap

MAX_MEMMAP_REGIONS is a macro that equal to 4. "i" is static local variable that default to 0. The comparison "i >= MAX_MEMMAP_REGIONS" will always be false.

---
 arch/x86/boot/compressed/kaslr.c | 3 ---
 1 file changed, 3 deletions(-)
arch/x86/boot/compressed/kaslr.c +0 -3
index 2e53c056ba20..a4a5a88edb94 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;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 3 lines · Qian Cai

MAX_MEMMAP_REGIONS is a macro that equal to 4. "i" is static local variable that default to 0. The comparison "i >= MAX_MEMMAP_REGIONS" will always be false.

Seems not true. mem_avoid_memmap() could be invoked many times if multiple memmap= added. It will carry the value accumulated from the past.

Quoted 23 lines
---
 arch/x86/boot/compressed/kaslr.c | 3 ---
 1 file changed, 3 deletions(-)
arch/x86/boot/compressed/kaslr.c +0 -3
index 2e53c056ba20..a4a5a88edb94 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;
Signature · 1 line
1.8.3.1
author
#2 lore raw
Quoted 8 lines · Baoquan He
Quoted 3 lines · Qian Cai

MAX_MEMMAP_REGIONS is a macro that equal to 4. "i" is static local variable that default to 0. The comparison "i >= MAX_MEMMAP_REGIONS" will always be false.

Seems not true. mem_avoid_memmap() could be invoked many times if multiple memmap= added. It will carry the value accumulated from the past.

Ah, I am still a newbie in C after all those years. Sorry for the noise.

Quoted 25 lines
Quoted 25 lines

---
 arch/x86/boot/compressed/kaslr.c | 3 ---

 1 file changed, 3 deletions(-)
arch/x86/boot/compressed/kaslr.c +0 -0
index 2e53c056ba20..a4a5a88edb94 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;
--
1.8.3.1