Skip to contentSkip to conversation

Add Amlogic general DMA

PATCH Applied Xianwei Zhao 3 participants 7 messages Sep 3 – Oct 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v12 cover Add Amlogic general DMA

Add DMA driver and bindigns for the Amlogic SoCs.

---
Changes in v12:
- Add prefix "AMLOGIG_A9_" for channel type.
- Use workqueue to free,and when remove module,destory queue.
- Consider the little-endian for hardware.
- Modify get dma status return value.
- Optimize the code according to Vinod's suggestion.
- Link to v11: https://lore.kernel.org/r/[email protected]

Changes in v11:
- MAX_DMA_LEN 4-byte align, and return real status when get, and lockless error print.
- Link to v10: https://lore.kernel.org/r/[email protected]

Changes in v10:
- Free dma memory in workqueue.
- Deal with zero len sg (not consume sg_link),and reset status to DMA_COMPLETE when terminal channel.
- Add desc for #dma-cells in dt-bindings.
- Link to v9: https://lore.kernel.org/r/[email protected]

Changes in v9:
- Use each transmission request sg_link mem instead of the loop mem get.
- Fix some hidden issues which reviewed by ai robot.
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- Use kzalloc instead of kmalloc.
- Initialize the temporary variable and fix a spelling mistake.
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- Take use vchan to support mltiple txns.
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- Some minor modifications according to Frank's suggestion.
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Rename head file and rename macro definition.
- Rename the subject in [2/3] from "dma" to "dmaengine".
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Support split transfer when data len > MAX_LEN.
- When a module fails or exits, perform de-initialization.
- Some other minor modifications.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Adjust the format of binding according to Frank's suggestion.
- Some code format modified according to Frank's suggestion.
- Support one prep_sg and one submit, drop multi prep_sg and one submit.
- Keep pre state when resume from pause status.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Introduce what the DMA is used for in the A9 SoC.
- Some minor modifications were made according to Krzysztof's suggestions.
- Some modifications were made according to Neil's suggestions.
- Fix a build error.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Xianwei Zhao (3):
dt-bindings: dma: Add Amlogic A9 SoC DMA
dmaengine: amlogic: Add general DMA driver for A9
MAINTAINERS: Add an entry for Amlogic DMA driver

 .../devicetree/bindings/dma/amlogic,a9-dma.yaml    |  68 ++
 MAINTAINERS                                        |   7 +
 drivers/dma/Kconfig                                |  10 +
 drivers/dma/Makefile                               |   1 +
 drivers/dma/amlogic-dma.c                          | 737 +++++++++++++++++++++
 include/dt-bindings/dma/amlogic,a9-dma.h           |   8 +
 6 files changed, 831 insertions(+)

---
base-commit: bea91d748771879c695b869a6c5a4a172cb0035f
change-id: 20251215-amlogic-dma-79477d5cd264

Best regards,

Signature · 1 line
Xianwei Zhao <[email protected]>
#1 lore raw

PATCH v12 1/3 dt-bindings: dma: Add Amlogic A9 SoC DMA

Add documentation describing the Amlogic A9 SoC DMA. And add the properties specific values defines into a new include file.

---
 .../devicetree/bindings/dma/amlogic,a9-dma.yaml    | 68 ++++++++++++++++++++++
 include/dt-bindings/dma/amlogic,a9-dma.h           |  8 +++
 2 files changed, 76 insertions(+)
