From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Niravkumar L Rabara <niravkumarlaxmidas.rabara@altera.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Miquel Raynal <miquel.raynal@bootlin.com>,
kernel test robot <lkp@intel.com>,
Dan Carpenter <error27@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v2 1/3] mtd: rawnand: cadence: Fix DMA device dereference when DMA is disabled
Date: Tue, 24 Nov 2026 10:24:22 +0100 [thread overview]
Message-ID: <20261124-perso-upstreaming-rawnand-fixes-v2-1-69db17ad07bd@bootlin.com> (raw)
In-Reply-To: <20261124-perso-upstreaming-rawnand-fixes-v2-0-69db17ad07bd@bootlin.com>
Move the DMA resource mapping into the has_dma branch and only unmap the
resource when a DMA channel was actually acquired.
Fixes: 5c56bf214af8 ("mtd: rawnand: cadence: fix DMA device NULL pointer dereference")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/all/202603252339.fQzI6oc8-lkp@intel.com/
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/all/202609010758.3N8tYZdG-lkp@intel.com/
Cc: stable@vger.kernel.org
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/mtd/nand/raw/cadence-nand-controller.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c
index e19ceb2d5dfc..42cc62b36457 100644
--- a/drivers/mtd/nand/raw/cadence-nand-controller.c
+++ b/drivers/mtd/nand/raw/cadence-nand-controller.c
@@ -3168,17 +3168,17 @@ static int cadence_nand_init(struct cdns_nand_ctrl *cdns_ctrl)
"%d: Failed to get a DMA channel\n", ret);
goto disable_irq;
}
- }
- 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);
+ 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);
- ret = dma_mapping_error(dma_dev->dev, cdns_ctrl->io.iova_dma);
- if (ret) {
- dev_err(cdns_ctrl->dev, "Failed to map I/O resource to DMA\n");
- goto dma_release_chnl;
+ ret = dma_mapping_error(dma_dev->dev, cdns_ctrl->io.iova_dma);
+ if (ret) {
+ dev_err(cdns_ctrl->dev, "Failed to map I/O resource to DMA\n");
+ goto dma_release_chnl;
+ }
}
nand_controller_init(&cdns_ctrl->controller);
@@ -3204,8 +3204,9 @@ static int cadence_nand_init(struct cdns_nand_ctrl *cdns_ctrl)
return 0;
unmap_dma_resource:
- dma_unmap_resource(dma_dev->dev, cdns_ctrl->io.iova_dma,
- cdns_ctrl->io.size, DMA_BIDIRECTIONAL, 0);
+ if (cdns_ctrl->dmac)
+ dma_unmap_resource(dma_dev->dev, cdns_ctrl->io.iova_dma,
+ cdns_ctrl->io.size, DMA_BIDIRECTIONAL, 0);
dma_release_chnl:
if (cdns_ctrl->dmac)
--
2.56.0
next prev parent reply other threads:[~2026-11-24 9:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 9:24 [PATCH v2 0/3] mtd: rawnand: cadence: Fix incorrect variable dereference Miquel Raynal
2026-11-24 9:24 ` Miquel Raynal [this message]
2026-11-24 9:24 ` [PATCH v2 2/3] mtd: rawnand: cadence: Resize the bounce buffer before the BBT scan Miquel Raynal
2026-11-24 9:24 ` [PATCH v2 3/3] mtd: rawnand: cadence: Switch to dmaengine_get_dma_device() Miquel Raynal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124-perso-upstreaming-rawnand-fixes-v2-1-69db17ad07bd@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=error27@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=lkp@intel.com \
--cc=niravkumarlaxmidas.rabara@altera.com \
--cc=richard@nod.at \
--cc=stable@vger.kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®