From patchwork Fri Sep 30 16:33:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9358633 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 7FEA76075E for ; Fri, 30 Sep 2016 16:35:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C6F01FFB9 for ; Fri, 30 Sep 2016 16:35:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B5782A0AF; Fri, 30 Sep 2016 16:35:25 +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 7D1DE1FFB9 for ; Fri, 30 Sep 2016 16:35:21 +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 1bq0mO-0000Kq-CX; Fri, 30 Sep 2016 16:35:20 +0000 Received: from mout.kundenserver.de ([212.227.126.135]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bq0m2-0007wn-G5; Fri, 30 Sep 2016 16:35:00 +0000 Received: from wuerfel.lan. ([78.43.20.153]) by mrelayeu.kundenserver.de (mreue005) with ESMTPA (Nemesis) id 0LzWOk-1auDUD13ze-014jxt; Fri, 30 Sep 2016 18:34:31 +0200 From: Arnd Bergmann To: Boris Brezillon , David Woodhouse , Brian Norris Subject: [PATCH] mtd: mtk: avoid warning in mtk_ecc_encode Date: Fri, 30 Sep 2016 18:33:02 +0200 Message-Id: <20160930163429.380785-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:/yOpLk+0G12yTpm2us2OcE/EJUXmeZGurVSm0GR2JsvjB4jvLnD O6QjRuNZez6PjBfy0GCnvzRXylOZSRGiuiubhueNzFFVB9pD7Ji38vrPZ9MSWNq0nxIjul2 HSGGZtQS+R3UMuIlKgvmXcj86uRBF/xM4nFyQcWyIbbsP8E2YUYUTNTJhgJzTGJNkjSdqF6 0C+YIk8Wl/JHXziCt7P9g== X-UI-Out-Filterresults: notjunk:1; V01:K0:Knin6uPFf2g=:Y1zX6YrJdnNlNFYbQjJuXE v6fiyC1Pwvczha3Ev4AXXOTrodGwB4zsTe4MHA9DMp6Z+cZgMOTack7R+zYP/5rwGRXVriX0d ZHPld7jYmiJjFEnN/V6Ku13iyv66Ui+0xTSj4fK2dUa9BhiUqzR+Ck72ywBwBSn73WOqzoUzV qRxsWPvcJBnZtRWELrxFUUJR0/SE/SNnhFE2/7L1tb2yDigEKjJ3xqonEk6q/oYS4F+nL3htF BFKhFOYw6YZvHcTXHtNQb1Ih5X2GeQx2/CUAdd/orMXkdj8qxfKW0dvnCxAl0N0JpQFX6Xmiz e19IkFrb9+eTbrcV86Shygbn8z1l0CIZCvrIu5iXCOtb+9EKduk2ZxHY+6YtswlPk6yCiuqik nrhc8P8/gN24uk9wXHvdiRrwtvc5YnuG1Y9Gv6cIOIJbSyUoZSOTlBL+1aLiFeU+Kn1RYztWA R8cYhMSeOH15Ec2+8Vild2mMpgIL06gEOTZ0MpAj+J88NXzva6tE0UCveqpNfTLZ1nSBZxpSV KkXGDfEhTbVuEuKWqi7xeSvHiUid+/ZIP3M4H4Hcx1LTQP1tORUvFZRyibOXhB9VNmKIOnJoE vqCTf+KYJqX40LP9+GZd/NVF7f6Aq9+JwtjfPNTeTM4yKKGTY+FEMlsNTVlFr6X7MX8BTjoyK Y/zyhSMeH+yZCgSREWIK8Ok2dZD3/OsgBVTy7iReazbIAhP76nD2W7hTTdpAa7a5RDfA= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160930_093459_011083_0A18048F X-CRM114-Status: GOOD ( 16.15 ) 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-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , linux-mtd@lists.infradead.org, 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 --- drivers/mtd/nand/mtk_ecc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/nand/mtk_ecc.c b/drivers/mtd/nand/mtk_ecc.c index d54f666417e1..237c83124a7d 100644 --- a/drivers/mtd/nand/mtk_ecc.c +++ b/drivers/mtd/nand/mtk_ecc.c @@ -366,9 +366,9 @@ 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; + u8 eccdata[112]; + int ret; addr = dma_map_single(ecc->dev, data, bytes, DMA_TO_DEVICE); ret = dma_mapping_error(ecc->dev, addr); @@ -393,14 +393,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(eccdata, ecc->regs + ECC_ENCPAR(0), round_up(len, 4)); + + /* copy into possibly unaligned OOB region with actual length */ + memcpy(data + bytes, eccdata, len); timeout: dma_unmap_single(ecc->dev, addr, bytes, DMA_TO_DEVICE);