Skip to contentSkip to conversation

dmaengine: atcdmac300: Add Andes ATCDMAC300 DMA driver

PATCH Superseded CL Wang 3 participants 7 messages May 27

Subsystems (2)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

CL Wang

author
#0 lore raw

v3 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 v3:
- Rename DT binding file from andestech,qilai-dma.yaml to andestech,ae350-dma.yaml
- Deprecate IP-core-based compatible and align with SoC/platform-based compatible 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 (3):
dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine
dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller
MAINTAINERS: Add entry for Andes ATCDMAC300

 .../bindings/dma/andestech,ae350-dma.yaml     |   68 +
 MAINTAINERS                                   |    6 +
 drivers/dma/Kconfig                           |   11 +
 drivers/dma/Makefile                          |    1 +
 drivers/dma/atcdmac300.c                      | 1505 +++++++++++++++++
 drivers/dma/atcdmac300.h                      |  296 ++++
 6 files changed, 1887 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 v3 1/3 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 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
- Dropped Acked-by tag from Conor Dooley due to the above change.

---
 .../bindings/dma/andestech,ae350-dma.yaml     | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +68 -0
new file mode 100644
index 000000000000..0f5ffdf1d160
@@ -0,0 +1,68 @@
+# 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
+    maxItems: 2
+    description:
+      First entry is the DMA controller register range (required).
+      Second entry is the cache control in IOCP controller (optional).
+
+  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
#2 lore raw

Re: [PATCH v3 1/3] dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Incorrect use of 'additionalProperties: false' when referencing a common schema. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Incorrect use of 'additionalProperties: false' when referencing a common schema. --

commit f1fe6e40b9cc08af2c1dbda4fec526d830ad7eb3
Author: CL Wang <[email protected]>

dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine

This commit documents the devicetree bindings for the Andes ATCDMAC300 DMA engine, which is embedded in platforms like AE350 and Qilai.

Quoted 5 lines
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +0 -0
new file mode 100644
index 0000000000000..0f5ffdf1d1609

[ ... ]

Quoted 3 lines
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +3 -0
+allOf:
+  - $ref: dma-controller.yaml#
+

[ ... ]

Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml line 49

Quoted 7 lines
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +7 -0
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#dma-cells"
+
+additionalProperties: false

[Severity: Low]
Should this be unevaluatedProperties: false instead?

Since this binding references the common dma-controller.yaml schema via an allOf block, using additionalProperties: false will cause dt_binding_check to reject standard DMA properties (like dma-channels or dma-requests) because they aren't explicitly defined in this file.

Using unevaluatedProperties: false allows properties defined in referenced schemas to be properly evaluated and permitted.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Acked-by on v3 1/3
#3 lore raw

Re: [PATCH v3 1/3] dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine

In reply to CL Wang
Quoted 44 lines · CL Wang

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 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
- Dropped Acked-by tag from Conor Dooley due to the above change.

---
 .../bindings/dma/andestech,ae350-dma.yaml     | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +19 -0
new file mode 100644
index 000000000000..0f5ffdf1d160
@@ -0,0 +1,68 @@
+# 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:

Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +10 -0
+              - andestech,qilai-dma
+          - const: andestech,ae350-dma
+      - const: andestech,ae350-dma
+
+  reg:
+    minItems: 1
+    maxItems: 2
+    description:
+      First entry is the DMA controller register range (required).
+      Second entry is the cache control in IOCP controller (optional).

This can be an items list FYI. Syntax is
reg:
minItems: 1
items:
- description: foo
- description: bar

Fix that and you can re-add my ack

pw-bot: changes-requested

author
#4 lore raw

PATCH v3 2/3 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 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

---
 drivers/dma/Kconfig      |   11 +
 drivers/dma/Makefile     |    1 +
 drivers/dma/atcdmac300.c | 1505 ++++++++++++++++++++++++++++++++++++++
 drivers/dma/atcdmac300.h |  296 ++++++++
 4 files changed, 1813 insertions(+)
 create mode 100644 drivers/dma/atcdmac300.c
 create mode 100644 drivers/dma/atcdmac300.h
drivers/dma/Kconfig +11 -0
index ae6a682c9f76..f7f6c5347a25 100644
@@ -100,6 +100,17 @@ config ARM_DMA350
 	help
 	  Enable support for the Arm DMA-350 controller.
 
