Skip to contentSkip to conversation

dmaengine: atcdmac300: Add Andes ATCDMAC300 DMA driver

PATCH Superseded CL Wang 3 participants 6 messages Sep 16 – Sep 22

Subsystems (2)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

CL Wang

author
#0 lore raw

v7 cover dmaengine: atcdmac300: Add Andes ATCDMAC300 DMA driver

This patch series adds support for the Andes ATCDMAC300 DMA controller, a memory-to-memory and peripheral DMA controller that provides scatter-gather, cyclic, and slave transfer capabilities.

The ATCDMAC300 IP is embedded in AndesCore-based platforms or SoCs such as AE350 and Qilai.

Changes in v7:
- Rebase onto the current dmaengine/next
- Fold in twelve correctness fixes found by review and confirmed on an FPGA; no interface or binding change
- Interrupt path:
- Acknowledge only the status bits that were actually read
- Key the acknowledge on channel ownership instead of on in-flight state the handler itself clears, which could leave a completion unacknowledged until the core disabled the line
- Use raw spinlocks for the state shared with the hard IRQ handler
- Termination and descriptor lifetime:
- Do not run the callback twice, or recycle a descriptor, when a transfer is terminated while its completion is in flight
- Initialise desc_node when a descriptor is allocated
- Wait for the channel to stop without holding the channel lock; the poll could spin 100 ms with interrupts disabled
- Suspend and resume:
- Move the PM callbacks to the late phase so clients terminate their transfers first, and name the channels that fail to idle
- Drain in-flight completions across suspend and resume
- Do not restart an idle cyclic channel on resume
- Probe:
- Register the DMA device only after the interrupt and cache coherency setup, closing a window in which a client could obtain a channel through dma_request_channel() on an unready controller
- Do not read-modify-write write-only registers
- Name the device in the probe-time reset error

Changes in v6:
- Rebase onto dmaengine/next; no functional changes from v5
- Fold the MAINTAINERS entry into the driver patch instead of carrying it as a separate patch (series is now 2 patches)

Changes in v5:
- Update copyright year to 2026
- Remove redundant headers (init.h, iopoll.h, mod_devicetable.h)
- Move atcdmac_init_iocp() before of_dma_controller_register() in probe
- Change builtin_platform_driver() to module_platform_driver()
- Implement .remove callback to support safe module unloading
- Update Kconfig entry from bool to tristate
- Add MODULE_AUTHOR, MODULE_DESCRIPTION, MODULE_LICENSE macros

Changes in v4:
- Use items list format with descriptions for reg property in DT binding as suggested by Conor Dooley
- Re-add Acked-by from Conor Dooley for DT binding patch

Changes in v3:
- Rename DT binding file from andestech,qilai-dma.yaml to andestech,ae350-dma.yaml
- Deprecate IP-core-based compatible usage and align with SoC/platform-based strings
- Dropped Acked-by from Conor Dooley due to the above binding change
- Remove "andestech,atcdmac300" from of_device_id table
- Replace deprecated tasklet with threaded IRQ using devm_request_threaded_irq() and IRQF_ONESHOT
- Update locking from spin_lock_bh() to spin_lock_irqsave()
- Use builtin_platform_driver() instead of module_platform_driver()
- Remove "select DMATEST" from Kconfig
- Add separate MAINTAINERS patch (patch 3/3)

Please kindly review.

CL Wang (2):
dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine
dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

 .../bindings/dma/andestech,ae350-dma.yaml     |   67 +
 MAINTAINERS                                   |    6 +
 drivers/dma/Kconfig                           |   11 +
 drivers/dma/Makefile                          |    1 +
 drivers/dma/atcdmac300.c                      | 1625 +++++++++++++++++
 drivers/dma/atcdmac300.h                      |  298 +++
 6 files changed, 2008 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
 create mode 100644 drivers/dma/atcdmac300.c
 create mode 100644 drivers/dma/atcdmac300.h
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v7 1/2 dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine

Document devicetree bindings for Andes ATCDMAC300 DMA engine

ATCDMAC300 is the IP name, which is embedded in AndesCore-based platforms or SoCs such as AE350 and Qilai.

---
Changes for v7:
- Rebase onto the current dmaengine/next; no changes from v6

Changes for v6:
- Rebase onto dmaengine/next; no changes from v5

Changes for v5:
- No changes from v4

Changes for v4:
- Use items list format with descriptions for reg property as suggested by Conor Dooley

Changes for v3:
- Rename DT binding file from andestech,qilai-dma.yaml to andestech,ae350-dma.yaml.
- Deprecate IP-core-based compatible usage and align with SoC/platform-based strings.
- Dropped Acked-by tag from Conor Dooley due to the above change.

---
 .../bindings/dma/andestech,ae350-dma.yaml     | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +67 -0
