Skip to contentSkip to conversation

ASoC: core: Create new components in sane state

PATCH In review Cezary Rojewski 3 participants 16 messages Oct 7 – Oct 15

Subsystems (4)
lore
Share & tools
lore

Cezary Rojewski

author maintainer
#0 lore raw

cover ASoC: core: Create new components in sane state

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/[email protected]/

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(-)
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH 2/7 ASoC: core: Rename and export soc_component_add()

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 <[email protected]>
---
 include/sound/soc-component.h |  3 +++
 sound/soc/soc-core.c          | 11 ++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)
include/sound/soc-component.h +3 -0
index d51f71e2f334..f4d4f836269e 100644
@@ -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);
sound/soc/soc-core.c +6 -5
index c4de336ab408..93bc7fa32444 100644
@@ -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);
 
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/7 ASoC: core: Add component constructor

In reply to 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 <[email protected]>
---
 include/sound/soc-component.h |  2 ++
 sound/soc/soc-core.c          | 44 +++++++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 4 deletions(-)
include/sound/soc-component.h +2 -0
index 6c1acc984ecb..d51f71e2f334 100644
@@ -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);
sound/soc/soc-core.c +40 -4

57 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 3/7 ASoC: dmaengine: Switch to snd_snd_component_new()

In reply to 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 <[email protected]>
---
 sound/soc/soc-generic-dmaengine-pcm.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
sound/soc/soc-generic-dmaengine-pcm.c +9 -9
index f6206ecaf26f..d750dc44981d 100644
@@ -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;
 
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH 4/7 ASoC: topology-test: Switch to snd_snd_component_new()

In reply to 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 <[email protected]>
---
 sound/soc/soc-topology-test.c | 66 +++++++++++++++++------------------
 1 file changed, 33 insertions(+), 33 deletions(-)
sound/soc/soc-topology-test.c +33 -33
index 346a52d3006a..bcfb52061133 100644
@@ -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++) {
Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH 5/7 ASoC: Intel: catpt: Switch to snd_snd_component_new()

In reply to 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.

---
 sound/soc/intel/catpt/pcm.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
sound/soc/intel/catpt/pcm.c +4 -8
index bbba0d959ea2..ca42bc531c6b 100644
@@ -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));
 }
Signature · 1 line
2.34.1
author maintainer
#6 lore raw

PATCH 6/7 ASoC: Intel: avs: Switch to snd_snd_component_new()

In reply to 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.

---
 sound/soc/intel/avs/pcm.c    | 11 +++++------
 sound/soc/intel/avs/probes.c | 12 ++++--------
 2 files changed, 9 insertions(+), 14 deletions(-)
sound/soc/intel/avs/pcm.c +5 -6
index 2d7ced953fde..6dd2b938baaa 100644
@@ -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[] = {
sound/soc/intel/avs/probes.c +4 -8
index 2e4063b743ba..483e151dfd66 100644
@@ -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));
 }
Signature · 1 line
2.34.1
author maintainer
#7 lore raw

PATCH 7/7 ASoC: core: Remove unused component-register members

In reply to 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 <[email protected]>
---
 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(-)
include/sound/soc-component.h +0 -2
index f4d4f836269e..ac5e9412582e 100644
@@ -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);
include/sound/soc.h +1 -7
index 553bb7e2be98..08fdee15dba7 100644
@@ -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,
sound/soc/soc-component.c +0 -19
index 463ea227cac8..34efb270ce29 100644
@@ -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;
sound/soc/soc-core.c +5 -49

72 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw
In reply to Cezary Rojewski

Hi Cezary

Thank you for the patch

Quoted 25 lines

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.

Quoted 5 lines

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.

I would like to review this patch, but unfortunately I'm busy this week. Actually, I'm now posting cleanup snd_soc_component_xxx(), which has many steps, and is now under progress.

I will review your patch next week, but I guess some of them (= not all) are conflicts to mine...

Thank you for your help !!

Best regards
---
Kuninori Morimoto

maintainer
#9 lore raw
Quoted 6 lines · Kuninori Morimoto

I would like to review this patch, but unfortunately I'm busy this week. Actually, I'm now posting cleanup snd_soc_component_xxx(), which has many steps, and is now under progress.

I will review your patch next week, but I guess some of them (= not all) are conflicts to mine...

Ah, unfortunately I already applied it since we're in the last week before the merge window and it didn't get a reply - sorry about that.

author maintainer
#10 lore raw
Quoted 11 lines · Mark Brown
Quoted 6 lines · Kuninori Morimoto

I would like to review this patch, but unfortunately I'm busy this week. Actually, I'm now posting cleanup snd_soc_component_xxx(), which has many steps, and is now under progress.