+config ATCDMAC300
+	bool "Andes DMA support"
+	depends on ARCH_ANDES
+	depends on OF
+	select DMA_ENGINE
+	help
+	  Enable support for the Andes ATCDMAC300 DMA controller.
+	  Select Y 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 +1505 -0

1,505 lines not on this page · raw message

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

296 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

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

Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider: - [Critical] Uninitialized `list_head` in dynamically allocated descriptors causes a NULL pointer…

Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider:
- [Critical] Uninitialized list_head in dynamically allocated descriptors causes a NULL pointer dereference in error paths.
- [Critical] Reused DMA descriptors do not have their linked list pointers cleared, potentially causing wild DMA accesses.
- [High] The driver registers the DMA device with the dmaengine and OF frameworks before completing hardware and IRQ initialization.
- [High] The interrupt handler masks the hardware interrupt status with used_chan before clearing, causing unexpected interrupts to remain permanently asserted.
- [High] atcdmac_terminate_all() fails to clear pending hardware interrupts, allowing stale interrupts to erroneously corrupt newly submitted transfers.
- [High] The driver omits a remove function, causing a severe use-after-free if the device is unbound via sysfs.
- [High] A race condition in atcdmac_advance_work() causes a use-after-free when invoking callbacks for cyclic transfers.
- [High] Spinning with interrupts disabled for up to 100ms during atcdmac_terminate_all() can cause severe system lockups.
- [High] Acquiring a spinlock_t in the primary hardware interrupt handler violates PREEMPT_RT locking rules.
- [High] Cyclic transfers are implemented using software polling and restarts instead of hardware linked lists, introducing unacceptable latency.
- [High] If the wait timeout expires during suspend, the DMA controller is left permanently disabled because dmac->stop_mask is never restored.
- [Medium] Descriptors are leaked during channel teardown if they are not in the free list.
--

commit e6e8d9a6da52e397472687ec989dd87d328e0650
Author: CL Wang <[email protected]>

dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

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

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

[ ... ]

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
@@ -76,6 +76,21 @@ static struct atcdmac_desc *atcdmac_alloc_desc(struct dma_chan *chan,
 	struct atcdmac_desc *desc;
 	dma_addr_t phys;
 
 	desc = dma_pool_zalloc(dmac->dma_desc_pool, gfp_flags, &phys);
 	if (desc) {
 		INIT_LIST_HEAD(&desc->tx_list);
 		dma_async_tx_descriptor_init(&desc->txd, chan);

[Severity: Critical]
Does this leave the desc_node list uninitialized? If an error occurs during transfer preparation, the cleanup routines might access uninitialized pointers and cause a kernel panic. Should INIT_LIST_HEAD(&desc->desc_node) be added here?

Quoted 7 lines
drivers/dma/atcdmac300.c new file +0 -0
 		desc->txd.flags = DMA_CTRL_ACK;
 		desc->txd.tx_submit = atcdmac_tx_submit;
 		desc->txd.phys = phys;
 	}
 
 	return desc;
 }

[ ... ]

