Skip to contentSkip to conversation

ASoC: Add support for Airoha AN7581

PATCH In review Christian Marangi 5 participants 12 messages Sep 8 – Oct 9

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

v6 cover ASoC: Add support for Airoha AN7581

Add all the patch and documentation to support Airoha AN7581 sound driver.

The card follows similar implementation with Mediatek with the codec present on i2c but with a simplified implementation register wise and additional frequency supported.

Changes v6:
- Fix PCM probe allocation logic
- Split driver patch to dedicated PCM/ETDM patch and machine driver Changes v5:
- Address comments from bot
- Better handle concurrent irq status bit
- Protect enable etdm
- Add Review tag for documentation patch
- Address formal comments from Cezary
Changes v4:
- Improve Documentation YAML
- Move IRQ regmap to mtk_base_afe_irq
- Use mutex for user tracking in ETDM
- Register IRQ after memif allocation
- Address suggestion from bot
Changes v3:
- Major fix to the ETDM code
- Add duplex support
- Improve Kconfig setup
- Rework and improve YAML schema
Changes v2:
- Fix wrong edit in MAINTAINERS file

Christian Marangi (5):
ASoC: dt-bindings: Add Airoha AN7581 AFE Sound card
ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema
ASoC: mediatek: common: permit to provide dedicated regmap for irq
ASoC: airoha: Add AFE driver for Airoha AN7581
ASoC: airoha: Add machine driver for Airoha AN7581

 .../bindings/sound/airoha,an7581-afe.yaml     |  41 ++
 .../bindings/sound/airoha,an7581-wm8960.yaml  |  71 +++
 MAINTAINERS                                   |   8 +
 sound/soc/mediatek/Kconfig                    |  27 +-
 sound/soc/mediatek/Makefile                   |   1 +
 sound/soc/mediatek/an7581/Makefile            |   9 +
 sound/soc/mediatek/an7581/an7581-afe-common.h |  49 ++
 sound/soc/mediatek/an7581/an7581-afe-pcm.c    | 515 ++++++++++++++++++
 sound/soc/mediatek/an7581/an7581-dai-etdm.c   | 433 +++++++++++++++
 sound/soc/mediatek/an7581/an7581-reg.h        | 114 ++++
 sound/soc/mediatek/an7581/an7581-wm8960.c     | 161 ++++++
 sound/soc/mediatek/common/mtk-afe-fe-dai.c    |  14 +-
 sound/soc/mediatek/common/mtk-base-afe.h      |   2 +
 13 files changed, 1439 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml
 create mode 100644 sound/soc/mediatek/an7581/Makefile
 create mode 100644 sound/soc/mediatek/an7581/an7581-afe-common.h
 create mode 100644 sound/soc/mediatek/an7581/an7581-afe-pcm.c
 create mode 100644 sound/soc/mediatek/an7581/an7581-dai-etdm.c
 create mode 100644 sound/soc/mediatek/an7581/an7581-reg.h
 create mode 100644 sound/soc/mediatek/an7581/an7581-wm8960.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH v6 1/5 ASoC: dt-bindings: Add Airoha AN7581 AFE Sound card

Add YAML schema for Airoha AN7581 AFE SoC sound card.

The AFE handling on this SoC is very basic with clock always enabled and all the power saving feature not available.

---
 .../bindings/sound/airoha,an7581-afe.yaml     | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml
Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml new file +41 -0
new file mode 100644
index 000000000000..80d9e87f1470
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/airoha,an7581-afe.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha AFE PCM controller for AN7581
+
+maintainers:
+  - Christian Marangi <[email protected]>
+
+properties:
+  compatible:
+    const: airoha,an7581-afe
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    afe@1fbe2200 {
+        compatible = "airoha,an7581-afe";
+        reg = <0x1fbe2200 0x9000>;
+
+        interrupts = <GIC_SPI 48 IRQ_TYPE_LEVEL_HIGH>;
+    };
+
+...
Signature · 1 line
2.53.0
#2 lore raw

