Skip to contentSkip to conversation

ASoC: Intel: avs: Code cleanups and separation

PATCH In review Cezary Rojewski 2 participants 6 messages Aug 18, 2025 – Aug 19, 2025

Subsystems (3)
lore
Share & tools
lore

Cezary Rojewski

author maintainer
#0 lore raw

cover ASoC: Intel: avs: Code cleanups and separation

Set of patches that brings no new functionality but makes it easier to maintain and read the avs-driver code. There is one 'fix' among them - the third patch, described below.

First, debug-related code - mainly the data-probing feature - is mixed with non-debug PCM code. Separate it into debug.h and update the pcm.c file.

Next, as the probing-board is not tied to any topology file, it shall not using struct avs_soc_component descriptor but the basic struct snd_soc_component one. While on the first sight this is just bump in LOCs, runtime is simplified as no topology checks and related code will be engaged.

With probing-board addressed and debug code relocated:
- address the component-teardown issues when the componet->name points to a string which is shared by multiple components and/or machine boards. devm_kstrdup() makes this go away.

- streamline the naming scheme for the functions engaged in the components registration. This is purely a readability improvement.

Cezary Rojewski (4):
ASoC: Intel: avs: Separate debug symbols
ASoC: Intel: avs: Drop pcm.h dependency for probes
ASoC: Intel: avs: Do not share the name pointer between components
ASoC: Intel: avs: Streamline register-component function names

 sound/soc/intel/avs/apl.c             |  1 +
 sound/soc/intel/avs/avs.h             | 89 +++-----------------------
 sound/soc/intel/avs/board_selection.c | 10 +--
 sound/soc/intel/avs/cnl.c             |  1 +
 sound/soc/intel/avs/core.c            |  1 +
 sound/soc/intel/avs/debug.h           | 91 +++++++++++++++++++++++++++
 sound/soc/intel/avs/debugfs.c         |  1 +
 sound/soc/intel/avs/icl.c             |  1 +
 sound/soc/intel/avs/ipc.c             |  1 +
 sound/soc/intel/avs/lnl.c             |  1 +
 sound/soc/intel/avs/mtl.c             |  1 +
 sound/soc/intel/avs/pcm.c             | 35 ++++++-----
 sound/soc/intel/avs/probes.c          | 23 +++++--
 sound/soc/intel/avs/ptl.c             |  1 +
 sound/soc/intel/avs/skl.c             |  1 +
 sound/soc/intel/avs/tgl.c             |  1 +
 16 files changed, 153 insertions(+), 106 deletions(-)
 create mode 100644 sound/soc/intel/avs/debug.h
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/4 ASoC: Intel: avs: Separate debug symbols

Make it clear what is part of debug functionality and what is not by separating debug symbols away from the common header file.

Apart from changing avs_probe_platform_register() to return -ENOTSUPP when CONFIG_DEBUG_FS is disabled, status quo is achieved.

---
 sound/soc/intel/avs/apl.c             |  1 +
 sound/soc/intel/avs/avs.h             | 75 +---------------------
 sound/soc/intel/avs/board_selection.c |  1 +
 sound/soc/intel/avs/cnl.c             |  1 +
 sound/soc/intel/avs/core.c            |  1 +
 sound/soc/intel/avs/debug.h           | 91 +++++++++++++++++++++++++++
 sound/soc/intel/avs/debugfs.c         |  1 +
 sound/soc/intel/avs/icl.c             |  1 +
 sound/soc/intel/avs/ipc.c             |  1 +
 sound/soc/intel/avs/lnl.c             |  1 +
 sound/soc/intel/avs/mtl.c             |  1 +
 sound/soc/intel/avs/probes.c          |  1 +
 sound/soc/intel/avs/ptl.c             |  1 +
 sound/soc/intel/avs/skl.c             |  1 +
 sound/soc/intel/avs/tgl.c             |  1 +
 15 files changed, 105 insertions(+), 74 deletions(-)
 create mode 100644 sound/soc/intel/avs/debug.h
sound/soc/intel/avs/apl.c +1 -0
index 3dccf0a57a3a..b922eeaba843 100644
@@ -10,6 +10,7 @@
 #include <linux/slab.h>
 #include <sound/hdaudio_ext.h>
 #include "avs.h"
+#include "debug.h"
 #include "messages.h"
 #include "path.h"
 #include "registers.h"
sound/soc/intel/avs/avs.h +1 -74

81 lines not on this page · raw message

