Skip to contentSkip to conversation

of/flattree: Fix crash when device tree absent

PATCH New Grant Likely 1 participant 1 message Jun 25, 2010 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of/flattree: Fix crash when device tree absent

This patch fixes the condition where device tree support is compiled in, but no device tree was proved by firmware. It makes of_platform_bus_probe() explicitly check for a NULL device tree pointer, and adds an error message if the device tree was unable to be flattened.

---
 drivers/of/fdt.c      |    2 ++
 drivers/of/platform.c |    2 ++
 2 files changed, 4 insertions(+), 0 deletions(-)
drivers/of/fdt.c +2 -0
index b6987bb..beda593 100644
@@ -94,6 +94,8 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node,
 			break;
 	} while (1);
 
+	if (rc)
+		pr_err("Failed to unflatten device tree blob.  rc=%i\n", rc);
 	return rc;
 }
 
drivers/of/platform.c +2 -0
index 3eb4cf6..1f5a210 100644
@@ -640,6 +640,8 @@ int of_platform_bus_probe(struct device_node *root,
 		root = of_find_node_by_path("/");
 	else
 		of_node_get(root);
+	if (root == NULL)
+		return -EINVAL;
 
 	pr_debug("of_platform_bus_probe()\n");
 	pr_debug(" starting at: %s\n", root->full_name);