From b28464a550c536296439b5785ed8852d1e15b35b Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 14 Apr 2020 15:02:51 +1000 Subject: Fix some potential unaligned accesses in dtc Because of the convention of packed representations in property layouts, it's not uncommon to have integer values in properties which aren't naturally aligned. Thus, there are several places in the dtc code where we cast a potentially unaligned byte pointer into an integer pointer and load it directly. On a number of architectures (including sparc64 and arm) this won't work and will cause a fault. In some cases it may be trapped and emulated by the kernel, but not always. Therefore, replace such direct unaligned reads with a helper which will handle unaligned data reads (a variant on the fdtXX_ld() functions already used in libfdt). Signed-off-by: David Gibson --- flattree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'flattree.c') diff --git a/flattree.c b/flattree.c index bd6977e..07f10d2 100644 --- a/flattree.c +++ b/flattree.c @@ -156,7 +156,7 @@ static void asm_emit_data(void *e, struct data d) emit_offset_label(f, m->ref, m->offset); while ((d.len - off) >= sizeof(uint32_t)) { - asm_emit_cell(e, fdt32_to_cpu(*((fdt32_t *)(d.val+off)))); + asm_emit_cell(e, dtb_ld32(d.val + off)); off += sizeof(uint32_t); } -- cgit v1.2.1