DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nuno Sá" <nuno.sa@analog.com>
Cc: vkoul@kernel.org, Frank.Li@kernel.org, dmaengine@vger.kernel.org
Subject: Re: [PATCH 4/9] dmaengine: qcom: gpi: Use bus width capability helpers
Date: Thu, 30 Jul 2026 14:43:32 +0000	[thread overview]
Message-ID: <20260730144332.9656F1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260730-dmaengine-support-wider-dma-masks-v1-4-3732f1f9d9ca@analog.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing dma_async_device_unregister() in the probe error path and lack of a .remove callback leads to Use-After-Free.
- [High] Error cleanup paths in gpi_ch_init() reset the wrong channel.
- [Medium] Out-of-bounds bitwise shift when processing the `dma-channels` property.
- [Medium] DMA coherent memory allocated for channel rings is leaked if channel initialization fails.
- [Medium] Potential integer overflow in devm_kzalloc when allocating gpiis array.
--

--- Patch [4]: [PATCH 4/9] dmaengine: qcom: gpi: Use bus width capability helpers ---
commit 359e67a23cc93b4c7bc48fb679da1cdd39760273
Author: Nuno Sá <nuno.sa@analog.com>

dmaengine: qcom: gpi: Use bus width capability helpers

Advertise the single supported source and destination bus width through
the new dma_set_src_bus_width() and dma_set_dst_bus_width() helpers
instead of assigning the legacy u32 fields directly.

> diff --git a/drivers/dma/qcom/gpi.c b/drivers/dma/qcom/gpi.c
> index a5055a6273af6..fd45cadce91fd 100644
> --- a/drivers/dma/qcom/gpi.c
> +++ b/drivers/dma/qcom/gpi.c

[ ... ]

> @@ -1994,11 +1994,11 @@ static int gpi_ch_init(struct gchan *gchan)
>  
>  error_start_chan:
>  	for (i = i - 1; i >= 0; i--) {
>  		gpi_stop_chan(&gpii->gchan[i]);
>  		gpi_send_cmd(gpii, gchan, GPI_CH_CMD_RESET);
                                   ^^^^^

[Severity: High]
This is a pre-existing issue, but does this pass the correct channel to
gpi_send_cmd()? It looks like the error cleanup paths are passing the
function parameter gchan instead of the iterated channel &gpii->gchan[i],
which might leave previously started channels running while resetting the
wrong one.

>  	}
>  	i = 2;
>  error_alloc_chan:
>  	for (i = i - 1; i >= 0; i--)
>  		gpi_reset_chan(gchan, GPI_CH_CMD_DE_ALLOC);
                               ^^^^^

[Severity: High]
This is a pre-existing issue, but does this also reset the wrong channel
for the same reason?

[ ... ]

> @@ -2058,11 +2058,11 @@ static int gpi_alloc_chan_resources(struct dma_chan *chan)
>  
>  	/* allocate memory for transfer ring */
>  	ret = gpi_alloc_ring(&gchan->ch_ring, CHAN_TRES,
>  			     sizeof(struct gpi_tre), gpii);
>  	if (ret)
>  		goto xfer_alloc_err;
>  
>  	ret = gpi_ch_init(gchan);
>  
>  	mutex_unlock(&gpii->ctrl_lock);
>  
>  	return ret;

[Severity: Medium]
This is a pre-existing issue, but does this error path leak the DMA coherent
memory allocated for gchan->ch_ring if gpi_ch_init() fails? It looks like it
exits without calling gpi_free_ring().

[ ... ]

> @@ -2218,17 +2218,17 @@ static int gpi_probe(struct platform_device *pdev)
>  
>  	gpi_dev->gpiis = devm_kzalloc(gpi_dev->dev, sizeof(*gpi_dev->gpiis) *
>  				      gpi_dev->max_gpii, GFP_KERNEL);

[Severity: Medium]
This is a pre-existing issue, but can this unchecked multiplication overflow
before being passed to devm_kzalloc()?

If a malformed Device Tree provides an excessively large max_gpii value, this
could result in a significantly smaller allocation and out-of-bounds writes in
the initialization loop. Should this use devm_kcalloc() instead?