PATCH v6 2/5 ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema

In reply to Christian Marangi

Add DT schema for Airoha AN7581 Sound Card with the specific WM8960 i2c Codec.

---
 .../bindings/sound/airoha,an7581-wm8960.yaml  | 71 +++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml
Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml new file +71 -0
new file mode 100644
index 000000000000..8886fbb6b43c
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/airoha,an7581-wm8960.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha AN7581 sound card with WM8960 codec
+
+maintainers:
+  - Christian Marangi <[email protected]>
+
+allOf:
+  - $ref: sound-card-common.yaml#
+
+properties:
+  compatible:
+    const: airoha,an7581-wm8960-sound
+
+  platform:
+    type: object
+
+    additionalProperties: false
+
+    properties:
+      sound-dai:
+        items:
+          - description: The phandle of AN7581 platform.
+
+    required:
+      - sound-dai
+
+  codec:
+    type: object
+
+    additionalProperties: false
+
+    properties:
+      sound-dai:
+        items:
+          - description: The phandle of WM8960 i2c codec.
+
+    required:
+      - sound-dai
+
+required:
+  - compatible
+  - audio-routing
+  - platform
+  - codec
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    sound {
+        compatible = "airoha,an7581-wm8960-sound";
+        model = "an7581-wm8960";
+        audio-routing =
+            "Headphone", "HP_L",
+            "Headphone", "HP_R",
+            "LINPUT1", "AMIC",
+            "RINPUT1", "AMIC";
+
+        platform {
+            sound-dai = <&afe>;
+        };
+
+        codec {
+            sound-dai = <&wm8960>;
+        };
+    };
Signature · 1 line
2.53.0
#3 lore raw

PATCH v6 3/5 ASoC: mediatek: common: permit to provide dedicated regmap for irq

In reply to Christian Marangi

Some SoC might require dedicated regmap to configure some specific IRQ register.

Add an extra entry in the base_afe_irq struct and use the specific regmap if defined.

If not defined then the global AFE regmap is used instead.

---
 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 14 +++++++++-----
 sound/soc/mediatek/common/mtk-base-afe.h   |  2 ++
 2 files changed, 11 insertions(+), 5 deletions(-)
sound/soc/mediatek/common/mtk-afe-fe-dai.c +9 -5
index 2a20fa5dba49..948f606cbaf2 100644
@@ -204,11 +204,15 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,
 	struct mtk_base_afe_irq *irqs = &afe->irqs[memif->irq_usage];
 	const struct mtk_base_irq_data *irq_data = irqs->irq_data;
 	unsigned int counter = runtime->period_size;
+	struct regmap *regmap = afe->regmap;
 	int fs;
 	int ret;
 
 	dev_dbg(afe->dev, "%s %s cmd=%d\n", __func__, memif->data->name, cmd);
 
+	if (irqs->regmap)
+		regmap = irqs->regmap;
+
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
 	case SNDRV_PCM_TRIGGER_RESUME:
@@ -220,7 +224,7 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,
 		}
 
 		/* set irq counter */