Documentation/devicetree/bindings/dma/amlogic,a9-dma.yaml new file +68 -0
new file mode 100644
index 000000000000..3e1a4fba3047
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/amlogic,a9-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic general DMA controller
+
+description:
+  This is a general-purpose peripheral DMA controller. It currently supports
+  major peripherals including I2C, I3C, PIO, and CAN-BUS. Transmit and receive
+  for the same peripheral use two separate channels, controlled by different
+  register sets. I2C and I3C transfer data in 1-byte units, while PIO and
+  CAN-BUS transfer data in 4-byte units. From the controller’s perspective,
+  there is no significant difference.
+
+maintainers:
+  - Xianwei Zhao <[email protected]>
+
+properties:
+  compatible:
+    const: amlogic,a9-dma
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    const: sys
+
+  '#dma-cells':
+    const: 2
+    description:
+      The first cell is the DMA channel type(AMLOGIC_A9_DMA_TX or AMLOGIC_A9_DMA_RX).
+      The second cell is the DMA channel index.
+
+  dma-channels:
+    maximum: 64
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - '#dma-cells'
+  - dma-channels
+
+allOf:
+  - $ref: dma-controller.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    dma-controller@fe400000 {
+        compatible = "amlogic,a9-dma";
+        reg = <0xfe400000 0x4000>;
+        interrupts = <GIC_SPI 35 IRQ_TYPE_EDGE_RISING>;
+        clocks = <&clkc 45>;
+        #dma-cells = <2>;
+        dma-channels = <28>;
+    };
include/dt-bindings/dma/amlogic,a9-dma.h new file +8 -0
new file mode 100644
index 000000000000..ea7c90063572
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
+
+#ifndef __DT_BINDINGS_DMA_AMLOGIC_DMA_H__
+#define __DT_BINDINGS_DMA_AMLOGIC_DMA_H__
+
+#define AMLOGIC_A9_DMA_TX		0
+#define AMLOGIC_A9_DMA_RX		1
+#endif /* __DT_BINDINGS_DMA_AMLOGIC_DMA_H__ */
Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH v12 1/3] dt-bindings: dma: Add Amlogic A9 SoC DMA

Hi Krzysztof,
Based on the bot and Vinod's suggestions, I added a prefix
"AMLOGIC_A9" for channel type. I didn't remove your Reviewed-by tag for this change. Is this appropriate?

Quoted 102 lines · On 2026/9/3 15:38, Xianwei Zhao via B4 Relay wrote:

From: Xianwei Zhao<[email protected]>

Add documentation describing the Amlogic A9 SoC DMA. And add the properties specific values defines into a new include file.

---
  .../devicetree/bindings/dma/amlogic,a9-dma.yaml    | 68
++++++++++++++++++++++
  include/dt-bindings/dma/amlogic,a9-dma.h           |  8 +++
  2 files changed, 76 insertions(+)
Documentation/devicetree/bindings/dma/amlogic,a9-dma.yaml new file +68 -0
new file mode 100644
index 000000000000..3e1a4fba3047
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id:http://devicetree.org/schemas/dma/amlogic,a9-dma.yaml#
+$schema:http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic general DMA controller
+
+description:
+  This is a general-purpose peripheral DMA controller. It currently supports
+  major peripherals including I2C, I3C, PIO, and CAN-BUS. Transmit and receive
+  for the same peripheral use two separate channels, controlled by different
+  register sets. I2C and I3C transfer data in 1-byte units, while PIO and
+  CAN-BUS transfer data in 4-byte units. From the controller’s perspective,
+  there is no significant difference.
+
+maintainers:
+  - Xianwei Zhao<[email protected]>
+
+properties:
+  compatible:
+    const: amlogic,a9-dma
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    const: sys
+
+  '#dma-cells':
+    const: 2
+    description:
+      The first cell is the DMA channel type(AMLOGIC_A9_DMA_TX or AMLOGIC_A9_DMA_RX).
+      The second cell is the DMA channel index.
+
+  dma-channels:
+    maximum: 64
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - '#dma-cells'
+  - dma-channels
+
+allOf:
+  - $ref: dma-controller.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    dma-controller@fe400000 {
+        compatible = "amlogic,a9-dma";
+        reg = <0xfe400000 0x4000>;
+        interrupts = <GIC_SPI 35 IRQ_TYPE_EDGE_RISING>;
+        clocks = <&clkc 45>;
+        #dma-cells = <2>;
+        dma-channels = <28>;
+    };
include/dt-bindings/dma/amlogic,a9-dma.h new file +8 -0
new file mode 100644
index 000000000000..ea7c90063572
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
+
+#ifndef __DT_BINDINGS_DMA_AMLOGIC_DMA_H__
+#define __DT_BINDINGS_DMA_AMLOGIC_DMA_H__
+
+#define AMLOGIC_A9_DMA_TX              0
+#define AMLOGIC_A9_DMA_RX              1
+#endif /* __DT_BINDINGS_DMA_AMLOGIC_DMA_H__ */
#3 lore raw