new file mode 100644
index 000000000000..f040a2bf7d4b
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/andestech,ae350-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Andes ATCDMAC300 DMA Controller
+
+maintainers:
+  - CL Wang <[email protected]>
+
+allOf:
+  - $ref: dma-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - andestech,qilai-dma
+          - const: andestech,ae350-dma
+      - const: andestech,ae350-dma
+
+  reg:
+    minItems: 1
+    items:
+      - description: DMA controller register range
+      - description: cache control in IOCP controller
+
+  reg-names:
+    minItems: 1
+    items:
+      - const: dma
+      - const: iocp
+
+  interrupts:
+    maxItems: 1
+
+  "#dma-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#dma-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        dma-controller@f0c00000 {
+            compatible = "andestech,ae350-dma";
+            reg = <0x0 0xf0c00000 0x0 0x1000>,
+                  <0x0 0xe8000000 0x0 0x10>;
+            reg-names = "dma", "iocp";
+            interrupts = <10 IRQ_TYPE_LEVEL_HIGH>;
+            #dma-cells = <1>;
+        };
+    };
+...
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v7 2/2 dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

In reply to CL Wang

This patch adds support for the Andes ATCDMAC300 DMA controller.

The ATCDMAC300 is a memory-to-memory and peripheral DMA controller that provides scatter-gather, cyclic, and slave transfer capabilities.

---
Changes for v7:
- Fold in twelve correctness fixes found by review and confirmed on an FPGA; no interface or binding change. Interrupt path:
- Acknowledge only the status bits that were actually read, and key the acknowledge on channel ownership rather than on in-flight state the handler itself clears. The old mask could drop a completion that arrived while it was being cleared, leaving the source asserted until the core disabled the line ("nobody cared").
- Use raw spinlocks for the state shared with the hard IRQ handler.
Termination and descriptor lifetime:
- Do not run the callback twice, or recycle a descriptor, when a transfer is terminated while its completion is in flight.
- Initialise desc_node when a descriptor is allocated.
- Wait for the channel to stop without holding the channel lock; the poll could spin 100 ms with interrupts disabled.
Suspend and resume:
- Move the PM callbacks to the late phase so clients terminate their transfers first, and name the channels that fail to idle.
- Drain in-flight completions across suspend and resume.
- Do not restart an idle cyclic channel on resume.
Probe:
- Register the DMA device only after the interrupt and cache coherency setup, closing a window in which a client could obtain a channel through dma_request_channel() on an unready controller.
- Do not read-modify-write write-only registers.
- Name the device in the probe-time reset error.

Changes for v6:
- Rebase onto dmaengine/next; no functional changes from v5
- Fold the MAINTAINERS entry into this patch instead of carrying it as a separate patch

Changes for v5:
- Update copyright year to 2026
- Remove redundant headers (init.h, iopoll.h, mod_devicetable.h)
- Move atcdmac_init_iocp() before of_dma_controller_register() in probe
- Change builtin_platform_driver() to module_platform_driver()
- Implement .remove callback to support safe module unloading
- Update Kconfig entry from bool to tristate
- Add MODULE_AUTHOR, MODULE_DESCRIPTION, MODULE_LICENSE macros

Changes for v4:
- No changes from v3

Changes for v3:
- Remove "andestech,atcdmac300" from of_device_id
- Replace deprecated tasklet with threaded IRQ using devm_request_threaded_irq() and IRQF_ONESHOT to handle bottom-half processing.
- Update locking mechanism from spin_lock_bh() to spin_lock_irqsave()
- Minor cleanups and correctness fixes
- Initialize descriptor pointers (first = NULL) explicitly
- Add missing headers (err.h, iopoll.h, log2.h, sprintf.h)
- Remove unused code paths related to tasklets
- Use builtin_platform_driver() instead of module_platform_driver()
- Remove "select DMATEST" from Kconfig

---
 MAINTAINERS              |    6 +
 drivers/dma/Kconfig      |   11 +
 drivers/dma/Makefile     |    1 +
 drivers/dma/atcdmac300.c | 1625 ++++++++++++++++++++++++++++++++++++++
 drivers/dma/atcdmac300.h |  298 +++++++
 5 files changed, 1941 insertions(+)
 create mode 100644 drivers/dma/atcdmac300.c
 create mode 100644 drivers/dma/atcdmac300.h