-		mtk_regmap_update_bits(afe->regmap, irq_data->irq_cnt_reg,
+		mtk_regmap_update_bits(regmap, irq_data->irq_cnt_reg,
 				       irq_data->irq_cnt_maskbit, counter,
 				       irq_data->irq_cnt_shift);
 
@@ -230,12 +234,12 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,
 		if (fs < 0)
 			return -EINVAL;
 
-		mtk_regmap_update_bits(afe->regmap, irq_data->irq_fs_reg,
+		mtk_regmap_update_bits(regmap, irq_data->irq_fs_reg,
 				       irq_data->irq_fs_maskbit, fs,
 				       irq_data->irq_fs_shift);
 
 		/* enable interrupt */
-		mtk_regmap_update_bits(afe->regmap, irq_data->irq_en_reg,
+		mtk_regmap_update_bits(regmap, irq_data->irq_en_reg,
 				       1, 1, irq_data->irq_en_shift);
 
 		return 0;
@@ -248,10 +252,10 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,
 		}
 
 		/* disable interrupt */
-		mtk_regmap_update_bits(afe->regmap, irq_data->irq_en_reg,
+		mtk_regmap_update_bits(regmap, irq_data->irq_en_reg,
 				       1, 0, irq_data->irq_en_shift);
 		/* and clear pending IRQ */
-		mtk_regmap_write(afe->regmap, irq_data->irq_clr_reg,
+		mtk_regmap_write(regmap, irq_data->irq_clr_reg,
 				 1 << irq_data->irq_clr_shift);
 		return ret;
 	default:
sound/soc/mediatek/common/mtk-base-afe.h +2 -0
index a406f2e3e7a8..b5300c9ed415 100644
@@ -153,6 +153,8 @@ struct mtk_base_afe_memif {
 struct mtk_base_afe_irq {
 	const struct mtk_base_irq_data *irq_data;
 	int irq_occupyed;
+
+	struct regmap *regmap;
 };
 
 struct mtk_base_afe_dai {
Signature · 1 line
2.53.0
#4 lore raw

PATCH v6 4/5 ASoC: airoha: Add AFE driver for Airoha AN7581

In reply to Christian Marangi

Add support for the Sound system present on Airoha AN7581 SoC. This is based on the Mediatek AFE drivers and adds the PCM and the ETDM driver.

---
 MAINTAINERS                                   |   8 +
 sound/soc/mediatek/Kconfig                    |  17 +-
 sound/soc/mediatek/Makefile                   |   1 +
 sound/soc/mediatek/an7581/Makefile            |   8 +
 sound/soc/mediatek/an7581/an7581-afe-common.h |  49 ++
 sound/soc/mediatek/an7581/an7581-afe-pcm.c    | 515 ++++++++++++++++++
 sound/soc/mediatek/an7581/an7581-dai-etdm.c   | 433 +++++++++++++++
 sound/soc/mediatek/an7581/an7581-reg.h        | 114 ++++
 8 files changed, 1144 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/mediatek/an7581/Makefile
 create mode 100644 sound/soc/mediatek/an7581/an7581-afe-common.h
 create mode 100644 sound/soc/mediatek/an7581/an7581-afe-pcm.c
 create mode 100644 sound/soc/mediatek/an7581/an7581-dai-etdm.c
 create mode 100644 sound/soc/mediatek/an7581/an7581-reg.h
MAINTAINERS +8 -0
index c3f72058a2f2..e3b7be8ad2dc 100644
@@ -768,6 +768,14 @@ F:	Documentation/devicetree/bindings/phy/airoha,en7581-pcie-phy.yaml
 F:	drivers/phy/phy-airoha-pcie-regs.h
 F:	drivers/phy/phy-airoha-pcie.c
 
+AIROHA SOUND DRIVER
+M:	Christian Marangi <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml
+F:	Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml
+F:	sound/soc/mediatek/an7581/*
+
 AIROHA SPI SNFI DRIVER
 M:	Lorenzo Bianconi <[email protected]>
 M:	Ray Liu <[email protected]>
sound/soc/mediatek/Kconfig +16 -1
index 224746e7664f..eb6f2a443b23 100644
@@ -1,10 +1,25 @@
 # SPDX-License-Identifier: GPL-2.0-only
-menu "Mediatek"
 
 config SND_SOC_MEDIATEK
 	tristate
 	select REGMAP_MMIO
 
+menu "Airoha"
+
+config SND_SOC_AN7581
+	tristate "ASoC support for Airoha AN7581 chip"
+	depends on ARCH_AIROHA || COMPILE_TEST
+	select SND_SOC_MEDIATEK
+	help
+	  This adds ASoC platform driver support for Airoha AN7581 chip
+	  that can be used with other codecs.
+	  Select Y if you have such device.
+	  If unsure select "N".
+
+endmenu
+
+menu "Mediatek"
+
 config SND_SOC_MT2701
 	tristate "ASoC support for Mediatek MT2701 chip"
 	depends on ARCH_MEDIATEK || COMPILE_TEST
sound/soc/mediatek/Makefile +1 -0
index a6815a3c5988..54522e1fa016 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
+obj-$(CONFIG_SND_SOC_AN7581) += an7581/
 obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT6797) += mt6797/
 obj-$(CONFIG_SND_SOC_MT7986) += mt7986/
sound/soc/mediatek/an7581/Makefile new file +8 -0
new file mode 100644
index 000000000000..d6de5ee1668e
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
+# platform driver
+snd-soc-an7581-afe-y := \
+	an7581-afe-pcm.o \
+	an7581-dai-etdm.o
+
+obj-$(CONFIG_SND_SOC_AN7581) += snd-soc-an7581-afe.o
sound/soc/mediatek/an7581/an7581-afe-common.h new file +49 -0

49 lines not on this page · raw message

sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +515 -0

515 lines not on this page · raw message

sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +433 -0

433 lines not on this page · raw message

sound/soc/mediatek/an7581/an7581-reg.h new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
2.53.0
#5 lore raw

Re: [PATCH v6 4/5] ASoC: airoha: Add AFE driver for Airoha AN7581

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Unconditional NULL pointer dereference in `mtk_dai_etdm_config` if `snd_soc_dai_set_fmt` is never…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Unconditional NULL pointer dereference in mtk_dai_etdm_config if snd_soc_dai_set_fmt is never called.
- [High] Unbalanced error path in an7581_afe_fe_startup leaves a dangling substream pointer leading to a Use-After-Free.
- [High] Impossible hardware constraints for capture streams due to a mix-up between frames and bytes.
- [Medium] Repeated, unbounded memory allocations in mtk_dai_etdm_set_fmt overwrite the previous pointer without freeing it.
- [Medium] DAI format clock inversion settings are successfully parsed but silently ignored by the hardware configuration. --

commit e1645bd481353127d1a22ed7f6309ae66d234cd2
Author: Christian Marangi <[email protected]>

ASoC: airoha: Add AFE driver for Airoha AN7581

Add support for the Sound system present on Airoha AN7581 SoC. This is based on the Mediatek AFE drivers and adds the PCM and the ETDM driver.

Quoted 5 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +0 -0
new file mode 100644
index 0000000000000..a1d742362538e

[ ... ]

Quoted 1 line
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +0 -0
@@ -0,0 +1,515 @@

[ ... ]

Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +4 -0
+static int an7581_afe_fe_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);

sound/soc/mediatek/an7581/an7581-afe-pcm.c line 136

Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10 -0
+	int ret;
+
+	ret = mtk_afe_fe_startup(substream, dai);
+	if (ret < 0)
+		return ret;
+
+	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+		ret = snd_pcm_hw_constraint_minmax(runtime,
+						   SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+						   0x2000, UINT_MAX);

[Severity: High]
Is this constraint using the correct parameter? The SNDRV_PCM_HW_PARAM_PERIOD_SIZE parameter is measured in frames, not bytes.

For an 8-channel, 32-bit capture stream (32 bytes per frame), 8192 frames equals 262,144 bytes, which exceeds the absolute maximum period_bytes_max of 131,072 bytes. This would cause the ALSA core interval intersection to fail and return -EINVAL.

Was this intended to be SNDRV_PCM_HW_PARAM_PERIOD_BYTES?

sound/soc/mediatek/an7581/an7581-afe-pcm.c line 142

Quoted 6 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +6 -0
+		if (ret < 0)
+			dev_err(afe->dev, "hw_constraint_minmax failed\n");
+	}
+
+	return ret;
+}

[Severity: High]
If snd_pcm_hw_constraint_minmax() fails here, does this error path leave a dangling substream pointer?

The earlier call to mtk_afe_fe_startup() saves the substream into the hardware tracking structure at memif->substream. Because we return immediately on failure without calling mtk_afe_fe_shutdown(), the ALSA core will destroy the stream without running the DAI .shutdown callback.

Could this lead to a use-after-free if a shared IRQ fires later and tries to access the freed memif->substream pointer?

[ ... ]

Quoted 5 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +0 -0
new file mode 100644
index 0000000000000..7fbfd8fe18362

[ ... ]

Quoted 1 line
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +0 -0
@@ -0,0 +1,433 @@

[ ... ]

Quoted 12 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +12 -0
+static int mtk_dai_etdm_config(struct mtk_base_afe *afe,
+			       struct snd_pcm_hw_params *params,
+			       struct snd_soc_dai *dai,
+			       int stream)
+{
+	struct an7581_afe_private *afe_priv = afe->platform_priv;
+	struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id];
+	unsigned int rate = params_rate(params);
+	unsigned int etdm_rate = an7581_etdm_rate_transform(afe->dev, rate);
+	unsigned int bit_width = params_width(params);
+	unsigned int mask, mask1;
+	unsigned int val, val1;

sound/soc/mediatek/an7581/an7581-dai-etdm.c line 187

Quoted 10 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +10 -0
+
+	dev_dbg(afe->dev, "%s(), stream %d, rate %u, bitwidth %u\n",
+		__func__, stream, rate, params_width(params));
+
+	/* CON0 */
+	mask = ETDM_SLAVE_MODE | ETDM_BIT_LEN | ETDM_WRD_LEN |
+	       ETDM_FMT | ETDM_CH_NUM;
+	val = FIELD_PREP(ETDM_BIT_LEN, params_width(params) - 1) |
+	      FIELD_PREP(ETDM_WRD_LEN, get_etdm_wlen(bit_width) - 1) |
+	      FIELD_PREP(ETDM_FMT, etdm_data->format) |

[Severity: High]
What happens if a machine driver does not configure the .dai_fmt on the DAI link?

If the ALSA core never invokes mtk_dai_etdm_set_fmt(), the pointer at afe_priv->dai_priv[dai->id] remains NULL. When a stream is opened and mtk_dai_etdm_config() runs, it appears this code will blindly fetch and dereference etdm_data->format.

Can this cause a kernel panic due to a NULL pointer dereference?

[Severity: Medium]
Are the clock inversion settings being silently ignored here?

The mtk_dai_etdm_set_fmt() function successfully parses the SND_SOC_DAIFMT_INV_MASK flags and stores them in etdm_data->bck_inv and etdm_data->lrck_inv. However, they don't seem to be applied when programming the ETDM_IN1_CON4 or ETDM_OUT1_CON5 registers in this configuration step.

Quoted 2 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +2 -0
+	      FIELD_PREP(ETDM_CH_NUM,
+			 get_etdm_ch_fixup(params_channels(params)) - 1);

[ ... ]

sound/soc/mediatek/an7581/an7581-dai-etdm.c line 325

Quoted 13 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +13 -0
+static int mtk_dai_etdm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
+	struct an7581_afe_private *afe_priv = afe->platform_priv;
+	struct mtk_dai_etdm_priv *etdm_data;
+	void *priv_data;
+
+	priv_data = devm_kzalloc(afe->dev, sizeof(struct mtk_dai_etdm_priv),
+				 GFP_KERNEL);
+	if (!priv_data)
+		return -ENOMEM;
+
+	afe_priv->dai_priv[dai->id] = priv_data;

[Severity: Medium]
Will this cause a memory leak if the DAI format is set multiple times?

A machine driver might configure the format dynamically or multiple times during stream restarts. Because this unconditionally allocates memory with devm_kzalloc() and overwrites the shared afe_priv->dai_priv[dai->id] pointer, it seems previous allocations will remain leaked for the lifespan of the device.

Quoted 3 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +3 -0
+	etdm_data = afe_priv->dai_priv[dai->id];
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {

[ ... ]

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

Re: [PATCH v6 4/5] ASoC: airoha: Add AFE driver for Airoha AN7581

In reply to Christian Marangi

sound/soc/mediatek/an7581/an7581-afe-pcm.c line 466

Quoted 5 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +5 -0
+       ret = devm_request_irq(dev, irq_id, an7581_afe_irq_handler,
+                              IRQF_TRIGGER_NONE, "asys-isr", (void *)afe);
+       if (ret)
+               return dev_err_probe(dev, ret, "Failed to request irq for asys-isr\n");
+

I think we can return the error directly here, as devm_request_irq() already reports the error.
dev_err_probe() would result in a redundant error message.

#7 lore raw

PATCH v6 5/5 ASoC: airoha: Add machine driver for Airoha AN7581

In reply to Christian Marangi

Add support for the machine driver for Airoha AN7581 paired with the WM8960 i2c codec. This driver creates the sound card for the AFE driver.

---
 sound/soc/mediatek/Kconfig                |  10 ++
 sound/soc/mediatek/an7581/Makefile        |   1 +
 sound/soc/mediatek/an7581/an7581-wm8960.c | 161 ++++++++++++++++++++++
 3 files changed, 172 insertions(+)
 create mode 100644 sound/soc/mediatek/an7581/an7581-wm8960.c
sound/soc/mediatek/Kconfig +10 -0
index eb6f2a443b23..ff2869641a35 100644
@@ -16,6 +16,16 @@ config SND_SOC_AN7581
 	  Select Y if you have such device.
 	  If unsure select "N".
 
+config SND_SOC_AN7581_WM8960
+	tristate "ASoc Audio driver for Airoha AN7581 with WM8960 codec"
+	depends on SND_SOC_AN7581 && I2C
+	select SND_SOC_WM8960
+	help
+	  This adds support for ASoC machine driver for Airoha AN7581
+	  boards with the WM8960 codecs.
+	  Select Y if you have such device.
+	  If unsure select "N".
+
 endmenu
 
 menu "Mediatek"
sound/soc/mediatek/an7581/Makefile +1 -0
index d6de5ee1668e..f48cd0269bea 100644
@@ -6,3 +6,4 @@ snd-soc-an7581-afe-y := \
 	an7581-dai-etdm.o
 
 obj-$(CONFIG_SND_SOC_AN7581) += snd-soc-an7581-afe.o
+obj-$(CONFIG_SND_SOC_AN7581_WM8960) += an7581-wm8960.o
sound/soc/mediatek/an7581/an7581-wm8960.c new file +161 -0

161 lines not on this page · raw message

Signature · 1 line
2.53.0
#8 lore raw

Re: [PATCH v6 5/5] ASoC: airoha: Add machine driver for Airoha AN7581

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Global static structures (`an7581_wm8960_card` and `an7581_wm8960_dai_links`) are modified during…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Global static structures (an7581_wm8960_card and an7581_wm8960_dai_links) are modified during probe without protection, leading to state corruption and potential Use-After-Free.
- [Medium] OF node references acquired via of_parse_phandle() are leaked on the successful probe path and never released on driver unbind.
- [Low] Duplicate platform components are defined and bound to each DAI link.
--

commit 7051186115da5c8ed0db19bf2c3b4aac46840edd
Author: Christian Marangi <[email protected]>

ASoC: airoha: Add machine driver for Airoha AN7581

Add support for the machine driver for Airoha AN7581 paired with the WM8960 i2c codec. This driver creates the sound card for the AFE driver.

Quoted 6 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +0 -0
new file mode 100644
index 0000000000000..03ea5732563cf
@@ -0,0 +1,161 @@

[ ... ]

sound/soc/mediatek/an7581/an7581-wm8960.c line 15

Quoted 4 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +4 -0
+SND_SOC_DAILINK_DEFS(playback,
+		     DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
+		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
+		     DAILINK_COMP_ARRAY(COMP_EMPTY(), COMP_EMPTY()));

[Severity: Low]
Are two platform components necessary for this DAI link?

The code defines two empty platform components here, and later assigns the exact same device node to both of them.

[ ... ]

sound/soc/mediatek/an7581/an7581-wm8960.c line 74

Quoted 9 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +9 -0
+static int an7581_wm8960_machine_probe(struct platform_device *pdev)
+{
+	struct device_node *platform_dai_node, *codec_dai_node;
+	struct snd_soc_card *card = &an7581_wm8960_card;
+	struct device_node *of_platform, *codec;
+	struct snd_soc_dai_link *dai_link;
+	int i, d, ret;
+
+	card->dev = &pdev->dev;

[Severity: High]
Does this code modify a global static structure during probe?

The an7581_wm8960_card structure is statically defined, but its dev pointer is overwritten with a per-device pointer here.

If the driver is unbound and rebound, or if multiple instances of this device exist, could this lead to state corruption or a use-after-free when device-managed memory is released?

Quoted 6 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +6 -0
+
+	of_platform = of_get_child_by_name(pdev->dev.of_node, "platform");
+
+	if (of_platform) {
+		platform_dai_node = of_parse_phandle(of_platform, "sound-dai", 0);
+		of_node_put(of_platform);

[ ... ]

sound/soc/mediatek/an7581/an7581-wm8960.c line 98

Quoted 8 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +8 -0
+	for_each_card_prelinks(card, i, dai_link) {
+		struct snd_soc_dai_link_component *platform;
+
+		dai_link->num_platforms = 2;
+		for_each_link_platforms(dai_link, d, platform) {
+			if (platform->name)
+				continue;
+			platform->of_node = platform_dai_node;

[Severity: Low]
Does this code assign the exact same platform_dai_node to both platform components?

Since dai_link->num_platforms is 2 and we have two empty platform components defined, this will bind the same component twice.

Quoted 7 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +7 -0
+		}
+	}
+
+	codec = of_get_child_by_name(pdev->dev.of_node, "codec");
+
+	if (codec) {
+		codec_dai_node = of_parse_phandle(codec, "sound-dai", 0);

[ ... ]

sound/soc/mediatek/an7581/an7581-wm8960.c line 122

Quoted 4 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +4 -0
+	for_each_card_prelinks(card, i, dai_link) {
+		if (dai_link->codecs->name)
+			continue;
+		dai_link->codecs->of_node = codec_dai_node;

[Severity: High]
Does this code modify the globally shared an7581_wm8960_dai_links array?

Writing a per-device codec_dai_node to a global structure could cause issues if the device is unbound, leading to dangling pointers for future probes.

sound/soc/mediatek/an7581/an7581-wm8960.c line 125

Quoted 3 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +3 -0
+	}
+
+	ret = snd_soc_of_parse_audio_routing(card, "audio-routing");

[Severity: High]
Does this introduce a use-after-free risk?

The snd_soc_of_parse_audio_routing function allocates device-managed memory for the routes and stores the pointer in the global static card->of_dapm_routes.

If the device is unbound, this memory will be freed, but the global structure will still hold a dangling pointer.

sound/soc/mediatek/an7581/an7581-wm8960.c line 137

Quoted 12 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +12 -0
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to parse audio-routing: %d\n", ret);
+		goto err_of_node_put;
+	}
+
+	ret = devm_snd_soc_register_card(&pdev->dev, card);
+	if (ret) {
+		dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__);
+		goto err_of_node_put;
+	}
+
+	return 0;

[Severity: Medium]
Will this successful return path leak the platform_dai_node and codec_dai_node references?

The references acquired via of_parse_phandle() earlier in the function are not released on success.

Since there is no .remove callback or device-managed cleanup action registered to release them upon driver unbind, could these device node references be permanently lost?

Quoted 6 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +6 -0
+
+err_of_node_put:
+	of_node_put(platform_dai_node);
+	of_node_put(codec_dai_node);
+	return ret;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
maintainer
#9 lore raw
In reply to Christian Marangi
Quoted 10 lines · Christian Marangi

ASoC: Add support for Airoha AN7581

Add all the patch and documentation to support Airoha AN7581 sound driver.

The card follows similar implementation with Mediatek with the codec present on i2c but with a simplified implementation register wise and additional frequency supported.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4

Thanks!

[1/5] ASoC: dt-bindings: Add Airoha AN7581 AFE Sound card

      https://git.kernel.org/broonie/sound/c/78da571393da
[2/5] ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema
      https://git.kernel.org/broonie/sound/c/8fcf0497e6da
[3/5] ASoC: mediatek: common: permit to provide dedicated regmap for irq
      https://git.kernel.org/broonie/sound/c/b49799e40313
[4/5] ASoC: airoha: Add AFE driver for Airoha AN7581
      https://git.kernel.org/broonie/sound/c/4974ffa0d6c2
[5/5] ASoC: airoha: Add machine driver for Airoha AN7581
      https://git.kernel.org/broonie/sound/c/272d6e51bc1f

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#10 lore raw
In reply to Christian Marangi
Quoted 7 lines · Christian Marangi

Add all the patch and documentation to support Airoha AN7581 sound driver.

The card follows similar implementation with Mediatek with the codec present on i2c but with a simplified implementation register wise and additional frequency supported.

Quoted 9 lines

Changes v6:
- Fix PCM probe allocation logic
- Split driver patch to dedicated PCM/ETDM patch and machine driver Changes v5:
- Address comments from bot
- Better handle concurrent irq status bit
- Protect enable etdm
- Add Review tag for documentation patch
- Address formal comments from Cezary

You've not included all the reviewers in the Cc list despite addressing some of the comments. I hope that wasn't done in bad faith to avoid further review.

Quoted 13 lines

Changes v4:
- Improve Documentation YAML
- Move IRQ regmap to mtk_base_afe_irq
- Use mutex for user tracking in ETDM
- Register IRQ after memif allocation
- Address suggestion from bot
Changes v3:
- Major fix to the ETDM code
- Add duplex support
- Improve Kconfig setup
- Rework and improve YAML schema
Changes v2:
- Fix wrong edit in MAINTAINERS file

#11 lore raw

Il giorno ven 9 ott 2026 alle ore 13:25 Cezary Rojewski <[email protected]> ha scritto:

Quoted 19 lines · Christian Marangi
Quoted 7 lines

Add all the patch and documentation to support Airoha AN7581 sound driver.

The card follows similar implementation with Mediatek with the codec present on i2c but with a simplified implementation register wise and additional frequency supported.

Quoted 9 lines

Changes v6:
- Fix PCM probe allocation logic
- Split driver patch to dedicated PCM/ETDM patch and machine driver Changes v5:
- Address comments from bot
- Better handle concurrent irq status bit
- Protect enable etdm
- Add Review tag for documentation patch
- Address formal comments from Cezary

Quoted 4 lines

You've not included all the reviewers in the Cc list despite addressing some of the comments. I hope that wasn't done in bad faith to avoid further review.

Absolutely not. I usually use get_maintainers script to get the emails so it's totally possible I make mistake and I forget to include reviewers.

If you have a better process, please suggest it!

Anyway, what did I miss? I can totally send a followup patch to address them! More than welcome to fix anything.

Quoted 15 lines
Quoted 13 lines

Changes v4:
- Improve Documentation YAML
- Move IRQ regmap to mtk_base_afe_irq
- Use mutex for user tracking in ETDM
- Register IRQ after memif allocation
- Address suggestion from bot
Changes v3:
- Major fix to the ETDM code
- Add duplex support
- Improve Kconfig setup
- Rework and improve YAML schema
Changes v2:
- Fix wrong edit in MAINTAINERS file