From patchwork Mon Oct 17 22:05:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9380703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E333D600CA for ; Mon, 17 Oct 2016 22:07:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD94C28A86 for ; Mon, 17 Oct 2016 22:07:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1C2928C56; Mon, 17 Oct 2016 22:07:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 35EF828A86 for ; Mon, 17 Oct 2016 22:07:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwG3p-0007dq-Ba; Mon, 17 Oct 2016 22:07:09 +0000 Received: from mout.kundenserver.de ([212.227.126.187]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwG3i-0007X7-TT; Mon, 17 Oct 2016 22:07:03 +0000 Received: from wuerfel.lan. ([78.43.20.153]) by mrelayeu.kundenserver.de (mreue003) with ESMTPA (Nemesis) id 0La0Mr-1cfFN43zJt-00lmaT; Tue, 18 Oct 2016 00:06:32 +0200 From: Arnd Bergmann To: Boris Brezillon Subject: [PATCH 02/28] [v2] mtd: mtk: avoid warning in mtk_ecc_encode Date: Tue, 18 Oct 2016 00:05:31 +0200 Message-Id: <20161017220557.1688282-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20161017220342.1627073-1-arnd@arndb.de> References: <20161017220342.1627073-1-arnd@arndb.de> X-Provags-ID: V03:K0:i2YLrPLJHAF9xQ7UpSIk5QW14dMXCPX4XENib7C85fwlxzrRbK3 KMYbn21itDYgW1mgdbNUNKyC5HZZHnVsKQxrjYSZRFwNEanTFEadudQ+eHrqrpBTGnV9+QZ XxU6SMxgivffGEsOUIb4t/6MbJT9XNouE6EZ77E6qy0dEm18coXXfD/7iTckkHQ2n+PGfn/ ASi6ahKbbYDHPpNDAXlJg== X-UI-Out-Filterresults: notjunk:1; V01:K0:ueToa7PIf2E=:NFVEPyrfGopR3nNyPX6wig 9egVKkziPqjIqTkv3Hj0RM96htSxBuAvvRBTqxWQuuZsjW8GAjpaQQMQMKMIc/+IRBj3vjQDs pAdUY32Zdeo2CIynGnookebm87PZHKIqoMtw8jX2pulB//fyYnTcuOT0715KjLaZfv3NLm9RZ nrQjkNuijsjVAUSjvXeKGbTu4M0ddwa2Ea8bte0ancOpHJ4BwdCOWA0slueuZNz5NRlC9BqAc h3GOly2QaXZeGJM7SMCU6hLVPeYLOunCVeYi9yE99gs+4A+XpxADnSJQpeBHObm0NZreXrXc7 ErOBZAQLmhrCKz44hcbpZpav22tDtjV5Bhy/7oZyszUOTe+h6vXFS3IcFUtXlPtuGSYPues4n 5dLcXT0yCuLA7O1NGhvgN0/xcCswseQgBALmx2NBGwiW7l/nSAVh2Y2IKO0++cRZuPYnV3gMG /zPu/ZQqBxxSTlbF96L3qhqykHEjY8Al5scyvY3q1FwSFTP82vpB/Q3aUUJywEGNiDoYoeCnA OWFWLcxMyx1/sqBmCPjvR5/yvwPviGQEvyMw+7OMeVEhVoDmNEICEBpOvN8MNRUe6ZZ/cXejo SoNhqLBjI3tcdEDp/oHN6khohZuFLQIIzscP/zbzpJZAQp2UD7Piuu+WZX3s+yhTBOPFfsdh6 w1YOblaA+S9PPKXg6fPCdxlGtzz0XJ6YrLqvX656ORYazECBVAqEsGqAyhav5AAdfaow= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161017_150703_348391_DA77B538 X-CRM114-Status: GOOD ( 17.61 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Richard Weinberger , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Torvalds , linux-mtd@lists.infradead.org, Matthias Brugger , Jorge Ramirez-Ortiz , Brian Norris , David Woodhouse , RogerCC Lin , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When building with -Wmaybe-uninitialized, gcc produces a silly false positive warning for the mtk_ecc_encode function: drivers/mtd/nand/mtk_ecc.c: In function 'mtk_ecc_encode': drivers/mtd/nand/mtk_ecc.c:402:15: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized] The function for some reason contains a double byte swap on big-endian builds to get the OOB data into the correct order again, and is written in a slightly confusing way. Using a simple memcpy32_fromio() to read the data simplifies it a lot so it becomes more readable and produces no warning. However, the output might not have 32-bit alignment, so we have to use another memcpy to avoid taking alignment faults or writing beyond the end of the array. Signed-off-by: Arnd Bergmann Tested-by: RogerCC Lin Acked-by: Boris Brezillon --- v2: move temporary buffer into struct mtk_ecc instead of having it on the stack, as suggested by Boris Brezillon --- drivers/mtd/nand/mtk_ecc.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/nand/mtk_ecc.c b/drivers/mtd/nand/mtk_ecc.c index d54f666..dbf2562 100644 --- a/drivers/mtd/nand/mtk_ecc.c +++ b/drivers/mtd/nand/mtk_ecc.c @@ -86,6 +86,8 @@ struct mtk_ecc { struct completion done; struct mutex lock; u32 sectors; + + u8 eccdata[112]; }; static inline void mtk_ecc_wait_idle(struct mtk_ecc *ecc, @@ -366,9 +368,8 @@ int mtk_ecc_encode(struct mtk_ecc *ecc, struct mtk_ecc_config *config, u8 *data, u32 bytes) { dma_addr_t addr; - u8 *p; - u32 len, i, val; - int ret = 0; + u32 len; + int ret; addr = dma_map_single(ecc->dev, data, bytes, DMA_TO_DEVICE); ret = dma_mapping_error(ecc->dev, addr); @@ -393,14 +394,12 @@ int mtk_ecc_encode(struct mtk_ecc *ecc, struct mtk_ecc_config *config, /* Program ECC bytes to OOB: per sector oob = FDM + ECC + SPARE */ len = (config->strength * ECC_PARITY_BITS + 7) >> 3; - p = data + bytes; - /* write the parity bytes generated by the ECC back to the OOB region */ - for (i = 0; i < len; i++) { - if ((i % 4) == 0) - val = readl(ecc->regs + ECC_ENCPAR(i / 4)); - p[i] = (val >> ((i % 4) * 8)) & 0xff; - } + /* write the parity bytes generated by the ECC back to temp buffer */ + __ioread32_copy(ecc->eccdata, ecc->regs + ECC_ENCPAR(0), round_up(len, 4)); + + /* copy into possibly unaligned OOB region with actual length */ + memcpy(data + bytes, ecc->eccdata, len); timeout: dma_unmap_single(ecc->dev, addr, bytes, DMA_TO_DEVICE);