PATCH v12 2/3 dmaengine: amlogic: Add general DMA driver for A9

In reply to Xianwei Zhao

Amlogic A9 SoCs include a general-purpose DMA controller that can be used by multiple peripherals, such as I2C PIO and I3C. Each peripheral group is associated with a dedicated DMA channel in hardware.

---
 drivers/dma/Kconfig       |  10 +
 drivers/dma/Makefile      |   1 +
 drivers/dma/amlogic-dma.c | 737 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 748 insertions(+)
drivers/dma/Kconfig +10 -0
index ae6a682c9f76..01f96a8257e5 100644
@@ -85,6 +85,16 @@ config AMCC_PPC440SPE_ADMA
 	help
 	  Enable support for the AMCC PPC440SPe RAID engines.
 
+config AMLOGIC_DMA
+	tristate "Amlogic general DMA support"
+	depends on ARCH_MESON || COMPILE_TEST
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	select REGMAP_MMIO
+	help
+	  Enable support for the Amlogic general DMA engines. THis DMA
+	  controller is used some Amlogic SoCs, such as A9.
+
 config APPLE_ADMAC
 	tristate "Apple ADMAC support"
 	depends on ARCH_APPLE || COMPILE_TEST
drivers/dma/Makefile +1 -0
index 14aa086629d5..f62d12b08e15 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_DMATEST) += dmatest.o
 obj-$(CONFIG_ALTERA_MSGDMA) += altera-msgdma.o
 obj-$(CONFIG_AMBA_PL08X) += amba-pl08x.o
 obj-$(CONFIG_AMCC_PPC440SPE_ADMA) += ppc4xx/
+obj-$(CONFIG_AMLOGIC_DMA) += amlogic-dma.o
 obj-$(CONFIG_APPLE_ADMAC) += apple-admac.o
 obj-$(CONFIG_ARM_DMA350) += arm-dma350.o
 obj-$(CONFIG_AT_HDMAC) += at_hdmac.o
drivers/dma/amlogic-dma.c new file +737 -0

737 lines not on this page · raw message

Signature · 1 line
2.52.0
#4 lore raw

Re: [PATCH v12 2/3] dmaengine: amlogic: Add general DMA driver for A9

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [High] Unmanaged workqueue `free_wq` leaks on probe errors, and premature tasklet termination in…

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] Unmanaged workqueue free_wq leaks on probe errors, and premature tasklet termination in remove() causes Use-After-Free due to devres ordering.
- [High] Bitwise ORing a host-endian constant into a little-endian (__le32) variable causes data corruption on big-endian architectures.
- [High] Failure to check platform_get_irq() return value breaks deferred probing.
- [High] aml_chan->status and aml_chan->err_num are updated outside the channel lock in aml_dma_terminate_all().
- [High] aml_dma_chan_resume() fails to start descriptors that were issued while the channel was paused.
- [Medium] aml_dma_tx_status() fails to check the desc_submitted list, leading to false errors and incorrect residue.
- [Medium] The interrupt handler unconditionally returns IRQ_HANDLED, defeating spurious interrupt detection.
- [Low] Taking the address of a member of a potentially NULL pointer in aml_dma_terminate_all().
--

commit 038e372b66227ebb6d24a3849c98d588ff0edcd7
Author: Xianwei Zhao <[email protected]>

dmaengine: amlogic: Add general DMA driver for A9

