Skip to contentSkip to conversation

of/fdt: Remove duplicate check in early_init_dt_scan_memory()

PATCH In review Qi Zheng 2 participants 3 messages Aug 14, 2020 – Aug 17, 2020 Device tree

lore
Share & tools
lore

Qi Zheng

author
#0 lore raw

PATCH 1/1 of/fdt: Remove duplicate check in early_init_dt_scan_memory()

When the value of the first reg is not NULL, there will be two repeated checks. So modify it.

---
 drivers/of/fdt.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/of/fdt.c +4 -3
index 4602e467ca8b..f54412c00642 100644
@@ -1002,10 +1002,11 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
 		return 0;
 
 	reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
-	if (reg == NULL)
+	if (reg == NULL) {
 		reg = of_get_flat_dt_prop(node, "reg", &l);
-	if (reg == NULL)
-		return 0;
+		if (reg == NULL)
+			return 0;
+	}
 
 	endp = reg + (l / sizeof(__be32));
 	hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Qi Zheng

When the value of the first reg is not NULL, there will be two repeated checks. So modify it.

I prefer the way it was. I'm sure the compiler is smart enough to throw out the 2nd check. Plus, 'linux,usable-memory' being present is the exception, so usually 'reg' will be NULL.

Quoted 27 lines
---
 drivers/of/fdt.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/of/fdt.c +4 -4
index 4602e467ca8b..f54412c00642 100644
@@ -1002,10 +1002,11 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
                return 0;
 
        reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
-       if (reg == NULL)
+       if (reg == NULL) {
                reg = of_get_flat_dt_prop(node, "reg", &l);
-       if (reg == NULL)
-               return 0;
+               if (reg == NULL)
+                       return 0;
+       }
 
        endp = reg + (l / sizeof(__be32));
        hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL);
--

2.25.1

author
#2 lore raw
Quoted 8 lines · Rob Herring
Quoted 3 lines · Qi Zheng

When the value of the first reg is not NULL, there will be two repeated checks. So modify it.

I prefer the way it was. I'm sure the compiler is smart enough to throw out the 2nd check. Plus, 'linux,usable-memory' being present is the exception, so usually 'reg' will be NULL.

I got it, and thanks for your review.
Please ignore this patch.

Quoted 28 lines
Quoted 28 lines
---
  drivers/of/fdt.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/of/fdt.c +4 -4
index 4602e467ca8b..f54412c00642 100644
@@ -1002,10 +1002,11 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
                 return 0;
 
         reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
-       if (reg == NULL)
+       if (reg == NULL) {
                 reg = of_get_flat_dt_prop(node, "reg", &l);
-       if (reg == NULL)
-               return 0;
+               if (reg == NULL)
+                       return 0;
+       }
 
         endp = reg + (l / sizeof(__be32));
         hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL);
--

2.25.1