[U-Boot] [PATCH] cmd/fdt.c align data buffer to avoid unaligned word access

Since the compiler is free to place a char array to any address in memory (in this case the stack), also to a non word aligned address the function "fdt_prop_parse" runs into troubles upon it wants to write some (fdt32_t *) to such a variable (if it has been placed to a none word aligned address).
To avoid this we tell the compiler to always align this scratchpad to a word aligned address.
Signed-off-by: Bernhard Messerklinger bernhard.messerklinger@br-automation.com ---
cmd/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index d7654b2c4f..aa9cb4b3c1 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -256,7 +256,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *pathp; /* path */ char *prop; /* property */ int nodeoffset; /* node offset from libfdt */ - static char data[SCRATCHPAD]; /* storage for the property */ + static char data[SCRATCHPAD] __aligned(4);/* property storage */ const void *ptmp; int len; /* new length of the property */ int ret; /* return value */

On 09/28/2017 11:29 AM, Bernhard Messerklinger wrote:
Since the compiler is free to place a char array to any address in memory (in this case the stack), also to a non word aligned address the function "fdt_prop_parse" runs into troubles upon it wants to write some (fdt32_t *) to such a variable (if it has been placed to a none word aligned address).
To avoid this we tell the compiler to always align this scratchpad to a word aligned address.
Signed-off-by: Bernhard Messerklinger bernhard.messerklinger@br-automation.com
cmd/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmd/fdt.c b/cmd/fdt.c index d7654b2c4f..aa9cb4b3c1 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -256,7 +256,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *pathp; /* path */ char *prop; /* property */ int nodeoffset; /* node offset from libfdt */
static char data[SCRATCHPAD]; /* storage for the property */
const void *ptmp; int len; /* new length of the property */ int ret; /* return value */static char data[SCRATCHPAD] __aligned(4);/* property storage */
Reviewed-by: Hannes Schmelzer oe5hpm@oevsv.at Tested-by: Hannes Schmelzer oe5hpm@oevsv.at

On 28 September 2017 at 03:29, Bernhard Messerklinger bernhard.messerklinger@br-automation.com wrote:
Since the compiler is free to place a char array to any address in memory (in this case the stack), also to a non word aligned address the function "fdt_prop_parse" runs into troubles upon it wants to write some (fdt32_t *) to such a variable (if it has been placed to a none word aligned address).
To avoid this we tell the compiler to always align this scratchpad to a word aligned address.
Signed-off-by: Bernhard Messerklinger bernhard.messerklinger@br-automation.com
cmd/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

On 28 September 2017 at 03:29, Bernhard Messerklinger bernhard.messerklinger@br-automation.com wrote:
Since the compiler is free to place a char array to any address in memory (in this case the stack), also to a non word aligned address the function "fdt_prop_parse" runs into troubles upon it wants to write some (fdt32_t *) to such a variable (if it has been placed to a none word aligned address).
To avoid this we tell the compiler to always align this scratchpad to a word aligned address.
Signed-off-by: Bernhard Messerklinger bernhard.messerklinger@br-automation.com
cmd/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm thanks!
participants (4)
-
Bernhard Messerklinger
-
Hannes Schmelzer
-
Simon Glass
-
sjg@google.com