Commit 5c56bf21 authored by Niravkumar L Rabara's avatar Niravkumar L Rabara Committed by Miquel Raynal
Browse files

mtd: rawnand: cadence: fix DMA device NULL pointer dereference



The DMA device pointer `dma_dev` was being dereferenced before ensuring
that `cdns_ctrl->dmac` is properly initialized.

Move the assignment of `dma_dev` after successfully acquiring the DMA
channel to ensure the pointer is valid before use.

Fixes: d76d22b5 ("mtd: rawnand: cadence: use dma_map_resource for sdma address")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarNiravkumar L Rabara <niravkumarlaxmidas.rabara@altera.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
parent 96313508
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2871,7 +2871,7 @@ cadence_nand_irq_cleanup(int irqnum, struct cdns_nand_ctrl *cdns_ctrl)
static int cadence_nand_init(struct cdns_nand_ctrl *cdns_ctrl)
{
	dma_cap_mask_t mask;
	struct dma_device *dma_dev = cdns_ctrl->dmac->device;
	struct dma_device *dma_dev;
	int ret;

	cdns_ctrl->cdma_desc = dma_alloc_coherent(cdns_ctrl->dev,
@@ -2915,6 +2915,7 @@ static int cadence_nand_init(struct cdns_nand_ctrl *cdns_ctrl)
		}
	}

	dma_dev = cdns_ctrl->dmac->device;
	cdns_ctrl->io.iova_dma = dma_map_resource(dma_dev->dev, cdns_ctrl->io.dma,
						  cdns_ctrl->io.size,
						  DMA_BIDIRECTIONAL, 0);