>  	if (!gpi_dev->gpiis)
>  		return -ENOMEM;
>  
>  	/* setup all the supported gpii */
>  	INIT_LIST_HEAD(&gpi_dev->dma_device.channels);
>  	for (i = 0; i < gpi_dev->max_gpii; i++) {
>  		struct gpii *gpii = &gpi_dev->gpiis[i];
>  		int chan;
>  
>  		if (!((1 << i) & gpi_dev->gpii_mask))
>  			continue;

[Severity: Medium]
This is a pre-existing issue, but can this bitwise shift (1 << i) overflow a
32-bit integer if i >= 32? Since max_gpii is parsed from the Device Tree
without bounds checking, it seems this could invoke undefined behavior.

[ ... ]

>  	/* configure dmaengine apis */
>  	gpi_dev->dma_device.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
>  	gpi_dev->dma_device.residue_granularity = DMA_RESIDUE_GRANULARITY_DESCRIPTOR;
> -	gpi_dev->dma_device.src_addr_widths = DMA_SLAVE_BUSWIDTH_8_BYTES;
> -	gpi_dev->dma_device.dst_addr_widths = DMA_SLAVE_BUSWIDTH_8_BYTES;
> +	ret = dma_set_src_bus_width(&gpi_dev->dma_device,
> +				    DMA_SLAVE_BUSWIDTH_8_BYTES);
> +	if (ret)
> +		return ret;
> +
> +	ret = dma_set_dst_bus_width(&gpi_dev->dma_device,
> +				    DMA_SLAVE_BUSWIDTH_8_BYTES);
> +	if (ret)
> +		return ret;
>  	gpi_dev->dma_device.device_alloc_chan_resources = gpi_alloc_chan_resources;

[ ... ]

>  	ret = of_dma_controller_register(gpi_dev->dev->of_node,
>  					 gpi_of_dma_xlate, gpi_dev);
>  	if (ret) {
>  		dev_err(gpi_dev->dev, "of_dma_controller_reg failed ret:%d", ret);
>  		return ret;
>  	}
>  
>  	return ret;
>  }

[Severity: High]
This isn't a bug introduced by this patch, but does the probe function return
here without unregistering the previously registered DMA device?

If of_dma_controller_register() fails, dma_async_device_unregister() is
missing, which could leave dangling pointers in the DMA and OF framework lists,
causing a Use-After-Free.

[ ... ]

> @@ -2319,9 +2319,9 @@ static const struct of_device_id gpi_of_match[] = {
>  MODULE_DEVICE_TABLE(of, gpi_of_match);
>  
>  static struct platform_driver gpi_driver = {
>  	.probe = gpi_probe,
>  	.driver = {
>  		.name = KBUILD_MODNAME,
>  		.of_match_table = gpi_of_match,
>  	},
>  };

[Severity: High]
This is a pre-existing issue, but does this platform driver lack a .remove
callback?

Without it, sysfs unbind invokes devres cleanup while leaving the DMA device
registered, which can lead to a Use-After-Free.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730-dmaengine-support-wider-dma-masks-v1-0-3732f1f9d9ca@analog.com?part=4

  reply	other threads:[~2026-07-30 14:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 14:23 [PATCH 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá via B4 Relay
2026-07-30 14:23 ` [PATCH 1/9] " Nuno Sá via B4 Relay
2026-07-30 14:38   ` sashiko-bot
2026-07-30 19:16   ` Frank Li
2026-07-30 14:23 ` [PATCH 2/9] dmaengine: dma-axi-dmac: Use bus width capability helpers Nuno Sá via B4 Relay
2026-07-30 14:39   ` sashiko-bot
2026-07-30 19:23   ` Frank Li
2026-07-30 14:23 ` [PATCH 3/9] dmaengine: dw-axi-dmac: " Nuno Sá via B4 Relay
2026-07-30 14:36   ` sashiko-bot
2026-07-30 19:24   ` Frank Li
2026-07-30 14:23 ` [PATCH 4/9] dmaengine: qcom: gpi: " Nuno Sá via B4 Relay
2026-07-30 14:43   ` sashiko-bot [this message]
2026-07-30 19:25   ` Frank Li
2026-07-30 14:23 ` [PATCH 5/9] dmaengine: stm32-dma3: " Nuno Sá via B4 Relay
2026-07-30 14:35   ` sashiko-bot
2026-07-30 19:26   ` Frank Li
2026-07-30 14:23 ` [PATCH 6/9] iio: buffer-dmaengine: Use dma_slave_caps bus width accessors Nuno Sá via B4 Relay
2026-07-30 19:27   ` Frank Li
2026-07-30 14:23 ` [PATCH 7/9] ALSA: pcm_dmaengine: Use dma_slave_caps bus width helpers Nuno Sá via B4 Relay
2026-07-30 19:30   ` Frank Li
2026-07-30 14:23 ` [PATCH 8/9] spi: dw: " Nuno Sá via B4 Relay
2026-07-30 14:43   ` sashiko-bot
2026-07-30 19:31   ` Frank Li
2026-07-30 14:23 ` [PATCH 9/9] dmaengine: Drop legacy bus width fields from dma_slave_caps Nuno Sá via B4 Relay
2026-07-30 19:05 ` [PATCH 0/9] dmaengine: Support bus widths of 32 bytes and above Frank Li

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=20260730144332.9656F1F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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