MAINTAINERS +6 -0
index c31b81eb42d7..2c48bb3053b3 100644
@@ -1974,6 +1974,12 @@ S:	Supported
 F:	drivers/clk/analogbits/*
 F:	include/linux/clk/analogbits*
 
+ANDES ATCDMAC300 DMA DRIVER
+M:	CL Wang <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
+F:	drivers/dma/atcdmac300*
+
 ANDES ATCSPI200 SPI DRIVER
 M:	CL Wang <[email protected]>
 S:	Supported
drivers/dma/Kconfig +11 -0
index ae6a682c9f76..dabd2c8cc94f 100644
@@ -100,6 +100,17 @@ config ARM_DMA350
 	help
 	  Enable support for the Arm DMA-350 controller.
 
+config ATCDMAC300
+	tristate "Andes ATCDMAC300 DMA support"
+	depends on ARCH_ANDES
+	depends on OF
+	select DMA_ENGINE
+	help
+	  Enable support for the Andes ATCDMAC300 DMA controller.
+	  Select Y or M if your platform includes an ATCDMAC300 device that
+	  requires DMA engine support. This driver supports DMA_SLAVE,
+	  DMA_MEMCPY, and DMA_CYCLIC transfer modes.
+
 config AT_HDMAC
 	tristate "Atmel AHB DMA support"
 	depends on ARCH_AT91 || COMPILE_TEST
drivers/dma/Makefile +1 -0
index 14aa086629d5..c8fffb31efc4 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_AMBA_PL08X) += amba-pl08x.o
 obj-$(CONFIG_AMCC_PPC440SPE_ADMA) += ppc4xx/
 obj-$(CONFIG_APPLE_ADMAC) += apple-admac.o
 obj-$(CONFIG_ARM_DMA350) += arm-dma350.o
+obj-$(CONFIG_ATCDMAC300) += atcdmac300.o
 obj-$(CONFIG_AT_HDMAC) += at_hdmac.o
 obj-$(CONFIG_AT_XDMAC) += at_xdmac.o
 obj-$(CONFIG_AXI_DMAC) += dma-axi-dmac.o
drivers/dma/atcdmac300.c new file +1625 -0

1,625 lines not on this page · raw message

drivers/dma/atcdmac300.h new file +298 -0

298 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v7 2/2] dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [High] dmaengine: atcdmac300: UAF on driver unbind due to devres lifecycle mismatch - [High] dmaengine…

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] dmaengine: atcdmac300: UAF on driver unbind due to devres lifecycle mismatch
- [High] dmaengine: atcdmac300: permanent controller halt if suspend times out
- [High] dmaengine: atcdmac300: NULL pointer dereference mixing cyclic and non-cyclic transfers
- [High] dmaengine: atcdmac300: cross-transfer corruption on simultaneous TC and ERR interrupts
- [Medium] dmaengine: atcdmac300: memory leak of unsubmitted descriptors
- [Medium] dmaengine: atcdmac300: silent truncation of DT req_num exceeding 15
- [Medium] dmaengine: atcdmac300: transfers queued during suspend are stranded on resume
- [Low] dmaengine: atcdmac300: missing endianness conversions for DMA descriptors --

commit 94fd62b6d9e6afc2cf50f8dff89eedcdc57f24c9
Author: CL Wang <[email protected]>
Subject: dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

This patch adds support for the Andes ATCDMAC300 DMA controller. It provides scatter-gather, cyclic, and slave transfer capabilities.

Quoted 4 lines
drivers/dma/atcdmac300.c new file +0 -0
index 0000000000000..e0a8a980e2fe8

[ ... ]

drivers/dma/atcdmac300.c static struct atcdmac_desc *atcdmac_alloc_desc(struct dma_chan *chan,

Quoted 8 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -82,9 +82,6 @@ static struct atcdmac_desc *atcdmac_alloc_desc(struct dma_chan *chan,
 		INIT_LIST_HEAD(&desc->desc_node);
 		INIT_LIST_HEAD(&desc->tx_list);
 		dma_async_tx_descriptor_init(&desc->txd, chan);
 		desc->txd.flags = DMA_CTRL_ACK;
 		desc->txd.tx_submit = atcdmac_tx_submit;
 		desc->txd.phys = phys;
 	}

[Severity: Medium]
The desc_free callback is omitted from the transaction descriptor here. If a client prepares a descriptor but aborts and frees it before submission, the DMA engine core won't be able to free it.

[ ... ]

Quoted 12 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -494,11 +494,11 @@ static irqreturn_t atcdmac_irq_thread(int irq, void *dev_id)
 	for (i = 0; i < dmac->num_ch; i++) {
 		dmac_chan = &dmac->chan[i];
 
 		if (test_and_clear_bit(ATCDMAC_STA_TC, &dmac_chan->status)) {
 			atcdmac_advance_work(dmac_chan);
 			handled = true;
 		}
 
 		if (test_and_clear_bit(ATCDMAC_STA_ERR, &dmac_chan->status)) {
 			atcdmac_handle_error(dmac_chan);
 			handled = true;
Quoted 1 line

}

[Severity: High]
The lack of mutual exclusivity allows both conditions to execute if both status bits are asserted simultaneously by the hardware. In this case, atcdmac_advance_work() would complete the current descriptor and start the next one, followed immediately by atcdmac_handle_error() wrongly aborting the newly started, innocent descriptor. Should these checks be mutually exclusive?

[ ... ]

drivers/dma/atcdmac300.c atcdmac_prep_dma_cyclic(struct dma_chan *chan, · line 917

Quoted 8 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -911,10 +911,8 @@ atcdmac_prep_dma_cyclic(struct dma_chan *chan,
 		if (!desc)
 			goto err_desc_get;
 		atcdmac_chain_desc(&first, &prev, desc, true);
 	}
 
 	first->txd.flags = flags;
 	dmac_chan->cyclic = true;

[Severity: High]
This modifies the channel-wide state during descriptor preparation. If a client prepares a cyclic transfer, does not submit it, and subsequently prepares and submits a non-cyclic transfer, this global flag remains set. When the non-cyclic transfer completes, could this cause atcdmac_advance_work() to treat it as cyclic and attempt to dereference dma_desc->at->next in atcdmac_start_next_trans(), leading to a kernel panic?

[ ... ]

drivers/dma/atcdmac300.c static void atcdmac_free_chan_resources(struct dma_chan *chan) · line 1151

Quoted 9 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1144,10 +1144,8 @@ static void atcdmac_free_chan_resources(struct dma_chan *chan)
 	spin_lock_irqsave(&dmac_chan->lock, flags);
 	list_for_each_entry_safe(desc,
 				 desc_next,
 				 &dmac_chan->free_list,
 				 desc_node) {
 		list_del(&desc->desc_node);
 		dma_pool_free(dmac->dma_desc_pool, desc, desc->txd.phys);
 	}

[Severity: Medium]
This loop only frees descriptors currently sitting in the free_list. Combined with the missing desc_free callback above, does this mean any prepared but unsubmitted descriptors are permanently leaked and never returned to the dma_desc_pool?

[ ... ]

drivers/dma/atcdmac300.c static struct dma_chan *atcdmac_dma_xlate_handler(struct of_phandle_args *dmac, · line 1194

Quoted 7 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1189,8 +1189,8 @@ static struct dma_chan *atcdmac_dma_xlate_handler(struct of_phandle_args *dmac,
 	if (!chan)
 		return NULL;
 
 	dmac_chan = atcdmac_chan_to_dmac_chan(chan);
 	dmac_chan->dev_chan = true;
 	dmac_chan->req_num = dmac->args[0] & 0xff;

[Severity: Medium]
The request number is extracted and masked to 8 bits. However, the hardware request selection registers (SRC_REQ_SEL_MASK, DST_REQ_SEL_MASK) are only 4 bits wide. Since FIELD_PREP silently truncates values, a device tree req_num of 16 will be programmed into hardware as 0 without warning. Should this value be explicitly validated against the 4-bit maximum?

[ ... ]

drivers/dma/atcdmac300.c static int atcdmac_init_ioremap_and_regmap(struct platform_device *pdev, · line 1310

Quoted 7 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1305,9 +1305,9 @@ static int atcdmac_init_ioremap_and_regmap(struct platform_device *pdev,
 	regmap_read(regmap, REG_CFG, &val);
 	num_ch = val & CH_NUM;
 	size = sizeof(*dmac) + num_ch * sizeof(struct atcdmac_chan);
 	dmac = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
 	if (!dmac)
 		return -ENOMEM;

[Severity: High]
The DMA controller structure is allocated using devres, tying its lifetime to the device binding rather than the dma_device refcount. If a client driver still holds a channel reference when the device is unbound, could this lead to a use-after-free when the client later releases the channel and atcdmac_free_chan_resources() accesses the freed dmac structure?

[ ... ]

drivers/dma/atcdmac300.c static int atcdmac_resume(struct device *dev) · line 1550

Quoted 9 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1543,9 +1543,8 @@ static int atcdmac_resume(struct device *dev)
 	list_for_each_entry_safe(chan,
 				 chan_next,
 				 &dmac->dma_device.channels,
 				 device_node) {
 		dmac_chan = atcdmac_chan_to_dmac_chan(chan);
 		spin_lock_irqsave(&dmac_chan->lock, flags);
 		if (!list_empty(&dmac_chan->active_list))
 			atcdmac_start_next_trans(dmac_chan);

[Severity: Medium]
This condition actively prevents queue_list items from being serviced if the active_list is empty during resume. Since transfers submitted during suspend are placed into queue_list (because stop_mask prevents them from starting), won't they remain stranded indefinitely unless issue_pending is also called here?

[ ... ]

drivers/dma/atcdmac300.c static int atcdmac_suspend(struct device *dev) · line 1575

Quoted 9 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1568,9 +1568,9 @@ static int atcdmac_suspend(struct device *dev)
 	synchronize_irq(dmac->irq);
 
 	ret = atcdmac_wait_chan_idle(dmac,
 				     chan_mask,
 				     ATCDMAC_CHAN_TIMEOUT_US * dmac->num_ch);
 
 	return ret;
 }

[Severity: High]
If atcdmac_wait_chan_idle() times out, the function returns the error code without reverting dmac->stop_mask back to 0. Since the PM core would abort the system suspend and resume normal operations, wouldn't this permanently prevent any new transfers from starting?

Quoted 4 lines
drivers/dma/atcdmac300.h new file +0 -0
index 0000000000000..3d2d07effc26d

[ ... ]

drivers/dma/atcdmac300.h enum dma_sta { · line 152

Quoted 6 lines
drivers/dma/atcdmac300.h new file +0 -0
@@ -148,10 +148,10 @@ enum dma_sta {
  * @ll_ptr_hi: Linked List Pointer Register (high 32-bit).
  */
 struct atcdmac_regs {
 	unsigned int ctrl;
 	unsigned int trans_size;

[Severity: Low]
The hardware descriptor layout uses native unsigned int instead of explicitly sized __le32 types. When these fields are populated in atcdmac_build_desc(), values are assigned directly without cpu_to_le32(). Does this lack of endianness conversion break portability if this driver is ever used on a big-endian system?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

Re: [PATCH v7 2/2] dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

Quoted 10 lines · On Wed, Sep 16, 2026 at 02:01:19PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] dmaengine: atcdmac300: UAF on driver unbind due to devres lifecycle mismatch
- [High] dmaengine: atcdmac300: permanent controller halt if suspend times out
- [High] dmaengine: atcdmac300: NULL pointer dereference mixing cyclic and non-cyclic transfers
- [High] dmaengine: atcdmac300: cross-transfer corruption on simultaneous TC and ERR interrupts
- [Medium] dmaengine: atcdmac300: memory leak of unsubmitted descriptors
- [Medium] dmaengine: atcdmac300: silent truncation of DT req_num exceeding 15
- [Medium] dmaengine: atcdmac300: transfers queued during suspend are stranded on resume
- [Low] dmaengine: atcdmac300: missing endianness conversions for DMA descriptors --