Amlogic A9 SoCs include a general-purpose DMA controller that can be used by multiple peripherals, such as I2C PIO and I3C. Each peripheral group is associated with a dedicated DMA channel in hardware.

Quoted 5 lines
drivers/dma/amlogic-dma.c new file +0 -0
new file mode 100644
index 0000000000000..b6687d98096c3

[ ... ]

Quoted 17 lines
drivers/dma/amlogic-dma.c new file +17 -0
+static enum dma_status aml_dma_tx_status(struct dma_chan *chan,
+					 dma_cookie_t cookie,
+					 struct dma_tx_state *txstate)
+{
+	struct aml_dma_chan *aml_chan = to_aml_dma_chan(chan);
+	struct aml_dma_dev *aml_dma = aml_chan->aml_dma;
+	struct aml_dma_desc *aml_desc = NULL;
+	struct virt_dma_desc *vd;
+	u32 residue = 0, done = 0;
+	unsigned long flags;
+	enum dma_status ret;
+
+	ret = dma_cookie_status(chan, cookie, txstate);
+	if (ret == DMA_COMPLETE)
+		return ret;
+
+	if (aml_chan->status == DMA_PAUSED)

drivers/dma/amlogic-dma.c line 248

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+		ret = DMA_PAUSED;
+	if (!txstate)
+		return ret;
+
+	spin_lock_irqsave(&aml_chan->vchan.lock, flags);
+	vd = vchan_find_desc(&aml_chan->vchan, cookie);
+	if (vd) {
+		aml_desc = to_aml_dma_desc(vd);
+		residue = aml_desc->data_len;
+	} else if (aml_chan->cur_desc && aml_chan->cur_desc->vd.tx.cookie == cookie) {

[Severity: Medium]
Does this skip checking the desc_submitted list?

When a DMA client submits a descriptor via tx_submit() but has not yet issued it via issue_pending(), the descriptor resides in desc_submitted. Since vchan_find_desc() only searches the desc_issued list, calling dma_tx_status() during this window will fail to find the descriptor. This causes the driver to incorrectly log a "cookie error" and return a residue of 0 instead of the full transfer length.

Quoted 11 lines
drivers/dma/amlogic-dma.c new file +11 -0
+		aml_desc = aml_chan->cur_desc;
+		regmap_read(aml_dma->regmap, aml_chan->reg_offs + RCH_RD_LEN, &done);
+		residue = aml_desc->data_len - done;
+	} else {
+		dev_err(aml_dma->dma_device.dev, "cookie error\n");
+	}
+	spin_unlock_irqrestore(&aml_chan->vchan.lock, flags);
+	dma_set_residue(txstate, residue);
+
+	return ret;
+}

[ ... ]

Quoted 5 lines
drivers/dma/amlogic-dma.c new file +5 -0
+static struct dma_async_tx_descriptor *aml_dma_prep_slave_sg
+		(struct dma_chan *chan, struct scatterlist *sgl,
+		unsigned int sg_len, enum dma_transfer_direction direction,
+		unsigned long flags, void *context)
+{

[ ... ]

drivers/dma/amlogic-dma.c line 324

Quoted 12 lines
drivers/dma/amlogic-dma.c new file +12 -0
+		/* set dma address and len to sglink*/
+		sg_link->addr_low = cpu_to_le32(lower_32_bits(paddr));
+		sg_link->addr_high = cpu_to_le32(upper_32_bits(paddr));
+		sg_link->ctl = cpu_to_le32(FIELD_PREP(LINK_LEN, avail));
+
+		aml_desc->data_len += sg_dma_len(sg);
+		sg_link++;
+	}
+
+	/* the last sg set eoc flag */
+	sg_link--;
+	sg_link->ctl |= LINK_EOC;

[Severity: High]
Can this cause data corruption on big-endian architectures?

The sg_link->ctl field is populated as an __le32, but the LINK_EOC flag (which evaluates to a host-endian BIT(28)) is bitwise OR'd directly into it. On big-endian systems, this will set the wrong bit in the memory-backed descriptor, meaning the hardware won't see the End-Of-Chain flag and may fetch uninitialized memory. Wrapping it with cpu_to_le32(LINK_EOC) would prevent this.

