Skip to content

Commit 8ff0513

Browse files
arndbBoris Brezillon
authored andcommitted
mtd: mtk: avoid warning in mtk_ecc_encode
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 <arnd@arndb.de> Tested-by: RogerCC Lin <rogercc.lin@mediatek.com> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
1 parent 73f907f commit 8ff0513

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

drivers/mtd/nand/mtk_ecc.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ struct mtk_ecc {
8686
struct completion done;
8787
struct mutex lock;
8888
u32 sectors;
89+
90+
u8 eccdata[112];
8991
};
9092

9193
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,
366368
u8 *data, u32 bytes)
367369
{
368370
dma_addr_t addr;
369-
u8 *p;
370-
u32 len, i, val;
371-
int ret = 0;
371+
u32 len;
372+
int ret;
372373

373374
addr = dma_map_single(ecc->dev, data, bytes, DMA_TO_DEVICE);
374375
ret = dma_mapping_error(ecc->dev, addr);
@@ -393,14 +394,12 @@ int mtk_ecc_encode(struct mtk_ecc *ecc, struct mtk_ecc_config *config,
393394

394395
/* Program ECC bytes to OOB: per sector oob = FDM + ECC + SPARE */
395396
len = (config->strength * ECC_PARITY_BITS + 7) >> 3;
396-
p = data + bytes;
397397

398-
/* write the parity bytes generated by the ECC back to the OOB region */
399-
for (i = 0; i < len; i++) {
400-
if ((i % 4) == 0)
401-
val = readl(ecc->regs + ECC_ENCPAR(i / 4));
402-
p[i] = (val >> ((i % 4) * 8)) & 0xff;
403-
}
398+
/* write the parity bytes generated by the ECC back to temp buffer */
399+
__ioread32_copy(ecc->eccdata, ecc->regs + ECC_ENCPAR(0), round_up(len, 4));
400+
401+
/* copy into possibly unaligned OOB region with actual length */
402+
memcpy(data + bytes, ecc->eccdata, len);
404403
timeout:
405404

406405
dma_unmap_single(ecc->dev, addr, bytes, DMA_TO_DEVICE);

0 commit comments

Comments
 (0)