* [PATCH 0/7] ASoC: core: Create new components in sane state
@ 2026-10-07 13:33 Cezary Rojewski
2026-10-07 13:33 ` [PATCH 1/7] ASoC: core: Add component constructor Cezary Rojewski
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Cezary Rojewski @ 2026-10-07 13:33 UTC (permalink / raw)
To: broonie, linux-sound
Cc: tiwai, perex, amade, linux-kernel, kuninori.morimoto.gx, Cezary Rojewski
There is a gap between snd_soc_component_alloc() and
snd_soc_register_component(). A driver that obtains a component object
through snd_soc_component_alloc() receives an object in uninitialized
state. soc_component_initialize() is the function responsible for
bringing it into a sane one but it is not accessible by the framework
users. Example of the uninitialized members are the lists e.g.:
comp->dai_list.
The framework shall prevent manipulation of uninitialized components.
Introduce snd_soc_component_new() which acts as a constructor: allocates
and initializes the component object before returning it to the caller.
Given the quite recent discussion related to all things
component-register [1], decided to stick to the "register" wording and
renamed soc_component_add() to snd_soc_component_register(). With that,
register/unregister pattern is kept. At the same time, the update
brings a clear division between:
1) snd_soc_component_register(component..)
2) snd_soc_register_component(dev..)
A driver uses 1) when operating on pre-constructed component object
explicitly and 2) when they want the ASoC framework to do everything for
them.
Parameter "name" is added to the ctor parameter list as it is one of the
fields that is always initialized, see the 'if (!component->name)'
within soc_component_initialize(). Private data on the other hand is
not so opted out of including it. And thus snd_soc_component_set_priv()
remains intact.
[1]: https://lore.kernel.org/all/87y0f2rz8l.wl-kuninori.morimoto.gx@renesas.com/
Cezary Rojewski (7):
ASoC: core: Add component constructor
ASoC: core: Rename and export soc_component_add()
ASoC: dmaengine: Switch to snd_snd_component_new()
ASoC: topology-test: Switch to snd_snd_component_new()
ASoC: Intel: catpt: Switch to snd_snd_component_new()
ASoC: Intel: avs: Switch to snd_snd_component_new()
ASoC: core: Remove unused component-register members
include/sound/soc-component.h | 7 ++-
include/sound/soc.h | 8 +--
sound/soc/intel/avs/pcm.c | 11 ++--
sound/soc/intel/avs/probes.c | 12 ++---
sound/soc/intel/catpt/pcm.c | 12 ++---
sound/soc/soc-component.c | 19 -------
sound/soc/soc-core.c | 77 ++++++++++++---------------
sound/soc/soc-generic-dmaengine-pcm.c | 18 +++----
sound/soc/soc-topology-test.c | 66 +++++++++++------------
9 files changed, 96 insertions(+), 134 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/7] ASoC: core: Add component constructor
2026-10-07 13:33 [PATCH 0/7] ASoC: core: Create new components in sane state Cezary Rojewski
@ 2026-10-07 13:33 ` Cezary Rojewski
2026-10-07 13:33 ` [PATCH 2/7] ASoC: core: Rename and export soc_component_add() Cezary Rojewski
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Cezary Rojewski @ 2026-10-07 13:33 UTC (permalink / raw)
To: broonie, linux-sound
Cc: tiwai, perex, amade, linux-kernel, kuninori.morimoto.gx, Cezary Rojewski
There is a gap between snd_soc_component_alloc() and
snd_soc_register_component(). A driver that obtains a component object
through snd_soc_component_alloc() receives an object in uninitialized
state. soc_component_initialize() is the function responsible for
bringing it into a sane one but it is not accessible by the framework
users.
The framework shall prevent manipulation of uninitialized components.
Introduce snd_soc_component_new() which acts as a constructor: allocates
and initializes the component object before returning it to the caller.
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
include/sound/soc-component.h | 2 ++
sound/soc/soc-core.c | 44 +++++++++++++++++++++++++++++++----
2 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index 6c1acc984ecb..d51f71e2f334 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -292,6 +292,8 @@ static inline int snd_soc_component_cache_sync(
return regcache_sync(component->regmap);
}
+struct snd_soc_component *snd_soc_component_new(struct device *dev, const char *name,
+ const struct snd_soc_component_driver *driver);
struct snd_soc_component *snd_soc_component_alloc(struct device *dev);
void snd_soc_component_set_name(struct snd_soc_component *component, const char *name);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 06167a198591..c4de336ab408 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2589,6 +2589,42 @@ static int soc_component_initialize(struct snd_soc_component *component,
return 0;
}
+struct snd_soc_component *snd_soc_component_new(struct device *dev, const char *name,
+ const struct snd_soc_component_driver *driver)
+{
+ struct snd_soc_component *component;
+
+ component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
+ if (!component)
+ return ERR_PTR(-ENOMEM);
+
+ component->dapm = snd_soc_dapm_alloc(dev);
+ if (!component->dapm)
+ return ERR_PTR(-ENOMEM);
+
+ if (!name) {
+ name = snd_soc_fmt_single_name(dev, NULL);
+ if (!name) {
+ dev_err(dev, "ASoC: Failed to allocate name\n");
+ return ERR_PTR(-ENOMEM);
+ }
+ }
+
+ component->dev = dev;
+ component->name = name;
+ component->driver = driver;
+
+ INIT_LIST_HEAD(&component->dai_list);
+ INIT_LIST_HEAD(&component->dobj_list);
+ INIT_LIST_HEAD(&component->card_list);
+ INIT_LIST_HEAD(&component->list);
+ INIT_LIST_HEAD(&component->card_aux_list);
+ mutex_init(&component->io_mutex);
+
+ return component;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_new);
+
static int soc_component_add(struct snd_soc_component *component,
struct snd_soc_dai_driver *dai_drv,
int num_dai)
@@ -2653,11 +2689,11 @@ int snd_soc_register_component_d(struct device *dev,
{
struct snd_soc_component *component;
- component = snd_soc_component_alloc(dev);
- if (!component)
- return -ENOMEM;
+ component = snd_soc_component_new(dev, NULL, component_driver);
+ if (IS_ERR(component))
+ return PTR_ERR(component);
- return snd_soc_register_component_c(component, component_driver, dai_drv, num_dai);
+ return soc_component_add(component, dai_drv, num_dai);
}
EXPORT_SYMBOL_GPL(snd_soc_register_component_d);
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/7] ASoC: core: Rename and export soc_component_add()
2026-10-07 13:33 [PATCH 0/7] ASoC: core: Create new components in sane state Cezary Rojewski
2026-10-07 13:33 ` [PATCH 1/7] ASoC: core: Add component constructor Cezary Rojewski
@ 2026-10-07 13:33 ` Cezary Rojewski
2026-10-07 13:33 ` [PATCH 3/7] ASoC: dmaengine: Switch to snd_snd_component_new() Cezary Rojewski
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Cezary Rojewski @ 2026-10-07 13:33 UTC (permalink / raw)
To: broonie, linux-sound
Cc: tiwai, perex, amade, linux-kernel, kuninori.morimoto.gx, Cezary Rojewski
To keep the register/unregister pattern intact, rename to the function
before exporting it. This concludes the registration update, leaving the
following two options available to the callers:
1) snd_soc_component_register(component..)
2) snd_soc_register_component(dev..)
A driver uses 1) when attempting to register a pre-constructed
component object explicitly and 2) when they want the ASoC framework to
do the entire job for them.
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
include/sound/soc-component.h | 3 +++
sound/soc/soc-core.c | 11 ++++++-----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index d51f71e2f334..f4d4f836269e 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -294,6 +294,9 @@ static inline int snd_soc_component_cache_sync(
struct snd_soc_component *snd_soc_component_new(struct device *dev, const char *name,
const struct snd_soc_component_driver *driver);
+int snd_soc_component_register(struct snd_soc_component *component,
+ struct snd_soc_dai_driver *dai_drv,
+ int num_dai);
struct snd_soc_component *snd_soc_component_alloc(struct device *dev);
void snd_soc_component_set_name(struct snd_soc_component *component, const char *name);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index c4de336ab408..93bc7fa32444 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2625,9 +2625,9 @@ struct snd_soc_component *snd_soc_component_new(struct device *dev, const char *
}
EXPORT_SYMBOL_GPL(snd_soc_component_new);
-static int soc_component_add(struct snd_soc_component *component,
- struct snd_soc_dai_driver *dai_drv,
- int num_dai)
+int snd_soc_component_register(struct snd_soc_component *component,
+ struct snd_soc_dai_driver *dai_drv,
+ int num_dai)
{
struct snd_soc_card *card, *c;
int ret;
@@ -2666,6 +2666,7 @@ static int soc_component_add(struct snd_soc_component *component,
return ret;
}
+EXPORT_SYMBOL_GPL(snd_soc_component_register);
int snd_soc_register_component_c(struct snd_soc_component *component,
const struct snd_soc_component_driver *component_driver,
@@ -2678,7 +2679,7 @@ int snd_soc_register_component_c(struct snd_soc_component *component,
if (ret < 0)
return ret;
- return soc_component_add(component, dai_drv, num_dai);
+ return snd_soc_component_register(component, dai_drv, num_dai);
}
EXPORT_SYMBOL_GPL(snd_soc_register_component_c);
@@ -2693,7 +2694,7 @@ int snd_soc_register_component_d(struct device *dev,
if (IS_ERR(component))
return PTR_ERR(component);
- return soc_component_add(component, dai_drv, num_dai);
+ return snd_soc_component_register(component, dai_drv, num_dai);
}
EXPORT_SYMBOL_GPL(snd_soc_register_component_d);
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/7] ASoC: dmaengine: Switch to snd_snd_component_new()
2026-10-07 13:33 [PATCH 0/7] ASoC: core: Create new components in sane state Cezary Rojewski
2026-10-07 13:33 ` [PATCH 1/7] ASoC: core: Add component constructor Cezary Rojewski
2026-10-07 13:33 ` [PATCH 2/7] ASoC: core: Rename and export soc_component_add() Cezary Rojewski
@ 2026-10-07 13:33 ` Cezary Rojewski
2026-10-07 13:33 ` [PATCH 4/7] ASoC: topology-test: " Cezary Rojewski
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Cezary Rojewski @ 2026-10-07 13:33 UTC (permalink / raw)
To: broonie, linux-sound
Cc: tiwai, perex, amade, linux-kernel, kuninori.morimoto.gx, Cezary Rojewski
snd_soc_component_alloc() leaves the component object in uninitialized
state. Switch to the constructor function to retrieve and operate on
object in sane state.
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
sound/soc/soc-generic-dmaengine-pcm.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index f6206ecaf26f..d750dc44981d 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -454,10 +454,6 @@ int snd_dmaengine_pcm_register(struct device *dev,
struct dmaengine_pcm *pcm;
int ret;
- component = snd_soc_component_alloc(dev);
- if (!component)
- return -ENOMEM;
-
pcm = kzalloc_obj(*pcm);
if (!pcm)
return -ENOMEM;
@@ -467,10 +463,6 @@ int snd_dmaengine_pcm_register(struct device *dev,
pcm->config = config;
pcm->flags = flags;
- if (config->name)
- snd_soc_component_set_name(component, config->name);
- snd_soc_component_set_priv(component, pcm);
-
ret = dmaengine_pcm_request_chan_of(pcm, dev, config);
if (ret)
goto err_free_dma;
@@ -480,7 +472,15 @@ int snd_dmaengine_pcm_register(struct device *dev,
else
driver = &dmaengine_pcm_component;
- ret = snd_soc_register_component(component, driver, NULL, 0);
+ component = snd_soc_component_new(dev, config->name, driver);
+ if (IS_ERR(component)) {
+ ret = PTR_ERR(component);
+ goto err_free_dma;
+ }
+
+ snd_soc_component_set_priv(component, pcm);
+
+ ret = snd_soc_component_register(component, NULL, 0);
if (ret)
goto err_free_dma;
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/7] ASoC: topology-test: Switch to snd_snd_component_new()
2026-10-07 13:33 [PATCH 0/7] ASoC: core: Create new components in sane state Cezary Rojewski
` (2 preceding siblings ...)
2026-10-07 13:33 ` [PATCH 3/7] ASoC: dmaengine: Switch to snd_snd_component_new() Cezary Rojewski
@ 2026-10-07 13:33 ` Cezary Rojewski
2026-10-07 13:33 ` [PATCH 5/7] ASoC: Intel: catpt: " Cezary Rojewski
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Cezary Rojewski @ 2026-10-07 13:33 UTC (permalink / raw)
To: broonie, linux-sound
Cc: tiwai, perex, amade, linux-kernel, kuninori.morimoto.gx, Cezary Rojewski
snd_soc_component_alloc() leaves the component object in uninitialized
state. Switch to the constructor function to retrieve and operate on
object in sane state.
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
sound/soc/soc-topology-test.c | 66 +++++++++++++++++------------------
1 file changed, 33 insertions(+), 33 deletions(-)
diff --git a/sound/soc/soc-topology-test.c b/sound/soc/soc-topology-test.c
index 346a52d3006a..bcfb52061133 100644
--- a/sound/soc/soc-topology-test.c
+++ b/sound/soc/soc-topology-test.c
@@ -246,8 +246,8 @@ static void snd_soc_tplg_test_load_with_null_comp(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component_null_comp);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -256,7 +256,7 @@ static void snd_soc_tplg_test_load_with_null_comp(struct kunit *test)
if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
- ret = snd_soc_register_component(component, &test_component_null_comp, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
/* cleanup */
@@ -291,8 +291,8 @@ static void snd_soc_tplg_test_load_with_null_ops(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -301,7 +301,7 @@ static void snd_soc_tplg_test_load_with_null_ops(struct kunit *test)
if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
- ret = snd_soc_register_component(component, &test_component, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
/* cleanup */
@@ -355,8 +355,8 @@ static void snd_soc_tplg_test_load_with_null_fw(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component_null_fw);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -365,7 +365,7 @@ static void snd_soc_tplg_test_load_with_null_fw(struct kunit *test)
if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
- ret = snd_soc_register_component(component, &test_component_null_fw, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
/* cleanup */
@@ -406,8 +406,8 @@ static void snd_soc_tplg_test_load_empty_tplg(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -416,7 +416,7 @@ static void snd_soc_tplg_test_load_empty_tplg(struct kunit *test)
if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
- ret = snd_soc_register_component(component, &test_component, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
/* cleanup */
@@ -464,8 +464,8 @@ static void snd_soc_tplg_test_load_empty_tplg_bad_magic(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -474,7 +474,7 @@ static void snd_soc_tplg_test_load_empty_tplg_bad_magic(struct kunit *test)
if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
- ret = snd_soc_register_component(component, &test_component, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
/* cleanup */
@@ -522,8 +522,8 @@ static void snd_soc_tplg_test_load_empty_tplg_bad_abi(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -532,7 +532,7 @@ static void snd_soc_tplg_test_load_empty_tplg_bad_abi(struct kunit *test)
if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
- ret = snd_soc_register_component(component, &test_component, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
/* cleanup */
@@ -580,8 +580,8 @@ static void snd_soc_tplg_test_load_empty_tplg_bad_size(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -590,7 +590,7 @@ static void snd_soc_tplg_test_load_empty_tplg_bad_size(struct kunit *test)
if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
- ret = snd_soc_register_component(component, &test_component, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
/* cleanup */
@@ -639,8 +639,8 @@ static void snd_soc_tplg_test_load_empty_tplg_bad_payload_size(struct kunit *tes
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -649,7 +649,7 @@ static void snd_soc_tplg_test_load_empty_tplg_bad_payload_size(struct kunit *tes
if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
- ret = snd_soc_register_component(component, &test_component, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
/* cleanup */
@@ -690,8 +690,8 @@ static void snd_soc_tplg_test_load_pcm_tplg(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -700,7 +700,7 @@ static void snd_soc_tplg_test_load_pcm_tplg(struct kunit *test)
if (ret != 0 && ret != -EPROBE_DEFER)
KUNIT_FAIL(test, "Failed to register card");
- ret = snd_soc_register_component(component, &test_component, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
snd_soc_unregister_component(test_dev);
@@ -743,8 +743,8 @@ static void snd_soc_tplg_test_load_pcm_tplg_reload_comp(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
@@ -755,7 +755,7 @@ static void snd_soc_tplg_test_load_pcm_tplg_reload_comp(struct kunit *test)
for (i = 0; i < 100; i++) {
- ret = snd_soc_register_component(component, &test_component, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
snd_soc_unregister_component(test_dev);
@@ -799,13 +799,13 @@ static void snd_soc_tplg_test_load_pcm_tplg_reload_card(struct kunit *test)
kunit_comp->card.num_links = ARRAY_SIZE(kunit_dai_links);
kunit_comp->card.fully_routed = true;
- component = snd_soc_component_alloc(test_dev);
- KUNIT_ASSERT_NOT_NULL(test, component);
+ component = snd_soc_component_new(test_dev, NULL, &test_component);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, component);
snd_soc_component_set_priv(component, kunit_comp);
/* run test */
- ret = snd_soc_register_component(component, &test_component, NULL, 0);
+ ret = snd_soc_component_register(component, NULL, 0);
KUNIT_EXPECT_EQ(test, 0, ret);
for (i = 0; i < 100; i++) {
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/7] ASoC: Intel: catpt: Switch to snd_snd_component_new()
2026-10-07 13:33 [PATCH 0/7] ASoC: core: Create new components in sane state Cezary Rojewski
` (3 preceding siblings ...)
2026-10-07 13:33 ` [PATCH 4/7] ASoC: topology-test: " Cezary Rojewski
@ 2026-10-07 13:33 ` Cezary Rojewski
2026-10-07 13:33 ` [PATCH 6/7] ASoC: Intel: avs: " Cezary Rojewski
2026-10-07 13:33 ` [PATCH 7/7] ASoC: core: Remove unused component-register members Cezary Rojewski
6 siblings, 0 replies; 8+ messages in thread
From: Cezary Rojewski @ 2026-10-07 13:33 UTC (permalink / raw)
To: broonie, linux-sound
Cc: tiwai, perex, amade, linux-kernel, kuninori.morimoto.gx, Cezary Rojewski
snd_soc_component_alloc() leaves the component object in uninitialized
state. Switch to the constructor function to retrieve and operate on
object in sane state.
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
sound/soc/intel/catpt/pcm.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/sound/soc/intel/catpt/pcm.c b/sound/soc/intel/catpt/pcm.c
index bbba0d959ea2..ca42bc531c6b 100644
--- a/sound/soc/intel/catpt/pcm.c
+++ b/sound/soc/intel/catpt/pcm.c
@@ -1073,13 +1073,9 @@ int catpt_register_plat_component(struct catpt_dev *cdev)
{
struct snd_soc_component *component;
- component = snd_soc_component_alloc(cdev->dev);
- if (!component)
- return -ENOMEM;
+ component = snd_soc_component_new(cdev->dev, catpt_comp_driver.name, &catpt_comp_driver);
+ if (IS_ERR(component))
+ return PTR_ERR(component);
- snd_soc_component_set_name(component, catpt_comp_driver.name);
-
- return snd_soc_register_component(component,
- &catpt_comp_driver,
- dai_drivers, ARRAY_SIZE(dai_drivers));
+ return snd_soc_component_register(component, dai_drivers, ARRAY_SIZE(dai_drivers));
}
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 6/7] ASoC: Intel: avs: Switch to snd_snd_component_new()
2026-10-07 13:33 [PATCH 0/7] ASoC: core: Create new components in sane state Cezary Rojewski
` (4 preceding siblings ...)
2026-10-07 13:33 ` [PATCH 5/7] ASoC: Intel: catpt: " Cezary Rojewski
@ 2026-10-07 13:33 ` Cezary Rojewski
2026-10-07 13:33 ` [PATCH 7/7] ASoC: core: Remove unused component-register members Cezary Rojewski
6 siblings, 0 replies; 8+ messages in thread
From: Cezary Rojewski @ 2026-10-07 13:33 UTC (permalink / raw)
To: broonie, linux-sound
Cc: tiwai, perex, amade, linux-kernel, kuninori.morimoto.gx, Cezary Rojewski
snd_soc_component_alloc() leaves the component object in uninitialized
state. Switch to the constructor function to retrieve and operate on
object in sane state.
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
sound/soc/intel/avs/pcm.c | 11 +++++------
sound/soc/intel/avs/probes.c | 12 ++++--------
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/sound/soc/intel/avs/pcm.c b/sound/soc/intel/avs/pcm.c
index 2d7ced953fde..6dd2b938baaa 100644
--- a/sound/soc/intel/avs/pcm.c
+++ b/sound/soc/intel/avs/pcm.c
@@ -1399,10 +1399,6 @@ int avs_register_component(struct device *dev, const char *name,
if (!acomp)
return -ENOMEM;
- acomp->base = snd_soc_component_alloc(dev);
- if (!acomp->base)
- return -ENOMEM;
-
comp_name = devm_kstrdup(dev, name, GFP_KERNEL);
if (!comp_name)
return -ENOMEM;
@@ -1411,10 +1407,13 @@ int avs_register_component(struct device *dev, const char *name,
drv->use_dai_pcm_id = !obsolete_card_names;
- snd_soc_component_set_name(acomp->base, comp_name);
+ acomp->base = snd_soc_component_new(dev, comp_name, drv);
+ if (IS_ERR(acomp->base))
+ return PTR_ERR(acomp->base);
+
snd_soc_component_set_priv(acomp->base, acomp);
- return snd_soc_register_component(acomp->base, drv, cpu_dais, num_cpu_dais);
+ return snd_soc_component_register(acomp->base, cpu_dais, num_cpu_dais);
}
static struct snd_soc_dai_driver dmic_cpu_dais[] = {
diff --git a/sound/soc/intel/avs/probes.c b/sound/soc/intel/avs/probes.c
index 2e4063b743ba..483e151dfd66 100644
--- a/sound/soc/intel/avs/probes.c
+++ b/sound/soc/intel/avs/probes.c
@@ -298,17 +298,13 @@ int avs_register_probe_component(struct avs_dev *adev, const char *name)
struct snd_soc_component *component;
const char *comp_name;
- component = snd_soc_component_alloc(adev->dev);
- if (!component)
- return -ENOMEM;
-
comp_name = devm_kstrdup(adev->dev, name, GFP_KERNEL);
if (!comp_name)
return -ENOMEM;
- snd_soc_component_set_name(component, comp_name);
+ component = snd_soc_component_new(adev->dev, comp_name, &avs_probe_component_driver);
+ if (IS_ERR(component))
+ return PTR_ERR(component);
- return snd_soc_register_component(component,
- &avs_probe_component_driver,
- probe_cpu_dais, ARRAY_SIZE(probe_cpu_dais));
+ return snd_soc_component_register(component, probe_cpu_dais, ARRAY_SIZE(probe_cpu_dais));
}
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 7/7] ASoC: core: Remove unused component-register members
2026-10-07 13:33 [PATCH 0/7] ASoC: core: Create new components in sane state Cezary Rojewski
` (5 preceding siblings ...)
2026-10-07 13:33 ` [PATCH 6/7] ASoC: Intel: avs: " Cezary Rojewski
@ 2026-10-07 13:33 ` Cezary Rojewski
6 siblings, 0 replies; 8+ messages in thread
From: Cezary Rojewski @ 2026-10-07 13:33 UTC (permalink / raw)
To: broonie, linux-sound
Cc: tiwai, perex, amade, linux-kernel, kuninori.morimoto.gx, Cezary Rojewski
With the new component constructor, functions snd_soc_component_alloc(),
snd_soc_component_set_name() and soc_component_initialize() become
unused. Remove them and drop the generic macro as there is only one
snd_soc_register_component() function.
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
include/sound/soc-component.h | 2 --
include/sound/soc.h | 8 +-----
sound/soc/soc-component.c | 19 ------------
sound/soc/soc-core.c | 54 ++++-------------------------------
4 files changed, 6 insertions(+), 77 deletions(-)
diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index f4d4f836269e..ac5e9412582e 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -297,9 +297,7 @@ struct snd_soc_component *snd_soc_component_new(struct device *dev, const char *
int snd_soc_component_register(struct snd_soc_component *component,
struct snd_soc_dai_driver *dai_drv,
int num_dai);
-struct snd_soc_component *snd_soc_component_alloc(struct device *dev);
-void snd_soc_component_set_name(struct snd_soc_component *component, const char *name);
const char *snd_soc_component_name(struct snd_soc_component *component);
void snd_soc_component_set_priv(struct snd_soc_component *component, void *priv);
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 553bb7e2be98..08fdee15dba7 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -447,15 +447,9 @@ static inline int snd_soc_resume(struct device *dev)
}
#endif
int snd_soc_poweroff(struct device *dev);
-int snd_soc_register_component_c(struct snd_soc_component *component,
- const struct snd_soc_component_driver *component_driver,
- struct snd_soc_dai_driver *dai_drv, int num_dai);
-int snd_soc_register_component_d(struct device *dev,
+int snd_soc_register_component(struct device *dev,
const struct snd_soc_component_driver *component_driver,
struct snd_soc_dai_driver *dai_drv, int num_dai);
-#define snd_soc_register_component(x, ...) _Generic((x), \
-struct device * : snd_soc_register_component_d, \
-struct snd_soc_component * : snd_soc_register_component_c)(x, __VA_ARGS__)
int devm_snd_soc_register_component(struct device *dev,
const struct snd_soc_component_driver *component_driver,
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index 463ea227cac8..34efb270ce29 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -29,25 +29,6 @@ static inline int _soc_component_ret_reg_rw(struct snd_soc_component *component,
func, component->name, reg);
}
-struct snd_soc_component *snd_soc_component_alloc(struct device *dev)
-{
- struct snd_soc_component *component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
-
- if (!component)
- return NULL;
-
- component->dev = dev;
-
- return component;
-}
-EXPORT_SYMBOL_GPL(snd_soc_component_alloc);
-
-void snd_soc_component_set_name(struct snd_soc_component *component, const char *name)
-{
- component->name = name;
-}
-EXPORT_SYMBOL_GPL(snd_soc_component_set_name);
-
const char *snd_soc_component_name(struct snd_soc_component *component)
{
return component->name;
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 93bc7fa32444..69181cc0258b 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2560,35 +2560,6 @@ static void snd_soc_del_component_unlocked(struct snd_soc_component *component)
list_del(&component->list);
}
-static int soc_component_initialize(struct snd_soc_component *component,
- const struct snd_soc_component_driver *driver)
-{
- struct device *dev = component->dev;
-
- component->dapm = snd_soc_dapm_alloc(dev);
- if (!component->dapm)
- return -ENOMEM;
-
- INIT_LIST_HEAD(&component->dai_list);
- INIT_LIST_HEAD(&component->dobj_list);
- INIT_LIST_HEAD(&component->card_list);
- INIT_LIST_HEAD(&component->list);
- INIT_LIST_HEAD(&component->card_aux_list);
- mutex_init(&component->io_mutex);
-
- if (!component->name) {
- component->name = snd_soc_fmt_single_name(dev, NULL);
- if (!component->name) {
- dev_err(dev, "ASoC: Failed to allocate name\n");
- return -ENOMEM;
- }
- }
-
- component->driver = driver;
-
- return 0;
-}
-
struct snd_soc_component *snd_soc_component_new(struct device *dev, const char *name,
const struct snd_soc_component_driver *driver)
{
@@ -2668,25 +2639,10 @@ int snd_soc_component_register(struct snd_soc_component *component,
}
EXPORT_SYMBOL_GPL(snd_soc_component_register);
-int snd_soc_register_component_c(struct snd_soc_component *component,
- const struct snd_soc_component_driver *component_driver,
- struct snd_soc_dai_driver *dai_drv,
- int num_dai)
-{
- int ret;
-
- ret = soc_component_initialize(component, component_driver);
- if (ret < 0)
- return ret;
-
- return snd_soc_component_register(component, dai_drv, num_dai);
-}
-EXPORT_SYMBOL_GPL(snd_soc_register_component_c);
-
-int snd_soc_register_component_d(struct device *dev,
- const struct snd_soc_component_driver *component_driver,
- struct snd_soc_dai_driver *dai_drv,
- int num_dai)
+int snd_soc_register_component(struct device *dev,
+ const struct snd_soc_component_driver *component_driver,
+ struct snd_soc_dai_driver *dai_drv,
+ int num_dai)
{
struct snd_soc_component *component;
@@ -2696,7 +2652,7 @@ int snd_soc_register_component_d(struct device *dev,
return snd_soc_component_register(component, dai_drv, num_dai);
}
-EXPORT_SYMBOL_GPL(snd_soc_register_component_d);
+EXPORT_SYMBOL_GPL(snd_soc_register_component);
/**
* snd_soc_unregister_component_by_driver - Unregister component using a given driver
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-10-07 13:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-07 13:33 [PATCH 0/7] ASoC: core: Create new components in sane state Cezary Rojewski
2026-10-07 13:33 ` [PATCH 1/7] ASoC: core: Add component constructor Cezary Rojewski
2026-10-07 13:33 ` [PATCH 2/7] ASoC: core: Rename and export soc_component_add() Cezary Rojewski
2026-10-07 13:33 ` [PATCH 3/7] ASoC: dmaengine: Switch to snd_snd_component_new() Cezary Rojewski
2026-10-07 13:33 ` [PATCH 4/7] ASoC: topology-test: " Cezary Rojewski
2026-10-07 13:33 ` [PATCH 5/7] ASoC: Intel: catpt: " Cezary Rojewski
2026-10-07 13:33 ` [PATCH 6/7] ASoC: Intel: avs: " Cezary Rojewski
2026-10-07 13:33 ` [PATCH 7/7] ASoC: core: Remove unused component-register members Cezary Rojewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®