I will review your patch next week, but I guess some of them (= not all) are conflicts to mine...

Ah, unfortunately I already applied it since we're in the last week before the merge window and it didn't get a reply - sorry about that.

I do not see it applied to the for-next.

Obviously I'd appreciate the merge as the gap mentioned in the cover-letter is there and the framework should sanitize the object before returning it.

At the same time, I'm here to help with any conflicts should any arise.

maintainer
#11 lore raw
Quoted 6 lines · Cezary Rojewski
Quoted 2 lines · Mark Brown

Ah, unfortunately I already applied it since we're in the last week before the merge window and it didn't get a reply - sorry about that.

I do not see it applied to the for-next.

There's a lag between me applying things and things making it through my CI (and often a stack of things in the pipeline so it's enormously painful when I have to pull things out).

maintainer
#15 lore raw
In reply to Cezary Rojewski
Quoted 11 lines · Cezary Rojewski

ASoC: core: Create new components in sane state

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.

[...]

Applied to

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

Thanks!

[1/7] ASoC: core: Add component constructor

      https://git.kernel.org/broonie/misc/c/0f2bec6921f0
[2/7] ASoC: core: Rename and export soc_component_add()
      https://git.kernel.org/broonie/misc/c/4e2db62172b5
[3/7] ASoC: dmaengine: Switch to snd_snd_component_new()
      https://git.kernel.org/broonie/misc/c/857469990ee1
[4/7] ASoC: topology-test: Switch to snd_snd_component_new()
      https://git.kernel.org/broonie/misc/c/c0e1ffec60ce
[5/7] ASoC: Intel: catpt: Switch to snd_snd_component_new()
      https://git.kernel.org/broonie/misc/c/6cb74a0741da
[6/7] ASoC: Intel: avs: Switch to snd_snd_component_new()
      https://git.kernel.org/broonie/misc/c/d7065004a33a
[7/7] ASoC: core: Remove unused component-register members
      https://git.kernel.org/broonie/misc/c/146caaa16f85

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

#12 lore raw
In reply to Cezary Rojewski

Hi Mark, Cezary

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

I will review your patch next week, but I guess some of them (= not all) are conflicts to mine...

Ah, unfortunately I already applied it since we're in the last week before the merge window and it didn't get a reply - sorry about that.

Quoted 7 lines

I do not see it applied to the for-next.

Obviously I'd appreciate the merge as the gap mentioned in the cover-letter is there and the framework should sanitize the object before returning it.

At the same time, I'm here to help with any conflicts should any arise.

It seems there was no big issue/conflicts, Thank you for your help. But 1 concern from my side is that the function naming

We would like to keep snd_soc_component_xxx() naming. New ASoC has similar functions, it is very confusable.

snd_soc_component_register()
snd_soc_register_component()

Both are for register function, and the diff is used parameter. So we would like to merge them by using _Generic() This part had conflict with my (not yet posted) patches.

I will post merge patch (by _Generic()) later.

Thank you for your help !!

Best regards
---
Kuninori Morimoto

author maintainer
#13 lore raw
Quoted 8 lines · Kuninori Morimoto
Quoted 1 line

At the same time, I'm here to help with any conflicts should any arise.

It seems there was no big issue/conflicts, Thank you for your help. But 1 concern from my side is that the function naming

We would like to keep snd_soc_component_xxx() naming. New ASoC has similar functions, it is very confusable.

Quoted 8 lines

snd_soc_component_register()
snd_soc_register_component()

Both are for register function, and the diff is used parameter. So we would like to merge them by using _Generic() This part had conflict with my (not yet posted) patches.

I will post merge patch (by _Generic()) later.

I disagree about the naming part. IMHO there should be a clear division between object-level and general-level functions.

In essence if something is found within object-level scope, it should be prefixed with the object' class name and have the object-ptr as a first argument e.g.:

1) snd_soc_component_register(struct snd_soc_component *component)

whereas for general-level functions where the framework does everything for the caller the arguments differ and so should the name:

2) snd_soc_register_component(<component does not start the list>)

If 2) is named in the same fashion as 1) then a user, especially ASoC newcomer assumes component-ptr always starts the list and gets surprised later. Again, in my opinion we should not mangle all the names together like if their arguments do not matter. Happy to hear more people voice their opinion about the subject.

Kind regards,
Czarek

#14 lore raw

Hi Cezary

Quoted 1 line
Quoted 1 line

We would like to keep snd_soc_component_xxx() naming.

(snip)

Quoted 2 lines

I disagree about the naming part. IMHO there should be a clear division between object-level and general-level functions.

Yeah, I agree.

I will update my branch patches which will be posted to ML

Thank you for your help !!

Best regards
---
Kuninori Morimoto