From 0ca970dce354cff6ad68edbf27f0559d02be5915 Mon Sep 17 00:00:00 2001 From: Chih-Min Chao Date: Sun, 15 Nov 2020 22:10:18 -0800 Subject: dts: extract cpu node checking as helper function all atrribute in cpu could leverage it Signed-off-by: Chih-Min Chao --- riscv/dts.cc | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'riscv/dts.cc') diff --git a/riscv/dts.cc b/riscv/dts.cc index 9469e3f..883ceb1 100644 --- a/riscv/dts.cc +++ b/riscv/dts.cc @@ -225,6 +225,24 @@ static int fdt_get_node_addr_size(void *fdt, int node, reg_t *addr, return 0; } +static int check_cpu_node(void *fdt, int cpu_offset) +{ + int len; + const void *prop; + + if (!fdt || cpu_offset < 0) + return -EINVAL; + + prop = fdt_getprop(fdt, cpu_offset, "device_type", &len); + if (!prop || !len) + return -EINVAL; + if (strncmp ((char *)prop, "cpu", strlen ("cpu"))) + return -EINVAL; + + return 0; +} + + int fdt_get_offset(void *fdt, const char *field) { return fdt_path_offset(fdt, field); @@ -291,17 +309,11 @@ int fdt_parse_pmp_alignment(void *fdt, reg_t *pmp_align, int fdt_parse_mmu_type(void *fdt, int cpu_offset, char *mmu_type) { - int len; + int len, rc; const void *prop; - if (!fdt || cpu_offset < 0) - return -EINVAL; - - prop = fdt_getprop(fdt, cpu_offset, "device_type", &len); - if (!prop || !len) - return -EINVAL; - if (strncmp ((char *)prop, "cpu", strlen ("cpu"))) - return -EINVAL; + if ((rc = check_cpu_node(fdt, cpu_offset)) < 0) + return rc; prop = fdt_getprop(fdt, cpu_offset, "mmu-type", &len); if (!prop || !len) -- cgit v1.1