]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
OF: Prevent unaligned access in of_alias_scan()
authorPaul Burton <paul.burton@imgtec.com>
Fri, 23 Sep 2016 15:38:27 +0000 (16:38 +0100)
committerRalf Baechle <ralf@linux-mips.org>
Tue, 3 Jan 2017 15:34:48 +0000 (16:34 +0100)
When allocating a struct alias_prop, of_alias_scan() only requested that
it be aligned on a 4 byte boundary. The struct contains pointers which
leads to us attempting 64 bit writes on 64 bit systems, and if the CPU
doesn't support unaligned memory accesses then this causes problems -
for example on some MIPS64r2 CPUs including the "mips64r2-generic" QEMU
emulated CPU it will trigger an address error exception.

Fix this by requesting alignment for the struct alias_prop allocation
matching that which the compiler expects, using the __alignof__ keyword.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Acked-by: Rob Herring <robh@kernel.org>
Reviewed-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/14306/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
drivers/of/base.c

index d4bea3c797d6a7b6a4d28c55cfdff1d30d03cc16..84cf2f3f396cbb2ccdeed8c8af679fab74a761d9 100644 (file)
@@ -2112,7 +2112,7 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
                        continue;
 
                /* Allocate an alias_prop with enough space for the stem */
-               ap = dt_alloc(sizeof(*ap) + len + 1, 4);
+               ap = dt_alloc(sizeof(*ap) + len + 1, __alignof__(*ap));
                if (!ap)
                        continue;
                memset(ap, 0, sizeof(*ap) + len + 1);