diff options
author | Arnd Bergmann <arnd@arndb.de> | 2016-10-17 18:05:31 -0400 |
---|---|---|
committer | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-10-28 04:21:23 -0400 |
commit | 8ff0513bdcdd71e84aa561cce216675d43fb41b8 (patch) | |
tree | 5a78c67a0d77953159dbad5e57f52f95a4e9b001 | |
parent | 73f907fd5fa56b0066d199bdd7126bbd04f6cd7b (diff) |
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>
-rw-r--r-- | drivers/mtd/nand/mtk_ecc.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/drivers/mtd/nand/mtk_ecc.c b/drivers/mtd/nand/mtk_ecc.c index d54f666417e1..dbf256217b3e 100644 --- a/drivers/mtd/nand/mtk_ecc.c +++ b/drivers/mtd/nand/mtk_ecc.c | |||
@@ -86,6 +86,8 @@ struct mtk_ecc { | |||
86 | struct completion done; | 86 | struct completion done; |
87 | struct mutex lock; | 87 | struct mutex lock; |
88 | u32 sectors; | 88 | u32 sectors; |
89 | |||
90 | u8 eccdata[112]; | ||
89 | }; | 91 | }; |
90 | 92 | ||
91 | static inline void mtk_ecc_wait_idle(struct mtk_ecc *ecc, | 93 | 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, | |||
366 | u8 *data, u32 bytes) | 368 | u8 *data, u32 bytes) |
367 | { | 369 | { |
368 | dma_addr_t addr; | 370 | dma_addr_t addr; |
369 | u8 *p; | 371 | u32 len; |
370 | u32 len, i, val; | 372 | int ret; |
371 | int ret = 0; | ||
372 | 373 | ||
373 | addr = dma_map_single(ecc->dev, data, bytes, DMA_TO_DEVICE); | 374 | addr = dma_map_single(ecc->dev, data, bytes, DMA_TO_DEVICE); |
374 | ret = dma_mapping_error(ecc->dev, addr); | 375 | ret = dma_mapping_error(ecc->dev, addr); |
@@ -393,14 +394,12 @@ int mtk_ecc_encode(struct mtk_ecc *ecc, struct mtk_ecc_config *config, | |||
393 | 394 | ||
394 | /* Program ECC bytes to OOB: per sector oob = FDM + ECC + SPARE */ | 395 | /* Program ECC bytes to OOB: per sector oob = FDM + ECC + SPARE */ |
395 | len = (config->strength * ECC_PARITY_BITS + 7) >> 3; | 396 | len = (config->strength * ECC_PARITY_BITS + 7) >> 3; |
396 | p = data + bytes; | ||
397 | 397 | ||
398 | /* write the parity bytes generated by the ECC back to the OOB region */ | 398 | /* write the parity bytes generated by the ECC back to temp buffer */ |
399 | for (i = 0; i < len; i++) { | 399 | __ioread32_copy(ecc->eccdata, ecc->regs + ECC_ENCPAR(0), round_up(len, 4)); |
400 | if ((i % 4) == 0) | 400 | |
401 | val = readl(ecc->regs + ECC_ENCPAR(i / 4)); | 401 | /* copy into possibly unaligned OOB region with actual length */ |
402 | p[i] = (val >> ((i % 4) * 8)) & 0xff; | 402 | memcpy(data + bytes, ecc->eccdata, len); |
403 | } | ||
404 | timeout: | 403 | timeout: |
405 | 404 | ||
406 | dma_unmap_single(ecc->dev, addr, bytes, DMA_TO_DEVICE); | 405 | dma_unmap_single(ecc->dev, addr, bytes, DMA_TO_DEVICE); |