Commit 4519668b29bb8422ceca8e7ca9a35d5af0afe959

Authored by Marcel Ziswiler
Committed by Tom Rini
1 parent 285e266b41

mtd/nand/ubi: assortment of alignment fixes

Various U-Boot adoptions/extensions to MTD/NAND/UBI did not take buffer
alignment into account which led to failures of the following form:

ERROR: v7_dcache_inval_range - start address is not aligned - 0x1f7f0108
ERROR: v7_dcache_inval_range - stop address is not aligned - 0x1f7f1108

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Scott Wood <scottwood@freescale.com>
[trini: Add __UBOOT__ hunk to lib/zlib/zutil.c due to malloc.h in common.h]
Signed-off-by: Tom Rini <trini@konsulko.com>

Showing 7 changed files with 19 additions and 7 deletions Side-by-side Diff

... ... @@ -363,7 +363,7 @@
363 363 tbuf_size = vol->usable_leb_size;
364 364 if (size < tbuf_size)
365 365 tbuf_size = ALIGN(size, ubi->min_io_size);
366   - tbuf = malloc(tbuf_size);
  366 + tbuf = malloc_cache_aligned(tbuf_size);
367 367 if (!tbuf) {
368 368 printf("NO MEM\n");
369 369 return ENOMEM;
drivers/mtd/nand/nand_util.c
... ... @@ -839,7 +839,7 @@
839 839  
840 840 patt_count = ARRAY_SIZE(patterns);
841 841  
842   - buf = malloc(nand->erasesize);
  842 + buf = malloc_cache_aligned(nand->erasesize);
843 843 if (buf == NULL) {
844 844 puts("Out of memory for erase block buffer\n");
845 845 return -ENOMEM;
... ... @@ -57,7 +57,8 @@
57 57 {
58 58 struct inode *inode;
59 59  
60   - inode = (struct inode *)malloc(sizeof(struct ubifs_inode));
  60 + inode = (struct inode *)malloc_cache_aligned(
  61 + sizeof(struct ubifs_inode));
61 62 if (inode) {
62 63 inode->i_ino = ino;
63 64 inode->i_sb = sb;
... ... @@ -104,7 +105,7 @@
104 105 /*
105 106 * Allocate and use new inode
106 107 */
107   - ino = (struct inode *)malloc(sizeof(struct ubifs_inode));
  108 + ino = (struct inode *)malloc_cache_aligned(sizeof(struct ubifs_inode));
108 109 memcpy(ino, inode, sizeof(struct ubifs_inode));
109 110  
110 111 /*
... ... @@ -108,7 +108,7 @@
108 108 struct crypto_comp *ptr;
109 109 int i = 0;
110 110  
111   - ptr = malloc(sizeof(struct crypto_comp));
  111 + ptr = malloc_cache_aligned(sizeof(struct crypto_comp));
112 112 while (i < UBIFS_COMPR_TYPES_CNT) {
113 113 comp = ubifs_compressors[i];
114 114 if (!comp) {
... ... @@ -723,7 +723,7 @@
723 723 * destination area to a multiple of
724 724 * UBIFS_BLOCK_SIZE.
725 725 */
726   - buff = malloc(UBIFS_BLOCK_SIZE);
  726 + buff = malloc_cache_aligned(UBIFS_BLOCK_SIZE);
727 727 if (!buff) {
728 728 printf("%s: Error, malloc fails!\n",
729 729 __func__);
... ... @@ -1060,6 +1060,15 @@
1060 1060 #define DEFINE_CACHE_ALIGN_BUFFER(type, name, size) \
1061 1061 DEFINE_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
1062 1062  
  1063 +#ifndef __ASSEMBLY__
  1064 +#include <malloc.h>
  1065 +
  1066 +static inline void *malloc_cache_aligned(size_t size)
  1067 +{
  1068 + return memalign(ARCH_DMA_MINALIGN, ALIGN(size, ARCH_DMA_MINALIGN));
  1069 +}
  1070 +#endif
  1071 +
1063 1072 /*
1064 1073 * check_member() - Check the offset of a structure member
1065 1074 *
... ... @@ -25,7 +25,7 @@
25 25 size *= items;
26 26 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
27 27  
28   - p = malloc (size);
  28 + p = malloc_cache_aligned(size);
29 29  
30 30 return (p);
31 31 }
... ... @@ -43,10 +43,12 @@
43 43 */
44 44 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
45 45  
  46 +#ifndef __UBOOT__
46 47 #ifndef STDC
47 48 extern voidp malloc OF((uInt size));
48 49 extern voidp calloc OF((uInt items, uInt size));
49 50 extern void free OF((voidpf ptr));
  51 +#endif
50 52 #endif
51 53  
52 54 voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)