sound/soc/intel/avs/board_selection.c +1 -0
index fb49167f5fc4..9eb59d5a73f7 100644
@@ -17,6 +17,7 @@
 #include <sound/soc-acpi.h>
 #include <sound/soc-component.h>
 #include "avs.h"
+#include "debug.h"
 #include "utils.h"
 
 static char *i2s_test;
sound/soc/intel/avs/cnl.c +1 -0
index 03f8fb0dc187..5b5359e9128b 100644
@@ -8,6 +8,7 @@
 
 #include <sound/hdaudio_ext.h>
 #include "avs.h"
+#include "debug.h"
 #include "messages.h"
 #include "registers.h"
 
sound/soc/intel/avs/core.c +1 -0
index 5ebadba07ecc..6e0e65584c7f 100644
@@ -27,6 +27,7 @@
 #include "../../codecs/hda.h"
 #include "avs.h"
 #include "cldma.h"
+#include "debug.h"
 #include "messages.h"
 #include "pcm.h"
 
sound/soc/intel/avs/debug.h new file +91 -0

91 lines not on this page · raw message

sound/soc/intel/avs/debugfs.c +1 -0
index f508f215ecd2..3534de46f9e4 100644
@@ -13,6 +13,7 @@
 #include <linux/string_helpers.h>
 #include <sound/soc.h>
 #include "avs.h"
+#include "debug.h"
 #include "messages.h"
 
 static unsigned int __kfifo_fromio(struct kfifo *fifo, const void __iomem *src, unsigned int len)
sound/soc/intel/avs/icl.c +1 -0
index f8d327ea2656..d655e727bebd 100644
@@ -10,6 +10,7 @@
 #include <sound/hdaudio.h>
 #include <sound/hdaudio_ext.h>
 #include "avs.h"
+#include "debug.h"
 #include "messages.h"
 
 #define ICL_VS_LTRP_GB_ICCMAX	95
sound/soc/intel/avs/ipc.c +1 -0
index 6bfb9d1a1ca8..c0feb9edd7f6 100644
@@ -10,6 +10,7 @@
 #include <linux/slab.h>
 #include <sound/hdaudio_ext.h>
 #include "avs.h"
+#include "debug.h"
 #include "messages.h"
 #include "registers.h"
 #include "trace.h"
sound/soc/intel/avs/lnl.c +1 -0
index 03208596dfb1..4fbc62bfd6c5 100644
@@ -8,6 +8,7 @@
 
 #include <sound/hdaudio_ext.h>
 #include "avs.h"
+#include "debug.h"
 #include "registers.h"
 
 int avs_lnl_core_stall(struct avs_dev *adev, u32 core_mask, bool stall)
sound/soc/intel/avs/mtl.c +1 -0
index e7b7915b2a82..d8bdd03275d7 100644
@@ -8,6 +8,7 @@
 
 #include <sound/hdaudio_ext.h>
 #include "avs.h"
+#include "debug.h"
 #include "registers.h"
 #include "trace.h"
 
sound/soc/intel/avs/probes.c +1 -0
index a42736b9aa55..505ca4975e61 100644
@@ -11,6 +11,7 @@
 #include <sound/hdaudio.h>
 #include <sound/soc.h>
 #include "avs.h"
+#include "debug.h"
 #include "messages.h"
 
 static int avs_dsp_init_probe(struct avs_dev *adev, union avs_connector_node_id node_id,
sound/soc/intel/avs/ptl.c +1 -0
index 2be4b545c91d..07da9b0aa2b8 100644
@@ -8,6 +8,7 @@
 
 #include <sound/hdaudio_ext.h>
 #include "avs.h"
+#include "debug.h"
 #include "registers.h"
 #include "trace.h"
 
sound/soc/intel/avs/skl.c +1 -0
index d66ef000de9e..8fb86f364ff3 100644
@@ -11,6 +11,7 @@
 #include <sound/hdaudio_ext.h>
 #include "avs.h"
 #include "cldma.h"
+#include "debug.h"
 #include "messages.h"
 #include "registers.h"
 
sound/soc/intel/avs/tgl.c +1 -0
index 9dbb3ad0954a..afb066516101 100644
@@ -8,6 +8,7 @@
 
 #include <linux/pci.h>
 #include "avs.h"
+#include "debug.h"
 #include "messages.h"
 
 #define CPUID_TSC_LEAF 0x15
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH 2/4 ASoC: Intel: avs: Drop pcm.h dependency for probes

In reply to Cezary Rojewski

The 'probe' machine board is not a typical one, it serves debug purpose only and does not expect any kind of topology. The topology descriptor pointer (acomp->tplg) is the only reason an avs-driver component would utilize the pcm.c helpers and be described by a 'struct avs_soc_component' instance rather than 'struct snd_soc_component' one.

Cut the line linking probes.c with pcm.h to avoid confusing readers. And with that link gone, constify the component-driver again.

---
 sound/soc/intel/avs/probes.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
sound/soc/intel/avs/probes.c +17 -3
index 505ca4975e61..88c6d385c73c 100644
@@ -285,7 +285,7 @@ static struct snd_soc_dai_driver probe_cpu_dais[] = {
 },
 };
 