Please fix these problem or provide explain.

Frank

Quoted 175 lines

commit 94fd62b6d9e6afc2cf50f8dff89eedcdc57f24c9
Author: CL Wang <[email protected]>
Subject: dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

This patch adds support for the Andes ATCDMAC300 DMA controller. It provides scatter-gather, cyclic, and slave transfer capabilities.

Quoted 4 lines
drivers/dma/atcdmac300.c new file +0 -0
index 0000000000000..e0a8a980e2fe8

[ ... ]

drivers/dma/atcdmac300.c static struct atcdmac_desc *atcdmac_alloc_desc(struct dma_chan *chan,

Quoted 8 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -82,9 +82,6 @@ static struct atcdmac_desc *atcdmac_alloc_desc(struct dma_chan *chan,
 		INIT_LIST_HEAD(&desc->desc_node);
 		INIT_LIST_HEAD(&desc->tx_list);
 		dma_async_tx_descriptor_init(&desc->txd, chan);
 		desc->txd.flags = DMA_CTRL_ACK;
 		desc->txd.tx_submit = atcdmac_tx_submit;
 		desc->txd.phys = phys;
 	}

[Severity: Medium]
The desc_free callback is omitted from the transaction descriptor here. If a client prepares a descriptor but aborts and frees it before submission, the DMA engine core won't be able to free it.

[ ... ]

Quoted 12 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -494,11 +494,11 @@ static irqreturn_t atcdmac_irq_thread(int irq, void *dev_id)
 	for (i = 0; i < dmac->num_ch; i++) {
 		dmac_chan = &dmac->chan[i];
 
 		if (test_and_clear_bit(ATCDMAC_STA_TC, &dmac_chan->status)) {
 			atcdmac_advance_work(dmac_chan);
 			handled = true;
 		}
 
 		if (test_and_clear_bit(ATCDMAC_STA_ERR, &dmac_chan->status)) {
 			atcdmac_handle_error(dmac_chan);
 			handled = true;
Quoted 1 line

}

[Severity: High]
The lack of mutual exclusivity allows both conditions to execute if both status bits are asserted simultaneously by the hardware. In this case, atcdmac_advance_work() would complete the current descriptor and start the next one, followed immediately by atcdmac_handle_error() wrongly aborting the newly started, innocent descriptor. Should these checks be mutually exclusive?

[ ... ]

drivers/dma/atcdmac300.c atcdmac_prep_dma_cyclic(struct dma_chan *chan, · line 917

Quoted 8 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -911,10 +911,8 @@ atcdmac_prep_dma_cyclic(struct dma_chan *chan,
 		if (!desc)
 			goto err_desc_get;
 		atcdmac_chain_desc(&first, &prev, desc, true);
 	}
 
 	first->txd.flags = flags;
 	dmac_chan->cyclic = true;

[Severity: High]
This modifies the channel-wide state during descriptor preparation. If a client prepares a cyclic transfer, does not submit it, and subsequently prepares and submits a non-cyclic transfer, this global flag remains set. When the non-cyclic transfer completes, could this cause atcdmac_advance_work() to treat it as cyclic and attempt to dereference dma_desc->at->next in atcdmac_start_next_trans(), leading to a kernel panic?

[ ... ]

drivers/dma/atcdmac300.c static void atcdmac_free_chan_resources(struct dma_chan *chan) · line 1151

Quoted 9 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1144,10 +1144,8 @@ static void atcdmac_free_chan_resources(struct dma_chan *chan)
 	spin_lock_irqsave(&dmac_chan->lock, flags);
 	list_for_each_entry_safe(desc,
 				 desc_next,
 				 &dmac_chan->free_list,
 				 desc_node) {
 		list_del(&desc->desc_node);
 		dma_pool_free(dmac->dma_desc_pool, desc, desc->txd.phys);
 	}

[Severity: Medium]
This loop only frees descriptors currently sitting in the free_list. Combined with the missing desc_free callback above, does this mean any prepared but unsubmitted descriptors are permanently leaked and never returned to the dma_desc_pool?

[ ... ]

drivers/dma/atcdmac300.c static struct dma_chan *atcdmac_dma_xlate_handler(struct of_phandle_args *dmac, · line 1194

Quoted 7 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1189,8 +1189,8 @@ static struct dma_chan *atcdmac_dma_xlate_handler(struct of_phandle_args *dmac,
 	if (!chan)
 		return NULL;
 
 	dmac_chan = atcdmac_chan_to_dmac_chan(chan);
 	dmac_chan->dev_chan = true;
 	dmac_chan->req_num = dmac->args[0] & 0xff;

[Severity: Medium]
The request number is extracted and masked to 8 bits. However, the hardware request selection registers (SRC_REQ_SEL_MASK, DST_REQ_SEL_MASK) are only 4 bits wide. Since FIELD_PREP silently truncates values, a device tree req_num of 16 will be programmed into hardware as 0 without warning. Should this value be explicitly validated against the 4-bit maximum?

[ ... ]

drivers/dma/atcdmac300.c static int atcdmac_init_ioremap_and_regmap(struct platform_device *pdev, · line 1310

Quoted 7 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1305,9 +1305,9 @@ static int atcdmac_init_ioremap_and_regmap(struct platform_device *pdev,
 	regmap_read(regmap, REG_CFG, &val);
 	num_ch = val & CH_NUM;
 	size = sizeof(*dmac) + num_ch * sizeof(struct atcdmac_chan);
 	dmac = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
 	if (!dmac)
 		return -ENOMEM;

[Severity: High]
The DMA controller structure is allocated using devres, tying its lifetime to the device binding rather than the dma_device refcount. If a client driver still holds a channel reference when the device is unbound, could this lead to a use-after-free when the client later releases the channel and atcdmac_free_chan_resources() accesses the freed dmac structure?

[ ... ]

drivers/dma/atcdmac300.c static int atcdmac_resume(struct device *dev) · line 1550

Quoted 9 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1543,9 +1543,8 @@ static int atcdmac_resume(struct device *dev)
 	list_for_each_entry_safe(chan,
 				 chan_next,
 				 &dmac->dma_device.channels,
 				 device_node) {
 		dmac_chan = atcdmac_chan_to_dmac_chan(chan);
 		spin_lock_irqsave(&dmac_chan->lock, flags);
 		if (!list_empty(&dmac_chan->active_list))
 			atcdmac_start_next_trans(dmac_chan);

[Severity: Medium]
This condition actively prevents queue_list items from being serviced if the active_list is empty during resume. Since transfers submitted during suspend are placed into queue_list (because stop_mask prevents them from starting), won't they remain stranded indefinitely unless issue_pending is also called here?

[ ... ]

drivers/dma/atcdmac300.c static int atcdmac_suspend(struct device *dev) · line 1575

Quoted 9 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1568,9 +1568,9 @@ static int atcdmac_suspend(struct device *dev)
 	synchronize_irq(dmac->irq);
 
 	ret = atcdmac_wait_chan_idle(dmac,
 				     chan_mask,
 				     ATCDMAC_CHAN_TIMEOUT_US * dmac->num_ch);
 
 	return ret;
 }

[Severity: High]
If atcdmac_wait_chan_idle() times out, the function returns the error code without reverting dmac->stop_mask back to 0. Since the PM core would abort the system suspend and resume normal operations, wouldn't this permanently prevent any new transfers from starting?

Quoted 4 lines
drivers/dma/atcdmac300.h new file +0 -0
index 0000000000000..3d2d07effc26d

[ ... ]

drivers/dma/atcdmac300.h enum dma_sta { · line 152

Quoted 6 lines
drivers/dma/atcdmac300.h new file +0 -0
@@ -148,10 +148,10 @@ enum dma_sta {
  * @ll_ptr_hi: Linked List Pointer Register (high 32-bit).
  */
 struct atcdmac_regs {
 	unsigned int ctrl;
 	unsigned int trans_size;

[Severity: Low]
The hardware descriptor layout uses native unsigned int instead of explicitly sized __le32 types. When these fields are populated in atcdmac_build_desc(), values are assigned directly without cpu_to_le32(). Does this lack of endianness conversion break portability if this driver is ever used on a big-endian system?

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2

author
#5 lore raw

Re: [PATCH v7 2/2] dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

Hi Frank,

Thanks for looking at this, and thanks to the bot for a careful pass.

Five of the eight are fixed for v8. Three do not apply to this driver and I have tried to say why rather than just assert it.

Quoted 2 lines

- [High] dmaengine: atcdmac300: UAF on driver unbind due to devres lifecycle mismatch

Fixed.

Quoted 2 lines

- [High] dmaengine: atcdmac300: permanent controller halt if suspend times out

Fixed.

Quoted 2 lines

- [High] dmaengine: atcdmac300: NULL pointer dereference mixing cyclic and non-cyclic transfers

Fixed.

Quoted 2 lines

- [High] dmaengine: atcdmac300: cross-transfer corruption on simultaneous TC and ERR interrupts

I do not think this one can happen. The data sheet defines the terminal count bit of the interrupt status register at offset 0x30 as

The terminal count status is set when a channel transfer finishes without the abort or error event.

so for one transfer the two are mutually exclusive. Chained transfers do not widen the window either: the same document says that with IntTCMask=0 an interrupt is "only be generated when data transfer of the last linked descriptor is complete", so a chain raises one terminal count rather than one per link.

Quoted 2 lines

- [Medium] dmaengine: atcdmac300: memory leak of unsubmitted descriptors

The desc_free half of this does not apply. The callback is reachable only through dmaengine_desc_free(),

	static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
	{
		/* this is supported for reusable desc, so check that */
		if (!dmaengine_desc_test_reuse(desc))
			return -EPERM;

		return desc->desc_free(desc);
	}:w

and a client can only set DMA_CTRL_REUSE through dmaengine_desc_set_reuse(), which fails unless the channel advertises descriptor_reuse. This driver does not set dma_device.descriptor_reuse, so the callback can never be invoked and adding it would be dead code. Documentation/driver-api/ dmaengine/provider.rst puts it the same way: dmaengine_desc_free() "can succeed only when DMA_CTRL_REUSE is already set".

I looked at closing that properly and do not think the API allows it. There is no unprepare, so a client that abandons a descriptor makes no call the driver could hook. Tracking every descriptor handed out would move the recovery point from teardown to terminate or free_chan_resources but not remove it, at the cost of a list operation on prep and submit. Implementing DMA_CTRL_REUSE does not help either: dmaengine_desc_free() requires the client to have set that flag first, and a client that intends to abandon a descriptor is not one that asked to reuse it.

No in-tree client of this driver prepares a transfer it does not submit, so I have left it. Say if you would rather have the tracking anyway.

Quoted 2 lines

- [Medium] dmaengine: atcdmac300: silent truncation of DT req_num exceeding 15

Fixed.

Quoted 2 lines

- [Medium] dmaengine: atcdmac300: transfers queued during suspend are stranded on resume

Fixed.

Quoted 2 lines

- [Low] dmaengine: atcdmac300: missing endianness conversions for DMA descriptors

This one cannot bite. The driver depends on ARCH_ANDES and Linux has no big-endian RISC-V: arch/riscv/Kconfig offers neither CPU_BIG_ENDIAN nor CPU_LITTLE_ENDIAN, so the conversions would be no-ops wherever this can be built.

If here are no further comments, I will submit v8 with the five fixes.

Thanks,
CL Wang

Quoted 193 lines · Frank Li

[EXTERNAL MAIL]

Quoted 10 lines · On Wed, Sep 16, 2026 at 02:01:19PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] dmaengine: atcdmac300: UAF on driver unbind due to devres lifecycle mismatch
- [High] dmaengine: atcdmac300: permanent controller halt if suspend times out
- [High] dmaengine: atcdmac300: NULL pointer dereference mixing cyclic and non-cyclic transfers
- [High] dmaengine: atcdmac300: cross-transfer corruption on simultaneous TC and ERR interrupts
- [Medium] dmaengine: atcdmac300: memory leak of unsubmitted descriptors
- [Medium] dmaengine: atcdmac300: silent truncation of DT req_num exceeding 15
- [Medium] dmaengine: atcdmac300: transfers queued during suspend are stranded on resume
- [Low] dmaengine: atcdmac300: missing endianness conversions for DMA descriptors --

Please fix these problem or provide explain.

Frank

Quoted 175 lines

commit 94fd62b6d9e6afc2cf50f8dff89eedcdc57f24c9
Author: CL Wang <[email protected]>
Subject: dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

This patch adds support for the Andes ATCDMAC300 DMA controller. It provides scatter-gather, cyclic, and slave transfer capabilities.

Quoted 4 lines
drivers/dma/atcdmac300.c new file +0 -0
index 0000000000000..e0a8a980e2fe8

[ ... ]

drivers/dma/atcdmac300.c static struct atcdmac_desc *atcdmac_alloc_desc(struct dma_chan *chan,

Quoted 8 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -82,9 +82,6 @@ static struct atcdmac_desc *atcdmac_alloc_desc(struct dma_chan *chan,
            INIT_LIST_HEAD(&desc->desc_node);
            INIT_LIST_HEAD(&desc->tx_list);
            dma_async_tx_descriptor_init(&desc->txd, chan);
            desc->txd.flags = DMA_CTRL_ACK;
            desc->txd.tx_submit = atcdmac_tx_submit;
            desc->txd.phys = phys;
    }

[Severity: Medium]
The desc_free callback is omitted from the transaction descriptor here. If a client prepares a descriptor but aborts and frees it before submission, the DMA engine core won't be able to free it.

[ ... ]

Quoted 12 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -494,11 +494,11 @@ static irqreturn_t atcdmac_irq_thread(int irq, void *dev_id)
    for (i = 0; i < dmac->num_ch; i++) {
            dmac_chan = &dmac->chan[i];
 
            if (test_and_clear_bit(ATCDMAC_STA_TC, &dmac_chan->status)) {
                    atcdmac_advance_work(dmac_chan);
                    handled = true;
            }
 
            if (test_and_clear_bit(ATCDMAC_STA_ERR, &dmac_chan->status)) {
                    atcdmac_handle_error(dmac_chan);
                    handled = true;
Quoted 1 line
            }

[Severity: High]
The lack of mutual exclusivity allows both conditions to execute if both status bits are asserted simultaneously by the hardware. In this case, atcdmac_advance_work() would complete the current descriptor and start the next one, followed immediately by atcdmac_handle_error() wrongly aborting the newly started, innocent descriptor. Should these checks be mutually exclusive?

[ ... ]

drivers/dma/atcdmac300.c atcdmac_prep_dma_cyclic(struct dma_chan *chan, · line 917

Quoted 8 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -911,10 +911,8 @@ atcdmac_prep_dma_cyclic(struct dma_chan *chan,
            if (!desc)
                    goto err_desc_get;
            atcdmac_chain_desc(&first, &prev, desc, true);
    }
 
    first->txd.flags = flags;
    dmac_chan->cyclic = true;

[Severity: High]
This modifies the channel-wide state during descriptor preparation. If a client prepares a cyclic transfer, does not submit it, and subsequently prepares and submits a non-cyclic transfer, this global flag remains set. When the non-cyclic transfer completes, could this cause atcdmac_advance_work() to treat it as cyclic and attempt to dereference dma_desc->at->next in atcdmac_start_next_trans(), leading to a kernel panic?

[ ... ]

drivers/dma/atcdmac300.c static void atcdmac_free_chan_resources(struct dma_chan *chan) · line 1151

Quoted 9 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1144,10 +1144,8 @@ static void atcdmac_free_chan_resources(struct dma_chan *chan)
    spin_lock_irqsave(&dmac_chan->lock, flags);
    list_for_each_entry_safe(desc,
                             desc_next,
                             &dmac_chan->free_list,
                             desc_node) {
            list_del(&desc->desc_node);
            dma_pool_free(dmac->dma_desc_pool, desc, desc->txd.phys);
    }

[Severity: Medium]
This loop only frees descriptors currently sitting in the free_list. Combined with the missing desc_free callback above, does this mean any prepared but unsubmitted descriptors are permanently leaked and never returned to the dma_desc_pool?

[ ... ]

drivers/dma/atcdmac300.c static struct dma_chan *atcdmac_dma_xlate_handler(struct of_phandle_args *dmac, · line 1194

Quoted 7 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1189,8 +1189,8 @@ static struct dma_chan *atcdmac_dma_xlate_handler(struct of_phandle_args *dmac,
    if (!chan)
            return NULL;
 
    dmac_chan = atcdmac_chan_to_dmac_chan(chan);
    dmac_chan->dev_chan = true;
    dmac_chan->req_num = dmac->args[0] & 0xff;

[Severity: Medium]
The request number is extracted and masked to 8 bits. However, the hardware request selection registers (SRC_REQ_SEL_MASK, DST_REQ_SEL_MASK) are only 4 bits wide. Since FIELD_PREP silently truncates values, a device tree req_num of 16 will be programmed into hardware as 0 without warning. Should this value be explicitly validated against the 4-bit maximum?

[ ... ]

drivers/dma/atcdmac300.c static int atcdmac_init_ioremap_and_regmap(struct platform_device *pdev, · line 1310

Quoted 7 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1305,9 +1305,9 @@ static int atcdmac_init_ioremap_and_regmap(struct platform_device *pdev,
    regmap_read(regmap, REG_CFG, &val);
    num_ch = val & CH_NUM;
    size = sizeof(*dmac) + num_ch * sizeof(struct atcdmac_chan);
    dmac = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
    if (!dmac)
            return -ENOMEM;

[Severity: High]
The DMA controller structure is allocated using devres, tying its lifetime to the device binding rather than the dma_device refcount. If a client driver still holds a channel reference when the device is unbound, could this lead to a use-after-free when the client later releases the channel and atcdmac_free_chan_resources() accesses the freed dmac structure?

[ ... ]

drivers/dma/atcdmac300.c static int atcdmac_resume(struct device *dev) · line 1550

Quoted 9 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1543,9 +1543,8 @@ static int atcdmac_resume(struct device *dev)
    list_for_each_entry_safe(chan,
                             chan_next,
                             &dmac->dma_device.channels,
                             device_node) {
            dmac_chan = atcdmac_chan_to_dmac_chan(chan);
            spin_lock_irqsave(&dmac_chan->lock, flags);
            if (!list_empty(&dmac_chan->active_list))
                    atcdmac_start_next_trans(dmac_chan);

[Severity: Medium]
This condition actively prevents queue_list items from being serviced if the active_list is empty during resume. Since transfers submitted during suspend are placed into queue_list (because stop_mask prevents them from starting), won't they remain stranded indefinitely unless issue_pending is also called here?

[ ... ]

drivers/dma/atcdmac300.c static int atcdmac_suspend(struct device *dev) · line 1575

Quoted 9 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1568,9 +1568,9 @@ static int atcdmac_suspend(struct device *dev)
    synchronize_irq(dmac->irq);
 
    ret = atcdmac_wait_chan_idle(dmac,
                                 chan_mask,
                                 ATCDMAC_CHAN_TIMEOUT_US * dmac->num_ch);
 
    return ret;
 }

[Severity: High]
If atcdmac_wait_chan_idle() times out, the function returns the error code without reverting dmac->stop_mask back to 0. Since the PM core would abort the system suspend and resume normal operations, wouldn't this permanently prevent any new transfers from starting?

Quoted 4 lines
drivers/dma/atcdmac300.h new file +0 -0
index 0000000000000..3d2d07effc26d

[ ... ]

drivers/dma/atcdmac300.h enum dma_sta { · line 152

Quoted 6 lines
drivers/dma/atcdmac300.h new file +0 -0
@@ -148,10 +148,10 @@ enum dma_sta {
  * @ll_ptr_hi: Linked List Pointer Register (high 32-bit).
  */
 struct atcdmac_regs {
    unsigned int ctrl;
    unsigned int trans_size;

[Severity: Low]
The hardware descriptor layout uses native unsigned int instead of explicitly sized __le32 types. When these fields are populated in atcdmac_build_desc(), values are assigned directly without cpu_to_le32(). Does this lack of endianness conversion break portability if this driver is ever used on a big-endian system?

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2