Quoted 3 lines
drivers/dma/amlogic-dma.c new file +3 -0
+
+	return vchan_tx_prep(&aml_chan->vchan, &aml_desc->vd, flags);
+}

[ ... ]

drivers/dma/amlogic-dma.c line 353

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+static int aml_dma_chan_resume(struct dma_chan *chan)
+{
+	struct aml_dma_chan *aml_chan = to_aml_dma_chan(chan);
+	struct aml_dma_dev *aml_dma = aml_chan->aml_dma;
+	unsigned long flags;
+
+	spin_lock_irqsave(&aml_chan->vchan.lock, flags);
+	regmap_clear_bits(aml_dma->regmap, aml_chan->reg_offs + RCH_CFG, CFG_PAUSE);
+	aml_chan->status = aml_chan->pre_status;
+	spin_unlock_irqrestore(&aml_chan->vchan.lock, flags);

[Severity: High]
Does aml_dma_chan_resume() fail to start descriptors that were issued while the channel was paused?

When a channel is paused, aml_chan->status is set to DMA_PAUSED. Any subsequent calls to aml_dma_issue_pending() append descriptors to the desc_issued list but return immediately from aml_dma_start() without triggering the hardware.

Because aml_dma_chan_resume() restores aml_chan->status to DMA_COMPLETE but does not check if the pending queue is non-empty, descriptors queued during the pause will stall indefinitely.

Quoted 19 lines
drivers/dma/amlogic-dma.c new file +19 -0
+
+	return 0;
+}
+
+static int aml_dma_terminate_all(struct dma_chan *chan)
+{
+	struct aml_dma_chan *aml_chan = to_aml_dma_chan(chan);
+	struct aml_dma_dev *aml_dma = aml_chan->aml_dma;
+	int chan_id = aml_chan->chan_id;
+	struct virt_dma_desc *cur_vd;
+	unsigned long flags;
+	LIST_HEAD(head);
+
+	spin_lock_irqsave(&aml_chan->vchan.lock, flags);
+	regmap_set_bits(aml_dma->regmap, aml_chan->reg_offs + RCH_CFG, CFG_PAUSE);
+	regmap_set_bits(aml_dma->regmap, aml_chan->reg_offs + RCH_CFG, CFG_CLEAR);
+
+	if (aml_chan->direction == DMA_MEM_TO_DEV)
+		regmap_set_bits(aml_dma->regmap, RCH_INT_MASK, BIT(chan_id));

drivers/dma/amlogic-dma.c line 382

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+	else if (aml_chan->direction == DMA_DEV_TO_MEM)
+		regmap_set_bits(aml_dma->regmap, WCH_INT_MASK, BIT(chan_id));
+
+	regmap_clear_bits(aml_dma->regmap, aml_chan->reg_offs + RCH_CFG, CFG_PAUSE);
+	regmap_clear_bits(aml_dma->regmap, aml_chan->reg_offs + RCH_CFG, CFG_CLEAR);
+
+	vchan_get_all_descriptors(&aml_chan->vchan, &head);
+	cur_vd = &aml_chan->cur_desc->vd;
+	aml_chan->cur_desc = NULL;
+	spin_unlock_irqrestore(&aml_chan->vchan.lock, flags);

[Severity: Low]
Is this taking the address of a member from a potentially NULL pointer?

If there is no active transfer, aml_chan->cur_desc is NULL. Calculating &aml_chan->cur_desc->vd before checking for NULL is undefined behavior in standard C. While it safely evaluates to NULL in the kernel because vd is at offset 0 and GCC is invoked with -fno-delete-null-pointer-checks, this diverges from the correct pattern used elsewhere in the driver.

drivers/dma/amlogic-dma.c line 389

Quoted 7 lines
drivers/dma/amlogic-dma.c new file +7 -0
+	if (cur_vd)
+		aml_dma_free_desc(cur_vd);
+
+	vchan_dma_desc_free_list(&aml_chan->vchan, &head);
+
+	aml_chan->status = DMA_COMPLETE;
+	aml_chan->err_num = 0;

[Severity: High]
Is there a race condition here since aml_chan->status and err_num are updated outside of the vchan.lock?

If a concurrent aml_dma_issue_pending() acquires the lock immediately after it is dropped here, it will see the stale aml_chan->status (e.g., DMA_PAUSED). aml_dma_start() will then return without touching the hardware. terminate_all will subsequently set the status to DMA_COMPLETE, but the newly queued transfer will be permanently stuck.

Quoted 3 lines
drivers/dma/amlogic-dma.c new file +3 -0
+
+	return 0;
+}

