[2/2,v3] of: Add check to of_scan_flat_dt() before accessing initial_boot_params
diff mbox

Message ID .WUbz5chXyR@loki
State Accepted
Delegated to: Ralf Baechle
Headers show

Commit Message

Tobias Wolf Nov. 23, 2016, 9:40 a.m. UTC
An empty __dtb_start to __dtb_end section might result in initial_boot_params 
being null for arch/mips/ralink. This showed that the boot process hangs 
indefinitely in of_scan_flat_dt().

Signed-off-by: Tobias Wolf <>
---

Dear Sergei,

Missed that warning completely during compilation of a testable image for my 
device. I regenerated the patch based on your input (for 4.9-rc6 this time) 
and based the check on the local blob variable this time.

Haven't seen any warnings this time.

Hope it's correct that I reference the new patch version each time in the 
subject line.

Best regards
Tobias

Btw.: Last e-mail I wanted to list occurrences EINVAL would break existing 
code. One is kernel/prom.c in arch/microblaze.

Patch
diff mbox

--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -738,9 +738,12 @@ 
 	const char *pathp;
 	int offset, rc = 0, depth = -1;
 
-        for (offset = fdt_next_node(blob, -1, &depth);
-             offset >= 0 && depth >= 0 && !rc;
-             offset = fdt_next_node(blob, offset, &depth)) {
+	if (!blob)
+		return 0;
+
+	for (offset = fdt_next_node(blob, -1, &depth);
+	     offset >= 0 && depth >= 0 && !rc;
+	     offset = fdt_next_node(blob, offset, &depth)) {
 
 		pathp = fdt_get_name(blob, offset, NULL);
 		if (*pathp == '/')