From patchwork Mon Aug 3 21:15:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Ziswiler X-Patchwork-Id: 503291 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 032811402A3 for ; Tue, 4 Aug 2015 07:16:47 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A3C44A7551; Mon, 3 Aug 2015 23:16:41 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Yan1FN1eBH1W; Mon, 3 Aug 2015 23:16:41 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 40DE9A7530; Mon, 3 Aug 2015 23:16:41 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 35E3DA7509 for ; Mon, 3 Aug 2015 23:16:38 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vEgTe7BzwayL for ; Mon, 3 Aug 2015 23:16:38 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mout.perfora.net (mout.perfora.net [74.208.4.194]) by theia.denx.de (Postfix) with ESMTPS id D6D06A7546 for ; Mon, 3 Aug 2015 23:16:33 +0200 (CEST) Received: from localhost.net ([62.167.132.2]) by mrelay.perfora.net (mreueus002) with ESMTPSA (Nemesis) id 0Lyk9B-1YpSna3YAR-0166K2; Mon, 03 Aug 2015 23:16:30 +0200 From: Marcel Ziswiler To: u-boot@lists.denx.de Date: Mon, 3 Aug 2015 23:15:49 +0200 Message-Id: <1745a3a98dda2ba4d0daec6eca0b9830addb3c0d.1438636040.git.marcel.ziswiler@toradex.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: References: X-Provags-ID: V03:K0:Xm8+Qd8yT/cDeg+MEnb5gP4oMQeeMsM6XWkonu6y+kx0wOf45j5 pmZU+ZDyWKzHzDL88FlpCil2dav4B7t+UZxreoqBvEKcalTe+k+Ju7917E0ENpiUIPVujy9 fD3Qv2gVdwSNOQwlLN1E176P9Zio9h+0F8AO1DUsr51jgVGU5PlLKMc7/pwlhf0dyhdMjCB WK5vHJCac4JZ94xvft4Yg== X-UI-Out-Filterresults: notjunk:1; V01:K0:Fx77E5gBTJc=:4feCKkswsuN8zOU3EllXur tf6rvnTVTmCtW7cww8TVLK23gKIRMIIYrDCBCYKf/HOdokvY+CxMHCmWhmIwHN9Fy+yalH7Ik RriP7I3bDFUDJvXF9pBjDRflxUYG7RFKS4P3CcKFnYCWZb5zFuyBjN3AR1tjULlNiZA5WoCfW 9cawsntrIpxwL88Cd+PvqNpQAeBJrQychrs7Ql/EMmm/u8jSoXpa2xd6B3PoQc4l+O68zRfHs CM/xNlWcn85+o/KVGdVuFGSokjKcF1WaNTDRMXgvnT6DNKNjcQx6XJegeoo1j2rvzMsqnnihj L9gV/qvnv2KiNa5e3S/Lisc5z5KJavPAYRQeXtB1jv8DqYrznGi3leqt1NrsmVGZzA7rejmKt 78Nfqdu0cG3JQ2946HBhjQ0Td+xY5YgcdAa3K/+RoFeAcoSTvrL0J+ZsZkF/tD4iPfI4MUyY1 kh7/5hFhzzWAAkQ+I4lj5CpugCO7HdGEOV964wjezpWew5Yyg/M6Cjb1lJH08DUuGO7B4uXwL Cr8SDzMuS/ACTDyvLPqSWQulTUT21a+L2wJhpTl81vk31uIOGoyvCJI/t0Umu4qZn8wVz68XV FAP/7clgy1p+UCg58umw6zRk+uOcV9s11hz74qwhyQydPaX57cWIEfUjb26vTtAA0FZUNUI+a TpTj1fjJFImJnYRlyCOK9Kp9O Cc: Marek Vasut , Tom Rini , Stefan Agner , Joe Hershberger , Marcel Ziswiler , Max Krummenacher , Scott Wood Subject: [U-Boot] [PATCH v3 7/8] mtd/nand/ubi: assortment of alignment fixes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Marcel Ziswiler 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 Reviewed-by: Simon Glass --- Changes in v3: introduce malloc_cache_aligned() as suggested by Scott Changes in v2: run it through checkpatch.pl and fix long lines common/cmd_ubi.c | 2 +- drivers/mtd/nand/nand_util.c | 2 +- fs/ubifs/super.c | 5 +++-- fs/ubifs/ubifs.c | 4 ++-- include/malloc.h | 8 ++++++++ lib/gzip.c | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c index cbc10c5..10eea65 100644 --- a/common/cmd_ubi.c +++ b/common/cmd_ubi.c @@ -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; diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c index ee2c24d..21b4a61 100644 --- a/drivers/mtd/nand/nand_util.c +++ b/drivers/mtd/nand/nand_util.c @@ -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; diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 10f8fff..0bf52db 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c @@ -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)); /* diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index 6dd6174..4daa7fa 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -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__); diff --git a/include/malloc.h b/include/malloc.h index f4da9e6..5933a94 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -955,6 +955,14 @@ extern ulong mem_malloc_brk; void mem_malloc_init(ulong start, ulong size); +#include +#include + +static inline void *malloc_cache_aligned(size_t size) +{ + return memalign(ARCH_DMA_MINALIGN, ALIGN(size, ARCH_DMA_MINALIGN)); +} + #ifdef __cplusplus }; /* end of extern "C" */ #endif diff --git a/lib/gzip.c b/lib/gzip.c index ff37d4f..cd8e9fe 100644 --- a/lib/gzip.c +++ b/lib/gzip.c @@ -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); }