devicetree: Check that fdt is not NULL in dt_available()
Up until now, for platforms that support DT, kvm-unit-tests would
unconditionally use DT to configure the system and the code made the
assumption that the fdt will always be a valid pointer.
On Arm systems that support both ACPI and DT, kvm-unit-tests plans to
follow the same convension as the Linux kernel: attempt to configure the
system using the DT first, then fallback to ACPI.
As a result, the fdt pointer can be NULL. Check for that in dt_available().
Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
[ Alex E: Minor changes to the commit message ]
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
diff --git a/lib/devicetree.c b/lib/devicetree.c
index 78c1f6f..3ff9d16 100644
--- a/lib/devicetree.c
+++ b/lib/devicetree.c
@@ -16,7 +16,7 @@
bool dt_available(void)
{
- return fdt_check_header(fdt) == 0;
+ return fdt && fdt_check_header(fdt) == 0;
}
int dt_get_nr_cells(int fdtnode, u32 *nr_address_cells, u32 *nr_size_cells)