]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
mtd/nand/ubi: assortment of alignment fixes
authorMarcel Ziswiler <marcel.ziswiler@toradex.com>
Tue, 18 Aug 2015 11:06:37 +0000 (13:06 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 10 Sep 2015 09:29:50 +0000 (11:29 +0200)
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>
common/cmd_ubi.c
drivers/mtd/nand/nand_util.c
fs/ubifs/super.c
fs/ubifs/ubifs.c
include/common.h
lib/gzip.c
lib/zlib/zutil.c

index cbc10c549474690f9adcb08c4c95d1ba479ed323..10eea655701e793fd6641f2e22972b78c1651f76 100644 (file)
@@ -363,7 +363,7 @@ int ubi_volume_read(char *volume, char *buf, size_t size)
        tbuf_size = vol->usable_leb_size;
        if (size < tbuf_size)
                tbuf_size = ALIGN(size, ubi->min_io_size);
-       tbuf = malloc(tbuf_size);
+       tbuf = malloc_cache_aligned(tbuf_size);
        if (!tbuf) {
                printf("NO MEM\n");
                return ENOMEM;
index ee2c24df3b852f47214e7e885bb6cbfa9f9d4a8b..21b4a618ce503c98bce2c861bc1e876941d83dc6 100644 (file)
@@ -839,7 +839,7 @@ int nand_torture(nand_info_t *nand, loff_t offset)
 
        patt_count = ARRAY_SIZE(patterns);
 
-       buf = malloc(nand->erasesize);
+       buf = malloc_cache_aligned(nand->erasesize);
        if (buf == NULL) {
                puts("Out of memory for erase block buffer\n");
                return -ENOMEM;
index 10f8fff0be6f7c1cb4bbecdfc673174901c72e28..0bf52db0cef5c1ce0ecb271ab234e5cd5a174d03 100644 (file)
@@ -57,7 +57,8 @@ struct inode *iget_locked(struct super_block *sb, unsigned long ino)
 {
        struct inode *inode;
 
-       inode = (struct inode *)malloc(sizeof(struct ubifs_inode));
+       inode = (struct inode *)malloc_cache_aligned(
+                       sizeof(struct ubifs_inode));
        if (inode) {
                inode->i_ino = ino;
                inode->i_sb = sb;
@@ -104,7 +105,7 @@ void iput(struct inode *inode)
        /*
         * Allocate and use new inode
         */
-       ino = (struct inode *)malloc(sizeof(struct ubifs_inode));
+       ino = (struct inode *)malloc_cache_aligned(sizeof(struct ubifs_inode));
        memcpy(ino, inode, sizeof(struct ubifs_inode));
 
        /*
index 6dd617426ad35dfdb28da648db8361f6e00a7c02..4daa7fad53df51acffcc7d58199181412e05b6d6 100644 (file)
@@ -108,7 +108,7 @@ static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name,
        struct crypto_comp *ptr;
        int i = 0;
 
-       ptr = malloc(sizeof(struct crypto_comp));
+       ptr = malloc_cache_aligned(sizeof(struct crypto_comp));
        while (i < UBIFS_COMPR_TYPES_CNT) {
                comp = ubifs_compressors[i];
                if (!comp) {
@@ -723,7 +723,7 @@ static int do_readpage(struct ubifs_info *c, struct inode *inode,
                                 * destination area to a multiple of
                                 * UBIFS_BLOCK_SIZE.
                                 */
-                               buff = malloc(UBIFS_BLOCK_SIZE);
+                               buff = malloc_cache_aligned(UBIFS_BLOCK_SIZE);
                                if (!buff) {
                                        printf("%s: Error, malloc fails!\n",
                                               __func__);
index c48e5bc11bf5b7ffe1d6f4314a17aa431b247b9a..c12f402f773ff6d0a334413437ff9bf17e03f236 100644 (file)
@@ -1060,6 +1060,15 @@ int cpu_release(int nr, int argc, char * const argv[]);
 #define DEFINE_CACHE_ALIGN_BUFFER(type, name, size)                    \
        DEFINE_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
 
+#ifndef __ASSEMBLY__
+#include <malloc.h>
+
+static inline void *malloc_cache_aligned(size_t size)
+{
+       return memalign(ARCH_DMA_MINALIGN, ALIGN(size, ARCH_DMA_MINALIGN));
+}
+#endif
+
 /*
  * check_member() - Check the offset of a structure member
  *
index ff37d4f31be4ba479a0c6e0d1b2bdacd0f32db26..cd8e9fea43dd6eb80f9256604cdf77b90e6b6e32 100644 (file)
@@ -25,7 +25,7 @@ static void *zalloc(void *x, unsigned items, unsigned size)
        size *= items;
        size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
 
-       p = malloc (size);
+       p = malloc_cache_aligned(size);
 
        return (p);
 }
index 14f6eb1e07d9d65a20231119d693231d1ed49c1a..173a81d1ea4df76325f2f45cbe82aa8e3e10641c 100644 (file)
@@ -43,11 +43,13 @@ void z_error (m)
  */
 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
 
+#ifndef __UBOOT__
 #ifndef STDC
 extern voidp    malloc OF((uInt size));
 extern voidp    calloc OF((uInt items, uInt size));
 extern void     free   OF((voidpf ptr));
 #endif
+#endif
 
 voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)
 {