[ ... ]

Quoted 2 lines
drivers/dma/amlogic-dma.c new file +2 -0
+static irqreturn_t aml_dma_interrupt_handler(int irq, void *dev_id)
+{

[ ... ]

drivers/dma/amlogic-dma.c line 542

Quoted 7 lines
drivers/dma/amlogic-dma.c new file +7 -0
+		vchan_cookie_complete(&aml_desc->vd);
+		aml_chan->cur_desc = NULL;
+		aml_dma_start(aml_chan);
+		spin_unlock(&aml_chan->vchan.lock);
+	}
+
+	return IRQ_HANDLED;

[Severity: Medium]
Does this unconditionally return IRQ_HANDLED even when no hardware bits were set?

If the interrupt handler is invoked but the hardware did not assert the interrupt, the processing loops are skipped, but the function still returns IRQ_HANDLED. This violates the IRQ API contract (which requires returning IRQ_NONE) and prevents the core IRQ subsystem from detecting and disabling spurious interrupt storms.

Quoted 1 line

+}

[ ... ]

Quoted 25 lines
drivers/dma/amlogic-dma.c new file +25 -0
+static int aml_dma_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct dma_device *dma_dev;
+	struct aml_dma_dev *aml_dma;
+	int ret, i, len;
+	u32 chan_nr;
+
+	const struct regmap_config aml_regmap_config = {
+		.reg_bits = 32,
+		.val_bits = 32,
+		.reg_stride = 4,
+		.max_register = 0x3000,
+	};
+
+	ret = of_property_read_u32(np, "dma-channels", &chan_nr);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "failed to read dma-channels\n");
+	if (chan_nr > (MAX_CHAN_ID * 2))
+		return dev_err_probe(&pdev->dev, -EINVAL, "dma-channels unusual\n");
+
+	len = sizeof(struct aml_dma_dev) + sizeof(struct aml_dma_chan) * chan_nr;
+	aml_dma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
+	if (!aml_dma)
+		return -ENOMEM;

drivers/dma/amlogic-dma.c line 631

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+
+	aml_dma->free_wq = alloc_ordered_workqueue("aml_dma_free", 0);
+	if (!aml_dma->free_wq)
+		return -ENOMEM;
+
+	aml_dma->chan_nr = chan_nr;
+
+	aml_dma->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(aml_dma->base))
+		return PTR_ERR(aml_dma->base);

[Severity: High]
Does this leak free_wq on probe errors?

If devm_platform_ioremap_resource() or any subsequent registration fails during probe, the function returns an error without calling destroy_workqueue(aml_dma->free_wq), leaking the workqueue memory.

Quoted 4 lines
drivers/dma/amlogic-dma.c new file +4 -0
+
+	aml_dma->regmap = devm_regmap_init_mmio(&pdev->dev, aml_dma->base,
+						&aml_regmap_config);
+	if (IS_ERR_OR_NULL(aml_dma->regmap))

