Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Miquel Raynal" <miquel.raynal@bootlin.com>,
	"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
Subject: Re: [PATCH 2/2] mtd: rawnand: cadence: Switch to dmaengine_get_dma_device()
Date: Thu, 19 Nov 2026 22:37:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-224135@kernel.org> (raw)
In-Reply-To: <20261119-perso-upstreaming-rawnand-fixes-v1-2-0c95641b550c@bootlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: rawnand: cadence: DMA device mismatch in
  cadence_nand_slave_dma_transfer()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] mtd: rawnand: cadence: heap buffer overflow in
  cadence_nand_attach_chip() [1]
--

commit c9efdaa390c8c64b9c5264e642be970afe9a5044
Author: Miquel Raynal <miquel.raynal@bootlin.com>

mtd: rawnand: cadence: Switch to dmaengine_get_dma_device()

This commit replaces direct accesses to cdns_ctrl->dmac->device->dev in
cadence_nand_init() with dmaengine_get_dma_device().

> diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c
> index 42cc62b36457a..2ab59ec6e732e 100644
> --- a/drivers/mtd/nand/raw/cadence-nand-controller.c
> +++ b/drivers/mtd/nand/raw/cadence-nand-controller.c
> @@ -3126,7 +3126,6 @@ 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;
>  	int ret;
>  
>  	cdns_ctrl->cdma_desc = dma_alloc_coherent(cdns_ctrl->dev,

[Severity: High]
This problem wasn't introduced by this patch, but can [1] overflow
cdns_ctrl->buf during cadence_nand_chips_init()?

cadence_nand_init() initially allocates cdns_ctrl->buf at 16 KiB and only
reallocates it to cdns_ctrl->buf_size after cadence_nand_chips_init()
returns.  When a NAND chip's writesize + oobsize exceeds 16 KiB,
cadence_nand_attach_chip() updates cdns_ctrl->buf_size without resizing
cdns_ctrl->buf, and nand_scan_tail() -> nand_create_bbt() then performs
page and OOB transfers up to writesize + oobsize against the 16 KiB heap
buffer before cadence_nand_chips_init() finishes.

> @@ -3162,6 +3161,8 @@ static int cadence_nand_init(struct cdns_nand_ctrl *cdns_ctrl)
>  	dma_cap_set(DMA_MEMCPY, mask);
>  
>  	if (cdns_ctrl->caps1->has_dma) {
> +		struct device *dma_dev;
> +
>  		cdns_ctrl->dmac = dma_request_chan_by_mask(&mask);
>  		if (IS_ERR(cdns_ctrl->dmac)) {
>  			ret = dev_err_probe(cdns_ctrl->dev, PTR_ERR(cdns_ctrl->dmac),
> @@ -3169,12 +3170,12 @@ static int cadence_nand_init(struct cdns_nand_ctrl *cdns_ctrl)
>  			goto disable_irq;
>  		}
>  
> -		dma_dev = cdns_ctrl->dmac->device;
> -		cdns_ctrl->io.iova_dma = dma_map_resource(dma_dev->dev, cdns_ctrl->io.dma,
> +		dma_dev = dmaengine_get_dma_device(cdns_ctrl->dmac);
> +		cdns_ctrl->io.iova_dma = dma_map_resource(dma_dev, cdns_ctrl->io.dma,
>  							  cdns_ctrl->io.size,
>  							  DMA_BIDIRECTIONAL, 0);
>  
> -		ret = dma_mapping_error(dma_dev->dev, cdns_ctrl->io.iova_dma);
> +		ret = dma_mapping_error(dma_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;

[Severity: Medium]
Should cadence_nand_slave_dma_transfer() also use
dmaengine_get_dma_device() instead of chan->device->dev when mapping and
unmapping buf_dma?

drivers/mtd/nand/raw/cadence-nand-controller.c:cadence_nand_slave_dma_transfer() {
	...
	chan = cdns_ctrl->dmac;
	dma_dev = chan->device;

	buf_dma = dma_map_single(dma_dev->dev, buf, len, dir);
	...
}

cadence_nand_slave_dma_transfer() passes both cdns_ctrl->io.iova_dma and
buf_dma to dmaengine_prep_dma_memcpy() on the same channel.  On DMA
engines with per-channel DMA devices (chan_dma_dev),
dmaengine_get_dma_device() returns &chan->chan_dev->device rather than
chan->device->dev, so the two endpoints of the transfer would be mapped
against different struct devices.

[1] https://sashiko.dev/#/bug/linux-ee4810cc-1bf6-40ac-bdf0-e7cb10ace410

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-perso-upstreaming-rawnand-fixes-v1-0-0c95641b550c@bootlin.com?part=2

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2026-11-19 22:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 22:27 [PATCH 0/2] mtd: rawnand: cadence: Fix incorrect variable dereference Miquel Raynal
2026-11-19 22:27 ` [PATCH 1/2] mtd: rawnand: cadence: Fix DMA device dereference when DMA is disabled Miquel Raynal
2026-11-19 22:27 ` [PATCH 2/2] mtd: rawnand: cadence: Switch to dmaengine_get_dma_device() Miquel Raynal
2026-11-19 22:37   ` sashiko-bot [this message]

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=sashiko-outbox-224135@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=niravkumarlaxmidas.rabara@altera.com \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --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