Quoted 4 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -215,6 +215,22 @@ static void atcdmac_chain_desc(struct atcdmac_desc **first,
 			       struct atcdmac_desc *desc,
 			       bool cyclic)
 {

drivers/dma/atcdmac300.c static void atcdmac_chain_desc(struct atcdmac_desc **first,

Quoted 10 lines
drivers/dma/atcdmac300.c new file +0 -0
 	if (!(*first)) {
 		*first = desc;
 		desc->at = &desc->tx_list;
 	} else {
 		if (!cyclic) {
 			(*prev)->regs.ll_ptr_lo =
 				lower_32_bits(desc->txd.phys);
 			(*prev)->regs.ll_ptr_hi =
 				upper_32_bits(desc->txd.phys);
 		}

[Severity: High]
Is hardware linked list chaining skipped for cyclic transfers here? By leaving the linked list pointers zeroed during cyclic transfers, the hardware stops at the end of each period. Does this require the CPU interrupt handler to manually restart the channel, potentially introducing audio dropouts and scheduling latency for time-sensitive clients?

Quoted 7 lines
drivers/dma/atcdmac300.c new file +0 -0
 		list_add_tail(&desc->desc_node, &(*first)->tx_list);
 	}
 	*prev = desc;
 
 	desc->regs.ll_ptr_hi = 0;
 	desc->regs.ll_ptr_lo = 0;
 }

[ ... ]

Quoted 11 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -345,6 +345,43 @@ static void atcdmac_advance_work(struct atcdmac_chan *dmac_chan)
 	struct dmaengine_result res;
 	LIST_HEAD(completed);
 	unsigned long flags;
 	unsigned short stop;
 
 	spin_lock_irqsave(&dmac_chan->lock, flags);
 	if (list_empty(&dmac_chan->active_list)) {
 		spin_unlock_irqrestore(&dmac_chan->lock, flags);
 		return;
 	}

drivers/dma/atcdmac300.c static void atcdmac_advance_work(struct atcdmac_chan *dmac_chan)

Quoted 10 lines
drivers/dma/atcdmac300.c new file +0 -0
 
 	dma_desc = atcdmac_get_active_head(dmac_chan);
 	stop = READ_ONCE(dmac->stop_mask) & BIT(dmac_chan->chan_id);
 	if (dmac_chan->cyclic) {
 		if (!stop)
 			atcdmac_start_next_trans(dmac_chan);
 
 		spin_unlock_irqrestore(&dmac_chan->lock, flags);
 		res.result = DMA_TRANS_NOERROR;
 		dmaengine_desc_get_callback_invoke(&dma_desc->txd, &res);

[Severity: High]
Could this lead to a race condition? The lock is dropped while dma_desc is still in the active_list. If dmaengine_terminate_all is called from another CPU, could it free the descriptor and allow it to be reallocated before the callback pointer is evaluated, potentially executing an overwritten callback?

Quoted 5 lines
drivers/dma/atcdmac300.c new file +0 -0
 	} else {
 		if (list_is_singular(&dmac_chan->active_list)) {
 			list_splice_init(&dmac_chan->active_list, &completed);
 			list_splice_init(&dmac_chan->queue_list,
 					 &dmac_chan->active_list);

[ ... ]

drivers/dma/atcdmac300.c static irqreturn_t atcdmac_interrupt(int irq, void *dev_id)

Quoted 13 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -472,6 +472,44 @@ static irqreturn_t atcdmac_interrupt(int irq, void *dev_id)
 	struct atcdmac_dmac *dmac = dev_id;
 	struct atcdmac_chan *dmac_chan;
 	unsigned int status;
 	unsigned int int_ch;
 	int ret = IRQ_NONE;
 	int i;
 
 	regmap_read(dmac->regmap, REG_INT_STA, &status);
 	int_ch = READ_ONCE(dmac->used_chan) & DMA_INT_ALL(status);
 
 	while (int_ch) {
 		spin_lock(&dmac->lock);

[Severity: High]
Does acquiring this spinlock in the primary hardirq handler cause issues on PREEMPT_RT kernels? Because spinlock_t is a preemptible sleepable lock on RT, acquiring it in hardirq context can trigger lockdep splats and deadlocks. Should dmac->lock be converted to a raw_spinlock_t?

[Severity: High]
By masking the interrupt status with used_chan, are we ignoring interrupts from hardware when used_chan is 0? If an unexpected interrupt fires, int_ch becomes 0 and the loop terminates without clearing the interrupt in REG_INT_STA. Since the IRQ is level-triggered, could this result in an infinite interrupt storm?

Quoted 5 lines
drivers/dma/atcdmac300.c new file +0 -0
 		dmac->used_chan = READ_ONCE(dmac->used_chan) & ~int_ch;
 		spin_unlock(&dmac->lock);
 		regmap_write(dmac->regmap, REG_INT_STA, DMA_INT_CLR(int_ch));
 
 		for (i = 0; i < dmac->num_ch; i++) {

[ ... ]

Quoted 14 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -638,6 +638,23 @@ static struct atcdmac_desc *
 atcdmac_build_desc(struct atcdmac_chan *dmac_chan,
 		   dma_addr_t src,
 		   dma_addr_t dst,
 		   unsigned int ctrl,
 		   unsigned int trans_size,
 		   unsigned int num_sg)
 {
 	struct atcdmac_desc *desc;
 
 	desc = atcdmac_get_desc(dmac_chan);
 	if (!desc)
 		return NULL;
 

drivers/dma/atcdmac300.c static struct atcdmac_desc *

Quoted 10 lines
drivers/dma/atcdmac300.c new file +0 -0
 	desc->regs.src_addr_lo = lower_32_bits(src);
 	desc->regs.src_addr_hi = upper_32_bits(src);
 	desc->regs.dst_addr_lo = lower_32_bits(dst);
 	desc->regs.dst_addr_hi = upper_32_bits(dst);
 	desc->regs.ctrl = ctrl;
 	desc->regs.trans_size = trans_size;
 	desc->num_sg = num_sg;
 
 	return desc;
 }

[Severity: Critical]
Are the linked list pointers cleared when a descriptor is reused? atcdmac_build_desc does not reset ll_ptr_lo and ll_ptr_hi. If this descriptor was previously used in a scatter-gather chain, could the hardware erroneously follow stale pointers and cause uncontrolled memory corruption?

[ ... ]

Quoted 7 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -953,6 +953,30 @@ static int atcdmac_terminate_all(struct dma_chan *chan)
 	struct atcdmac_chan *dmac_chan = atcdmac_chan_to_dmac_chan(chan);
 	struct atcdmac_desc *desc_cur, *desc_next;
 	LIST_HEAD(list);
 	unsigned long flags;
 	unsigned int val;
 	int ret;

drivers/dma/atcdmac300.c static int atcdmac_terminate_all(struct dma_chan *chan)

Quoted 10 lines
drivers/dma/atcdmac300.c new file +0 -0
 
 	spin_lock_irqsave(&dmac_chan->lock, flags);
 	atcdmac_abort_chan(dmac_chan);
 	atcdmac_enable_chan(dmac_chan, 0);
 	ret = regmap_read_poll_timeout_atomic(dmac_chan->dma_dev->regmap,
 					      REG_CH_EN,
 					      val,
 					      !(val & BIT(dmac_chan->chan_id)),
 					      10,
 					      ATCDMAC_CHAN_TIMEOUT_US);

[Severity: High]
Is it safe to poll for up to 100ms with local interrupts disabled? ATCDMAC_CHAN_TIMEOUT_US is 100,000. Busy-waiting this long in an atomic context can trigger soft lockups and trip the NMI watchdog.

[Severity: High]
Does aborting the channel here leave an unhandled abort interrupt pending? atcdmac_abort_chan() triggers a hardware abort, but the subsequent dmac_chan->chan_used = 0 causes the interrupt handler to ignore it. If a new transfer is submitted later, could the stale abort interrupt fire immediately, disrupting the new transfer state?

Quoted 3 lines
drivers/dma/atcdmac300.c new file +0 -0
 	if (ret)
 		dev_err(atcdmac_chan_to_dev(chan),
 			"Timed out waiting for channel to disable\n");

[ ... ]

Quoted 13 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1066,6 +1066,32 @@ static void atcdmac_free_chan_resources(struct dma_chan *chan)
 {
 	struct atcdmac_chan *dmac_chan = atcdmac_chan_to_dmac_chan(chan);
 	struct atcdmac_dmac *dmac = atcdmac_dev_to_dmac(chan->device);
 	struct atcdmac_desc *desc_next, *desc;
 	unsigned long flags;
 
 	WARN_ON_ONCE(atcdmac_is_chan_enable(dmac_chan));
 
 	spin_lock_irq(&dmac->lock);
 	dmac->stop_mask |= BIT(dmac_chan->chan_id);
 	spin_unlock_irq(&dmac->lock);
 

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

Quoted 10 lines
drivers/dma/atcdmac300.c new file +0 -0
 	atcdmac_terminate_all(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]
Could descriptors be leaked if a client submits a new transfer from within the completion callback during atcdmac_terminate_all? Since the loop above only iterates over free_list, any newly added descriptors in queue_list would not be freed and permanently leaked.

Quoted 3 lines
drivers/dma/atcdmac300.c new file +0 -0
 	INIT_LIST_HEAD(&dmac_chan->free_list);
 	dmac_chan->descs_allocated = 0;

[ ... ]

Quoted 29 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1438,6 +1438,40 @@ static int atcdmac_probe(struct platform_device *pdev)
 	struct atcdmac_dmac *dmac;
 	int ret;
 
 	ret = atcdmac_init_ioremap_and_regmap(pdev, &dmac);
 	if (ret)
 		return ret;
 
 	ret = atcdmac_reset_and_wait_chan_idle(dmac);
 	if (ret)
 		return ret;
 
 	ret = atcdmac_init_desc_pool(pdev, dmac);
 	if (ret)
 		return ret;
 
 	ret = atcdmac_init_channels(pdev, dmac);
 	if (ret)
 		return ret;
 
 	atcdmac_init_dma_device(pdev, dmac);
 
 	ret = dma_async_device_register(&dmac->dma_device);
 	if (ret)
 		return ret;
 
 	ret = atcdmac_init_irq(pdev, dmac);
 	if (ret)
 		goto err_dma_async_register;

drivers/dma/atcdmac300.c static int atcdmac_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/dma/atcdmac300.c new file +0 -0
 
 	ret = of_dma_controller_register(pdev->dev.of_node,
 					 atcdmac_dma_xlate_handler,
 					 dmac);
 	if (ret)
 		goto err_dma_async_register;
 
 	ret = atcdmac_init_iocp(pdev, dmac);
 	if (ret)
 		goto err_of_dma_register;

[Severity: High]
Are the frameworks being notified before the device is fully initialized? dma_async_device_register and of_dma_controller_register expose the device to clients, but atcdmac_init_irq and atcdmac_init_iocp are called after. If a client immediately queues a transfer, could it execute before the IRQ handler is ready, leading to unhandled interrupts?

Quoted 2 lines

return 0;

[ ... ]

Quoted 5 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1480,6 +1480,24 @@ static int atcdmac_suspend(struct device *dev)
 {
 	struct atcdmac_dmac *dmac = dev_get_drvdata(dev);
 	int ret;
 	unsigned long flags;

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

Quoted 10 lines
drivers/dma/atcdmac300.c new file +0 -0
 
 	spin_lock_irqsave(&dmac->lock, flags);
 	dmac->stop_mask = BIT(dmac->num_ch) - 1;
 	spin_unlock_irqrestore(&dmac->lock, flags);
 	ret = atcdmac_wait_chan_idle(dmac,
 				     dmac->stop_mask,
 				     ATCDMAC_CHAN_TIMEOUT_US * dmac->num_ch);
 
 	return ret;
 }

[Severity: High]
Does a timeout here leave the controller permanently disabled? If atcdmac_wait_chan_idle times out and returns an error, the PM core skips the resume callback. Because stop_mask is never cleared, does the DMA controller reject all future transfers until reboot?

Quoted 2 lines

static DEFINE_SIMPLE_DEV_PM_OPS(atcdmac_pm_ops,

[ ... ]

Quoted 4 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -1498,6 +1498,14 @@ static const struct of_device_id atcdmac_dt_ids[] = {
 	{ .compatible = "andestech,ae350-dma", },
 	{ /* sentinel */ },
 };

drivers/dma/atcdmac300.c static const struct of_device_id atcdmac_dt_ids[] = {

Quoted 10 lines
drivers/dma/atcdmac300.c new file +0 -0
 MODULE_DEVICE_TABLE(of, atcdmac_dt_ids);
 
 static struct platform_driver atcdmac_driver = {
 	.probe = atcdmac_probe,
 	.driver = {
 		.name = "atcdmac300",
 		.of_match_table = atcdmac_dt_ids,
 		.pm = pm_sleep_ptr(&atcdmac_pm_ops),
 	},
 };

[Severity: High]
Is a remove function needed here? Memory is allocated via devm_ functions, but the DMA controller and dmaengine are registered using non-devm APIs. If the driver is unbound via sysfs, could this lead to a use-after-free when clients attempt to access the freed memory?

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

PATCH v3 3/3 MAINTAINERS: Add entry for Andes ATCDMAC300

In reply to CL Wang

Add a MAINTAINERS entry for the Andes ATCDMAC300 DMA engine driver and its associated Device Tree bindings.

---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index 2fb1c75afd16..0d17580a6d17 100644
@@ -1868,6 +1868,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
Signature · 1 line
2.34.1