-static struct snd_soc_component_driver avs_probe_component_driver = {
+static const struct snd_soc_component_driver avs_probe_component_driver = {
 	.name			= "avs-probe-compr",
 	.compress_ops		= &avs_probe_compress_ops,
 	.module_get_upon_open	= 1, /* increment refcount when a stream is opened */
@@ -293,6 +293,20 @@ static struct snd_soc_component_driver avs_probe_component_driver = {
 
 int avs_probe_platform_register(struct avs_dev *adev, const char *name)
 {
-	return avs_soc_component_register(adev->dev, name, &avs_probe_component_driver,
-					  probe_cpu_dais, ARRAY_SIZE(probe_cpu_dais));
+	struct snd_soc_component *component;
+	int ret;
+
+	component = devm_kzalloc(adev->dev, sizeof(*component), GFP_KERNEL);
+	if (!component)
+		return -ENOMEM;
+
+	component->name = devm_kstrdup(adev->dev, name, GFP_KERNEL);
+	if (!component->name)
+		return -ENOMEM;
+
+	ret = snd_soc_component_initialize(component, &avs_probe_component_driver, adev->dev);
+	if (ret)
+		return ret;
+
+	return snd_soc_add_component(component, probe_cpu_dais, ARRAY_SIZE(probe_cpu_dais));
 }
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH 3/4 ASoC: Intel: avs: Do not share the name pointer between components

In reply to Cezary Rojewski

By sharing 'name' directly, tearing down components may lead to use-after-free errors. Duplicate the name to avoid that.

At the same time, update the order of operations - since commit cee28113db17 ("ASoC: dmaengine_pcm: Allow passing component name via config") the framework does not override component->name if set before invoking the initializer.

---
 sound/soc/intel/avs/pcm.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
sound/soc/intel/avs/pcm.c +7 -5
index 67ce6675eea7..e738deb2d314 100644
@@ -1390,16 +1390,18 @@ int avs_soc_component_register(struct device *dev, const char *name,
 	if (!acomp)
 		return -ENOMEM;
 
-	ret = snd_soc_component_initialize(&acomp->base, drv, dev);
-	if (ret < 0)
-		return ret;
+	acomp->base.name = devm_kstrdup(dev, name, GFP_KERNEL);
+	if (!acomp->base.name)
+		return -ENOMEM;
 
-	/* force name change after ASoC is done with its init */
-	acomp->base.name = name;
 	INIT_LIST_HEAD(&acomp->node);
 
 	drv->use_dai_pcm_id = !obsolete_card_names;
 
+	ret = snd_soc_component_initialize(&acomp->base, drv, dev);
+	if (ret < 0)
+		return ret;
+
 	return snd_soc_add_component(&acomp->base, cpu_dais, num_cpu_dais);
 }
 
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH 4/4 ASoC: Intel: avs: Streamline register-component function names

In reply to Cezary Rojewski

Word 'component' is commonly used in ASoC when referring to any component, regardless if it is a platform-type or codec-type component. Reword all avs_xxx_platform_register() to match the scheme present in ASoC's core. In case of avs_soc_component_register(), the name is simplified.

Summary:
- avs_xxx_platform_register() -> avs_register_xxx_component()
- avs_soc_component_register() -> avs_register_component()

---
 sound/soc/intel/avs/avs.h             | 14 +++++++-------
 sound/soc/intel/avs/board_selection.c |  9 +++++----
 sound/soc/intel/avs/debug.h           |  4 ++--
 sound/soc/intel/avs/pcm.c             | 23 +++++++++++------------
 sound/soc/intel/avs/probes.c          |  2 +-
 5 files changed, 26 insertions(+), 26 deletions(-)
sound/soc/intel/avs/avs.h +7 -7
index 2be35c19d6ee..95f9ac2683c0 100644
@@ -348,13 +348,13 @@ struct avs_soc_component {
 
 extern const struct snd_soc_dai_ops avs_dai_fe_ops;
 
-int avs_soc_component_register(struct device *dev, const char *name,
-			       struct snd_soc_component_driver *drv,
-			       struct snd_soc_dai_driver *cpu_dais, int num_cpu_dais);
-int avs_dmic_platform_register(struct avs_dev *adev, const char *name);
-int avs_i2s_platform_register(struct avs_dev *adev, const char *name, unsigned long port_mask,
-			      unsigned long *tdms);
-int avs_hda_platform_register(struct avs_dev *adev, const char *name);
+int avs_register_dmic_component(struct avs_dev *adev, const char *name);
+int avs_register_i2s_component(struct avs_dev *adev, const char *name, unsigned long port_mask,
+			       unsigned long *tdms);
+int avs_register_hda_component(struct avs_dev *adev, const char *name);
+int avs_register_component(struct device *dev, const char *name,
+			   struct snd_soc_component_driver *drv,
+			   struct snd_soc_dai_driver *cpu_dais, int num_cpu_dais);
 
 int avs_register_all_boards(struct avs_dev *adev);
 void avs_unregister_all_boards(struct avs_dev *adev);
sound/soc/intel/avs/board_selection.c +5 -4
index 9eb59d5a73f7..e1d6fa344aa1 100644
@@ -18,6 +18,7 @@
 #include <sound/soc-component.h>
 #include "avs.h"
 #include "debug.h"
+#include "pcm.h"
 #include "utils.h"
 
 static char *i2s_test;
@@ -410,7 +411,7 @@ static int __maybe_unused avs_register_probe_board(struct avs_dev *adev)
 	struct snd_soc_acpi_mach mach = {{0}};
 	int ret;
 
-	ret = avs_probe_platform_register(adev, "probe-platform");
+	ret = avs_register_probe_component(adev, "probe-platform");
 	if (ret < 0)
 		return ret;
 
@@ -455,7 +456,7 @@ static int avs_register_dmic_board(struct avs_dev *adev)
 		return ret;
 	}
 
-	ret = avs_dmic_platform_register(adev, "dmic-platform");
+	ret = avs_register_dmic_component(adev, "dmic-platform");
 	if (ret < 0)
 		return ret;
 
@@ -516,7 +517,7 @@ static int avs_register_i2s_board(struct avs_dev *adev, struct snd_soc_acpi_mach
 	if (!name)
 		return -ENOMEM;
 
-	ret = avs_i2s_platform_register(adev, name, mach->mach_params.i2s_link_mask, pdata->tdms);
+	ret = avs_register_i2s_component(adev, name, mach->mach_params.i2s_link_mask, pdata->tdms);
 	if (ret < 0)
 		return ret;
 
@@ -655,7 +656,7 @@ static int avs_register_hda_board(struct avs_dev *adev, struct hda_codec *codec)
 	pdata->obsolete_card_names = obsolete_card_names;
 	pdata->codec = codec;
 
-	ret = avs_hda_platform_register(adev, pname);
+	ret = avs_register_hda_component(adev, pname);
 	if (ret < 0)
 		return ret;
 
sound/soc/intel/avs/debug.h +2 -2
index 9f0f6f3b2bde..94fe8729a5c1 100644
@@ -50,7 +50,7 @@ static_assert(sizeof(struct avs_apl_log_buffer_layout) == 8);
 	(addr + sizeof(struct avs_apl_log_buffer_layout))
 
 #ifdef CONFIG_DEBUG_FS
-int avs_probe_platform_register(struct avs_dev *adev, const char *name);
+int avs_register_probe_component(struct avs_dev *adev, const char *name);
 
 #define AVS_SET_ENABLE_LOGS_OP(name) \
 	.enable_logs = avs_##name##_enable_logs
@@ -63,7 +63,7 @@ void avs_debugfs_init(struct avs_dev *adev);
 void avs_debugfs_exit(struct avs_dev *adev);
 
 #else
-static inline int avs_probe_platform_register(struct avs_dev *adev, const char *name)
+static inline int avs_register_probe_component(struct avs_dev *adev, const char *name)
 {
 	return -EOPNOTSUPP;
 }
sound/soc/intel/avs/pcm.c +11 -12
index e738deb2d314..d31058e2de5b 100644
@@ -1379,9 +1379,9 @@ static struct snd_soc_component_driver avs_component_driver = {
 	.topology_name_prefix	= "intel/avs",
 };
 
-int avs_soc_component_register(struct device *dev, const char *name,
-			       struct snd_soc_component_driver *drv,
-			       struct snd_soc_dai_driver *cpu_dais, int num_cpu_dais)
+int avs_register_component(struct device *dev, const char *name,
+			   struct snd_soc_component_driver *drv,
+			   struct snd_soc_dai_driver *cpu_dais, int num_cpu_dais)
 {
 	struct avs_soc_component *acomp;
 	int ret;
@@ -1428,7 +1428,7 @@ static struct snd_soc_dai_driver dmic_cpu_dais[] = {
 },
 };
 
-int avs_dmic_platform_register(struct avs_dev *adev, const char *name)
+int avs_register_dmic_component(struct avs_dev *adev, const char *name)
 {
 	const struct snd_soc_dai_ops *ops;
 
@@ -1439,8 +1439,8 @@ int avs_dmic_platform_register(struct avs_dev *adev, const char *name)
 
 	dmic_cpu_dais[0].ops = ops;
 	dmic_cpu_dais[1].ops = ops;
-	return avs_soc_component_register(adev->dev, name, &avs_component_driver, dmic_cpu_dais,
-					  ARRAY_SIZE(dmic_cpu_dais));
+	return avs_register_component(adev->dev, name, &avs_component_driver, dmic_cpu_dais,
+				      ARRAY_SIZE(dmic_cpu_dais));
 }
 
 static const struct snd_soc_dai_driver i2s_dai_template = {
@@ -1472,8 +1472,8 @@ static const struct snd_soc_dai_driver i2s_dai_template = {
 	},
 };
 
-int avs_i2s_platform_register(struct avs_dev *adev, const char *name, unsigned long port_mask,
-			      unsigned long *tdms)
+int avs_register_i2s_component(struct avs_dev *adev, const char *name, unsigned long port_mask,
+			       unsigned long *tdms)
 {
 	struct snd_soc_dai_driver *cpus, *dai;
 	const struct snd_soc_dai_ops *ops;
@@ -1539,7 +1539,7 @@ int avs_i2s_platform_register(struct avs_dev *adev, const char *name, unsigned l
 	}
 
 plat_register:
-	return avs_soc_component_register(adev->dev, name, &avs_component_driver, cpus, cpu_count);
+	return avs_register_component(adev->dev, name, &avs_component_driver, cpus, cpu_count);
 }
 
 /* HD-Audio CPU DAI template */
@@ -1764,8 +1764,7 @@ static struct snd_soc_component_driver avs_hda_component_driver = {
 	.topology_name_prefix	= "intel/avs",
 };
 
-int avs_hda_platform_register(struct avs_dev *adev, const char *name)
+int avs_register_hda_component(struct avs_dev *adev, const char *name)
 {
-	return avs_soc_component_register(adev->dev, name,
-					  &avs_hda_component_driver, NULL, 0);
+	return avs_register_component(adev->dev, name, &avs_hda_component_driver, NULL, 0);
 }
sound/soc/intel/avs/probes.c +1 -1
index 88c6d385c73c..c7b70006354a 100644
@@ -291,7 +291,7 @@ static const struct snd_soc_component_driver avs_probe_component_driver = {
 	.module_get_upon_open	= 1, /* increment refcount when a stream is opened */
 };
 
-int avs_probe_platform_register(struct avs_dev *adev, const char *name)
+int avs_register_probe_component(struct avs_dev *adev, const char *name)
 {
 	struct snd_soc_component *component;
 	int ret;
Signature · 1 line
2.25.1
maintainer
#5 lore raw
In reply to Cezary Rojewski
Quoted 9 lines · Cezary Rojewski

Set of patches that brings no new functionality but makes it easier to maintain and read the avs-driver code. There is one 'fix' among them - the third patch, described below.

First, debug-related code - mainly the data-probing feature - is mixed with non-debug PCM code. Separate it into debug.h and update the pcm.c file.

[...]

Applied to

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

Thanks!

[1/4] ASoC: Intel: avs: Separate debug symbols

      commit: 62dc545be11d956419a21724de3810930db20d43
[2/4] ASoC: Intel: avs: Drop pcm.h dependency for probes
      commit: df36e5c197f31a105b8c8a70f13ebdf3a4c019d5
[3/4] ASoC: Intel: avs: Do not share the name pointer between components
      commit: 4dee5c1cc439b0d5ef87f741518268ad6a95b23d
[4/4] ASoC: Intel: avs: Streamline register-component function names
      commit: 2a55135201d5e24b80b7624880ff42eafd8e320c

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