Skip to content

Commit 3b36f86

Browse files
Thomas-fouriermiquelraynal
authored andcommitted
mtd: rawnand: rockchip: Add missing check after DMA map
The DMA map functions can fail and should be tested for errors. Fixes: 058e0e8 ("mtd: rawnand: rockchip: NFC driver for RK3308, RK2928 and others") Signed-off-by: Thomas Fourier <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 1251005 commit 3b36f86

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/mtd/nand/raw/rockchip-nand-controller.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,16 @@ static int rk_nfc_write_page_hwecc(struct nand_chip *chip, const u8 *buf,
656656

657657
dma_data = dma_map_single(nfc->dev, (void *)nfc->page_buf,
658658
mtd->writesize, DMA_TO_DEVICE);
659+
if (dma_mapping_error(nfc->dev, dma_data))
660+
return -ENOMEM;
661+
659662
dma_oob = dma_map_single(nfc->dev, nfc->oob_buf,
660663
ecc->steps * oob_step,
661664
DMA_TO_DEVICE);
665+
if (dma_mapping_error(nfc->dev, dma_oob)) {
666+
dma_unmap_single(nfc->dev, dma_data, mtd->writesize, DMA_TO_DEVICE);
667+
return -ENOMEM;
668+
}
662669

663670
reinit_completion(&nfc->done);
664671
writel(INT_DMA, nfc->regs + nfc->cfg->int_en_off);
@@ -772,9 +779,17 @@ static int rk_nfc_read_page_hwecc(struct nand_chip *chip, u8 *buf, int oob_on,
772779
dma_data = dma_map_single(nfc->dev, nfc->page_buf,
773780
mtd->writesize,
774781
DMA_FROM_DEVICE);
782+
if (dma_mapping_error(nfc->dev, dma_data))
783+
return -ENOMEM;
784+
775785
dma_oob = dma_map_single(nfc->dev, nfc->oob_buf,
776786
ecc->steps * oob_step,
777787
DMA_FROM_DEVICE);
788+
if (dma_mapping_error(nfc->dev, dma_oob)) {
789+
dma_unmap_single(nfc->dev, dma_data, mtd->writesize,
790+
DMA_FROM_DEVICE);
791+
return -ENOMEM;
792+
}
778793

779794
/*
780795
* The first blocks (4, 8 or 16 depending on the device)

0 commit comments

Comments
 (0)