drivers/dma/amlogic-dma.c line 645

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+		return PTR_ERR(aml_dma->regmap);
+
+	aml_dma->clk = devm_clk_get_enabled(&pdev->dev, NULL);
+	if (IS_ERR(aml_dma->clk))
+		return PTR_ERR(aml_dma->clk);
+
+	aml_dma->irq = platform_get_irq(pdev, 0);
+
+	aml_dma->pdev = pdev;
+	aml_dma->dma_device.dev = &pdev->dev;

[Severity: High]
Does this break deferred probing by missing a bounds check on the returned IRQ value?

platform_get_irq() can return a negative error code such as -EPROBE_DEFER. By unconditionally assigning it to aml_dma->irq and passing it to devm_request_irq(), the IRQ core will reject the negative IRQ value and return -EINVAL. This overwrites the -EPROBE_DEFER error and causes a permanent failure to probe.

Quoted 2 lines
drivers/dma/amlogic-dma.c new file +2 -0
+
+	dma_dev = &aml_dma->dma_device;

[ ... ]

Quoted 11 lines
drivers/dma/amlogic-dma.c new file +11 -0
+static void aml_dma_remove(struct platform_device *pdev)
+{
+	struct aml_dma_dev *aml_dma = platform_get_drvdata(pdev);
+	struct aml_dma_chan *aml_chan = NULL;
+	int i;
+
+	of_dma_controller_free((&pdev->dev)->of_node);
+
+	regmap_write(aml_dma->regmap, RCH_INT_MASK, INT_MASK);
+	regmap_write(aml_dma->regmap, WCH_INT_MASK, INT_MASK);
+

drivers/dma/amlogic-dma.c line 716

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+	for (i = 0; i < MAX_CHAN_ID; i++) {
+		aml_chan = aml_dma->aml_rch[i];
+		if (aml_chan)
+			tasklet_kill(&aml_chan->vchan.task);
+		aml_chan = aml_dma->aml_wch[i];
+		if (aml_chan)
+			tasklet_kill(&aml_chan->vchan.task);
+	}
+	destroy_workqueue(aml_dma->free_wq);
+}

[Severity: High]
Is there a use-after-free race condition during driver unbind?

The tasklets are killed here, but because devm_request_irq() was used during probe, the IRQ line remains active until devres runs after aml_dma_remove() returns.

Without a call to synchronize_irq(), an in-flight interrupt on another CPU could schedule the tasklet again after tasklet_kill() has finished. When devres subsequently frees the driver's memory, the delayed tasklet will execute on freed memory.

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

PATCH v12 3/3 MAINTAINERS: Add an entry for Amlogic DMA driver

In reply to Xianwei Zhao

Add Amlogic DMA controller entry to MAINTAINERS to clarify the maintainers.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 3e7b2d9e9c24..b4ef8d3f52cb 100644
@@ -1307,6 +1307,13 @@ F:	Documentation/devicetree/bindings/perf/amlogic,g12-ddr-pmu.yaml
 F:	drivers/perf/amlogic/
 F:	include/soc/amlogic/
 
+AMLOGIC DMA DRIVER
+M:	Xianwei Zhao <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/dma/amlogic,a9-dma.yaml
+F:	drivers/dma/amlogic-dma.c
+
 AMLOGIC ISP DRIVER
 M:	Keke Li <[email protected]>
 L:	[email protected]
Signature · 1 line
2.52.0
maintainer Applied
#6 lore raw
In reply to Xianwei Zhao
Quoted 3 lines · Xianwei Zhao

Add DMA driver and bindigns for the Amlogic SoCs.

Applied, thanks!

[1/3] dt-bindings: dma: Add Amlogic A9 SoC DMA

      commit: 9d79e5efaf7b908fd3eea1a6afb34fc06dfa1d7e
[2/3] dmaengine: amlogic: Add general DMA driver for A9
      commit: b84b5197e344e2d378a9edf5d782b6fbddff8d06
[3/3] MAINTAINERS: Add an entry for Amlogic DMA driver
      commit: a5b2763df36b5c8ca0927f24ee97d9617e4eb6eb

Best regards,

Signature · 1 line
~Vinod