alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3
@ 2019-09-12  4:37 Kuninori Morimoto
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 01/14] ASoC: soc-core: move soc_free_pcm_runtime() Kuninori Morimoto
                   ` (13 more replies)
  0 siblings, 14 replies; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:37 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


Hi Mark

These are v2 of soc-core.c cleanup (maybe) step 3.
These try to clenaup around kmalloc/kfree related code.
Basically these do nothing from technical point of view.
I added +1 extra patch as [00/14]

Kuninori Morimoto (14):
  ASoC: soc-core: move soc_free_pcm_runtime()
  ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime()
  ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime()
  ASoC: soc-core: create rtd->codec_dais first
  ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init()
  ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free()
  ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order
  ASoC: soc-core: remove snd_soc_rtdcom_del_all()
  ASoC: soc-core: use devm_kzalloc() for rtd
  ASoC: soc-core: remove soc_remove_dai_links()
  ASoC: soc-core: add soc_setup_card_name()
  ASoC: soc-core: use devm_xxx for component related resource
  ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()
  ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume()

 include/sound/soc.h  |   1 -
 sound/soc/soc-core.c | 287 ++++++++++++++++++++++++++-------------------------
 sound/soc/soc-ops.c  |  11 +-
 3 files changed, 151 insertions(+), 148 deletions(-)

-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 01/14] ASoC: soc-core: move soc_free_pcm_runtime()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
@ 2019-09-12  4:38 ` Kuninori Morimoto
  2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: move soc_free_pcm_runtime()" to the asoc tree Mark Brown
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 02/14] ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime() Kuninori Morimoto
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:38 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

This patch moves soc_free_pcm_runtime() next to soc_new_pcm_runtime().
This is prepare for soc_xxx_pcm_runtime() cleanup.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- no change

 sound/soc/soc-core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 35f48e9..2aa5bc7 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -355,6 +355,13 @@ EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
 
 static const struct snd_soc_ops null_snd_soc_ops;
 
+static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
+{
+	kfree(rtd->codec_dais);
+	snd_soc_rtdcom_del_all(rtd);
+	kfree(rtd);
+}
+
 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
 {
@@ -381,13 +388,6 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	return rtd;
 }
 
-static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
-{
-	kfree(rtd->codec_dais);
-	snd_soc_rtdcom_del_all(rtd);
-	kfree(rtd);
-}
-
 static void soc_add_pcm_runtime(struct snd_soc_card *card,
 		struct snd_soc_pcm_runtime *rtd)
 {
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 02/14] ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 01/14] ASoC: soc-core: move soc_free_pcm_runtime() Kuninori Morimoto
@ 2019-09-12  4:38 ` Kuninori Morimoto
  2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime()" to the asoc tree Mark Brown
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 03/14] ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime() Kuninori Morimoto
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:38 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

We have soc_new_pcm_runtime() which allocs rtd and its related memory,
and     soc_add_pcm_runtime() which connects rtd to card.

But we don't need to separate these, we can alloc and connect rtd
in the same time.

Current implementation is just makes code complex.
This patch merges these into one.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- no change

 sound/soc/soc-core.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 2aa5bc7..4e93d2f 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -385,16 +385,12 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 		return NULL;
 	}
 
-	return rtd;
-}
-
-static void soc_add_pcm_runtime(struct snd_soc_card *card,
-		struct snd_soc_pcm_runtime *rtd)
-{
 	/* see for_each_card_rtds */
 	list_add_tail(&rtd->list, &card->rtd_list);
 	rtd->num = card->num_rtd;
 	card->num_rtd++;
+
+	return rtd;
 }
 
 static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
@@ -930,7 +926,6 @@ static int soc_bind_dai_link(struct snd_soc_card *card,
 		}
 	}
 
-	soc_add_pcm_runtime(card, rtd);
 	return 0;
 
 _err_defer:
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 03/14] ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 01/14] ASoC: soc-core: move soc_free_pcm_runtime() Kuninori Morimoto
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 02/14] ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime() Kuninori Morimoto
@ 2019-09-12  4:38 ` Kuninori Morimoto
  2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime()" to the asoc tree Mark Brown
  2019-09-12  4:39 ` [alsa-devel] [PATCH v2 04/14] ASoC: soc-core: create rtd->codec_dais first Kuninori Morimoto
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:38 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Current ALSA SoC is calling list_del(&rtd->list) at (1)

	static void soc_remove_pcm_runtimes(...)
	{
		...
		for_each_card_rtds_safe(card, rtd, _rtd) {
(1)			list_del(&rtd->list);
(2)			soc_free_pcm_runtime(rtd);
		}
		...
	}

But, we will call soc_free_pcm_runtime() after that (2).
&rtd->list is         connected at soc_new_pcm_runtime(),
Thus, it should be disconnected at soc_free_pcm_runtime().

This patch calls list_del(&rtd->list) at soc_free_pcm_runtime().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- no change

 sound/soc/soc-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4e93d2f..44e1bff 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -359,6 +359,7 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 {
 	kfree(rtd->codec_dais);
 	snd_soc_rtdcom_del_all(rtd);
+	list_del(&rtd->list);
 	kfree(rtd);
 }
 
@@ -397,10 +398,8 @@ static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
 {
 	struct snd_soc_pcm_runtime *rtd, *_rtd;
 
-	for_each_card_rtds_safe(card, rtd, _rtd) {
-		list_del(&rtd->list);
+	for_each_card_rtds_safe(card, rtd, _rtd)
 		soc_free_pcm_runtime(rtd);
-	}
 
 	card->num_rtd = 0;
 }
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 04/14] ASoC: soc-core: create rtd->codec_dais first
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (2 preceding siblings ...)
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 03/14] ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime() Kuninori Morimoto
@ 2019-09-12  4:39 ` Kuninori Morimoto
  2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: create rtd->codec_dais first" to the asoc tree Mark Brown
  2019-09-12  4:40 ` [alsa-devel] [PATCH v2 05/14] ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init() Kuninori Morimoto
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:39 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

soc_new_pcm_runtime() allocs rtd and rtd->codec_dais.
This patch allocs both first, and setup these after that.
This is prepare for soc_new_pcm_runtime() cleanup.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- new patch
	- [05/14] will be more readable

 sound/soc/soc-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 44e1bff..fe6cafd 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -372,12 +372,6 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	if (!rtd)
 		return NULL;
 
-	INIT_LIST_HEAD(&rtd->component_list);
-	rtd->card = card;
-	rtd->dai_link = dai_link;
-	if (!rtd->dai_link->ops)
-		rtd->dai_link->ops = &null_snd_soc_ops;
-
 	rtd->codec_dais = kcalloc(dai_link->num_codecs,
 					sizeof(struct snd_soc_dai *),
 					GFP_KERNEL);
@@ -386,6 +380,12 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 		return NULL;
 	}
 
+	INIT_LIST_HEAD(&rtd->component_list);
+	rtd->card = card;
+	rtd->dai_link = dai_link;
+	if (!rtd->dai_link->ops)
+		rtd->dai_link->ops = &null_snd_soc_ops;
+
 	/* see for_each_card_rtds */
 	list_add_tail(&rtd->list, &card->rtd_list);
 	rtd->num = card->num_rtd;
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 05/14] ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (3 preceding siblings ...)
  2019-09-12  4:39 ` [alsa-devel] [PATCH v2 04/14] ASoC: soc-core: create rtd->codec_dais first Kuninori Morimoto
@ 2019-09-12  4:40 ` Kuninori Morimoto
  2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init()" to the asoc tree Mark Brown
  2019-09-12  4:41 ` [alsa-devel] [PATCH v2 06/14] ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free() Kuninori Morimoto
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:40 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

"rtd"      is handled by soc_xxx_pcm_runtime(), and
"rtd->dev" is handled by soc_rtd_xxx().

There is no reason to separate these, and it makes code complex.
We can create these in the same time.

This patch merges soc_rtd_init() into soc_new_pcm_runtime().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- separated into [04/14] and [05/14]

 sound/soc/soc-core.c | 95 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 53 insertions(+), 42 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index fe6cafd..b550fa9 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -355,8 +355,17 @@ EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
 
 static const struct snd_soc_ops null_snd_soc_ops;
 
+static void soc_release_rtd_dev(struct device *dev)
+{
+	/* "dev" means "rtd->dev" */
+	kfree(dev);
+}
+
 static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 {
+	if (!rtd)
+		return;
+
 	kfree(rtd->codec_dais);
 	snd_soc_rtdcom_del_all(rtd);
 	list_del(&rtd->list);
@@ -367,20 +376,54 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
 {
 	struct snd_soc_pcm_runtime *rtd;
+	int ret;
 
+	/*
+	 * for rtd
+	 */
 	rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
 	if (!rtd)
-		return NULL;
+		goto free_rtd;
 
+	/*
+	 * for rtd->codec_dais
+	 */
 	rtd->codec_dais = kcalloc(dai_link->num_codecs,
 					sizeof(struct snd_soc_dai *),
 					GFP_KERNEL);
-	if (!rtd->codec_dais) {
-		kfree(rtd);
-		return NULL;
+	if (!rtd->codec_dais)
+		goto free_rtd;
+
+	/*
+	 * for rtd->dev
+	 */
+	rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
+	if (!rtd->dev)
+		goto free_rtd;
+
+	rtd->dev->parent = card->dev;
+	rtd->dev->release = soc_release_rtd_dev;
+	rtd->dev->groups = soc_dev_attr_groups;
+
+	dev_set_name(rtd->dev, "%s", dai_link->name);
+	dev_set_drvdata(rtd->dev, rtd);
+
+	ret = device_register(rtd->dev);
+	if (ret < 0) {
+		put_device(rtd->dev); /* soc_release_rtd_dev */
+		rtd->dev = NULL;
+		goto free_rtd;
 	}
 
+	/*
+	 * rtd remaining settings
+	 */
 	INIT_LIST_HEAD(&rtd->component_list);
+	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
+	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
+	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
+	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
+
 	rtd->card = card;
 	rtd->dai_link = dai_link;
 	if (!rtd->dai_link->ops)
@@ -391,7 +434,13 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	rtd->num = card->num_rtd;
 	card->num_rtd++;
 
+	rtd->dev_registered = 1;
+
 	return rtd;
+
+free_rtd:
+	soc_free_pcm_runtime(rtd);
+	return NULL;
 }
 
 static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
@@ -1420,40 +1469,6 @@ static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd)
 	}
 }
 
-static void soc_rtd_release(struct device *dev)
-{
-	kfree(dev);
-}
-
-static int soc_rtd_init(struct snd_soc_pcm_runtime *rtd, const char *name)
-{
-	int ret = 0;
-
-	/* register the rtd device */
-	rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
-	if (!rtd->dev)
-		return -ENOMEM;
-	rtd->dev->parent = rtd->card->dev;
-	rtd->dev->release = soc_rtd_release;
-	rtd->dev->groups = soc_dev_attr_groups;
-	dev_set_name(rtd->dev, "%s", name);
-	dev_set_drvdata(rtd->dev, rtd);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
-	ret = device_register(rtd->dev);
-	if (ret < 0) {
-		/* calling put_device() here to free the rtd->dev */
-		put_device(rtd->dev);
-		dev_err(rtd->card->dev,
-			"ASoC: failed to register runtime device: %d\n", ret);
-		return ret;
-	}
-	rtd->dev_registered = 1;
-	return 0;
-}
-
 static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais,
 				struct snd_soc_pcm_runtime *rtd)
 {
@@ -1503,10 +1518,6 @@ static int soc_link_init(struct snd_soc_card *card,
 			return ret;
 	}
 
-	ret = soc_rtd_init(rtd, dai_link->name);
-	if (ret)
-		return ret;
-
 	/* add DPCM sysfs entries */
 	soc_dpcm_debugfs_add(rtd);
 
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 06/14] ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (4 preceding siblings ...)
  2019-09-12  4:40 ` [alsa-devel] [PATCH v2 05/14] ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init() Kuninori Morimoto
@ 2019-09-12  4:41 ` Kuninori Morimoto
  2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free()" to the asoc tree Mark Brown
  2019-09-12  4:42 ` [alsa-devel] [PATCH v2 07/14] ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order Kuninori Morimoto
                   ` (7 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:41 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

"rtd"      is handled by soc_xxx_pcm_runtime(), and
"rtd->dev" is handled by soc_rtd_xxx().

There is no reason to separate these, and it makes code complex.
We can free these in the same time.

Here soc_rtd_free() (A) which frees rtd->dev is called from
soc_remove_link_dais() many times (1).
Then, it is using dev_registered flags to avoid multi kfree() (2).
This is no longer needed if we can merge these functions.

	static void soc_remove_link_dais(...)
	{
		...
(1)		for_each_comp_order(order) {
(1)			for_each_card_rtds(card, rtd) {

(A)				soc_rtd_free(rtd);
				...
			}
		}
	}

(A)	static void soc_rtd_free(...)
	{
(2)		if (rtd->dev_registered) {
			/* we don't need to call kfree() for rtd->dev */
			device_unregister(rtd->dev);
(2)			rtd->dev_registered = 0;
		}
	}

This patch merges soc_rtd_free() into soc_free_pcm_runtime().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- keep comment for rtd->dev
	  /* we don't need to call kfree() for rtd->dev */

 include/sound/soc.h  |  1 -
 sound/soc/soc-core.c | 24 ++++++++----------------
 2 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index f264c65..d93cb46 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1148,7 +1148,6 @@ struct snd_soc_pcm_runtime {
 	struct list_head component_list; /* list of connected components */
 
 	/* bit field */
-	unsigned int dev_registered:1;
 	unsigned int pop_wait:1;
 	unsigned int fe_compr:1; /* for Dynamic PCM */
 };
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index b550fa9..f34d3f9 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -369,6 +369,14 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 	kfree(rtd->codec_dais);
 	snd_soc_rtdcom_del_all(rtd);
 	list_del(&rtd->list);
+
+	/*
+	 * we don't need to call kfree() for rtd->dev
+	 * see
+	 *	soc_release_rtd_dev()
+	 */
+	if (rtd->dev)
+		device_unregister(rtd->dev);
 	kfree(rtd);
 }
 
@@ -434,8 +442,6 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	rtd->num = card->num_rtd;
 	card->num_rtd++;
 
-	rtd->dev_registered = 1;
-
 	return rtd;
 
 free_rtd:
@@ -1169,7 +1175,6 @@ static int soc_probe_dai(struct snd_soc_dai *dai, int order)
 	return 0;
 }
 
-static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd); /* remove me */
 static void soc_remove_link_dais(struct snd_soc_card *card)
 {
 	int i;
@@ -1179,10 +1184,6 @@ static void soc_remove_link_dais(struct snd_soc_card *card)
 
 	for_each_comp_order(order) {
 		for_each_card_rtds(card, rtd) {
-
-			/* finalize rtd device */
-			soc_rtd_free(rtd);
-
 			/* remove the CODEC DAI */
 			for_each_rtd_codec_dai(rtd, i, codec_dai)
 				soc_remove_dai(codec_dai, order);
@@ -1460,15 +1461,6 @@ void snd_soc_remove_dai_link(struct snd_soc_card *card,
 }
 EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link);
 
-static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd)
-{
-	if (rtd->dev_registered) {
-		/* we don't need to call kfree() for rtd->dev */
-		device_unregister(rtd->dev);
-		rtd->dev_registered = 0;
-	}
-}
-
 static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais,
 				struct snd_soc_pcm_runtime *rtd)
 {
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 07/14] ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (5 preceding siblings ...)
  2019-09-12  4:41 ` [alsa-devel] [PATCH v2 06/14] ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free() Kuninori Morimoto
@ 2019-09-12  4:42 ` Kuninori Morimoto
  2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order" to the asoc tree Mark Brown
  2019-09-12  4:42 ` [alsa-devel] [PATCH v2 08/14] ASoC: soc-core: remove snd_soc_rtdcom_del_all() Kuninori Morimoto
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:42 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

This patch allocs dev first at soc_new_pcm_runtime().
This is prepare for rtd->dev, rtd->codec_dais alloc cleanup

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- add new comment for rtd->dev
	- call device_unregister() without if check
	  (it done at [09/14] in v1)

 sound/soc/soc-core.c | 55 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index f34d3f9..0ffa780 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -125,6 +125,9 @@ static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
 	struct device *dev = kobj_to_dev(kobj);
 	struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
 
+	if (!rtd)
+		return 0;
+
 	if (attr == &dev_attr_pmdown_time.attr)
 		return attr->mode; /* always visible */
 	return rtd->num_codecs ? attr->mode : 0; /* enabled only with codec */
@@ -374,9 +377,13 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 	 * we don't need to call kfree() for rtd->dev
 	 * see
 	 *	soc_release_rtd_dev()
+	 *
+	 * We don't need rtd->dev NULL check, because
+	 * it is alloced *before* rtd.
+	 * see
+	 *	soc_new_pcm_runtime()
 	 */
-	if (rtd->dev)
-		device_unregister(rtd->dev);
+	device_unregister(rtd->dev);
 	kfree(rtd);
 }
 
@@ -384,15 +391,38 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
 {
 	struct snd_soc_pcm_runtime *rtd;
+	struct device *dev;
 	int ret;
 
 	/*
+	 * for rtd->dev
+	 */
+	dev = kzalloc(sizeof(struct device), GFP_KERNEL);
+	if (!dev)
+		return NULL;
+
+	dev->parent	= card->dev;
+	dev->release	= soc_release_rtd_dev;
+	dev->groups	= soc_dev_attr_groups;
+
+	dev_set_name(dev, "%s", dai_link->name);
+
+	ret = device_register(dev);
+	if (ret < 0) {
+		put_device(dev); /* soc_release_rtd_dev */
+		return NULL;
+	}
+
+	/*
 	 * for rtd
 	 */
 	rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
 	if (!rtd)
 		goto free_rtd;
 
+	rtd->dev = dev;
+	dev_set_drvdata(dev, rtd);
+
 	/*
 	 * for rtd->codec_dais
 	 */
@@ -403,27 +433,6 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 		goto free_rtd;
 
 	/*
-	 * for rtd->dev
-	 */
-	rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
-	if (!rtd->dev)
-		goto free_rtd;
-
-	rtd->dev->parent = card->dev;
-	rtd->dev->release = soc_release_rtd_dev;
-	rtd->dev->groups = soc_dev_attr_groups;
-
-	dev_set_name(rtd->dev, "%s", dai_link->name);
-	dev_set_drvdata(rtd->dev, rtd);
-
-	ret = device_register(rtd->dev);
-	if (ret < 0) {
-		put_device(rtd->dev); /* soc_release_rtd_dev */
-		rtd->dev = NULL;
-		goto free_rtd;
-	}
-
-	/*
 	 * rtd remaining settings
 	 */
 	INIT_LIST_HEAD(&rtd->component_list);
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 08/14] ASoC: soc-core: remove snd_soc_rtdcom_del_all()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (6 preceding siblings ...)
  2019-09-12  4:42 ` [alsa-devel] [PATCH v2 07/14] ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order Kuninori Morimoto
@ 2019-09-12  4:42 ` Kuninori Morimoto
  2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: remove snd_soc_rtdcom_del_all()" to the asoc tree Mark Brown
  2019-09-12  4:43 ` [alsa-devel] [PATCH v2 09/14] ASoC: soc-core: use devm_kzalloc() for rtd Kuninori Morimoto
                   ` (5 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:42 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

If we can use devm_kzalloc(rtd->dev, xxx) for rtdcom,
we don't need to call snd_soc_rtdcom_del_all() for kfree().
This patch uses devm_kzalloc(rtd->dev, xxx) for rtdcom,
and remove snd_soc_rtdcom_del_all().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- no change

 sound/soc/soc-core.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 0ffa780..ecc22b8 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -288,28 +288,29 @@ static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
 			return 0;
 	}
 
-	rtdcom = kmalloc(sizeof(*rtdcom), GFP_KERNEL);
+	/*
+	 * created rtdcom here will be freed when rtd->dev was freed.
+	 * see
+	 *	soc_free_pcm_runtime() :: device_unregister(rtd->dev)
+	 */
+	rtdcom = devm_kzalloc(rtd->dev, sizeof(*rtdcom), GFP_KERNEL);
 	if (!rtdcom)
 		return -ENOMEM;
 
 	rtdcom->component = component;
 	INIT_LIST_HEAD(&rtdcom->list);
 
+	/*
+	 * When rtd was freed, created rtdcom here will be
+	 * also freed.
+	 * And we don't need to call list_del(&rtdcom->list)
+	 * when freed, because rtd is also freed.
+	 */
 	list_add_tail(&rtdcom->list, &rtd->component_list);
 
 	return 0;
 }
 
-static void snd_soc_rtdcom_del_all(struct snd_soc_pcm_runtime *rtd)
-{
-	struct snd_soc_rtdcom_list *rtdcom1, *rtdcom2;
-
-	for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2)
-		kfree(rtdcom1);
-
-	INIT_LIST_HEAD(&rtd->component_list);
-}
-
 struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
 						const char *driver_name)
 {
@@ -370,7 +371,6 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 		return;
 
 	kfree(rtd->codec_dais);
-	snd_soc_rtdcom_del_all(rtd);
 	list_del(&rtd->list);
 
 	/*
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 09/14] ASoC: soc-core: use devm_kzalloc() for rtd
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (7 preceding siblings ...)
  2019-09-12  4:42 ` [alsa-devel] [PATCH v2 08/14] ASoC: soc-core: remove snd_soc_rtdcom_del_all() Kuninori Morimoto
@ 2019-09-12  4:43 ` Kuninori Morimoto
  2019-09-12  4:43 ` [alsa-devel] [PATCH v2 10/14] ASoC: soc-core: remove soc_remove_dai_links() Kuninori Morimoto
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Current rtd, rtd->dev, rtd->codec_dais are created by normal kzalloc(),
but we want to use devm_kzalloc() as much as possible.

Created rtd->dev is registered by device_register() at
soc_new_pcm_runtime(), and it will be freed at
soc_free_pcm_runtime() by device_unregister().

This means, if we can use devm_kzalloc(rtd->dev, xxx) for
rtd / rtd->codec_dais, all these are automatically freed
via soc_free_pcm_runtime().
This patch uses devm_kzalloc(rtd->dev, xxx) for rtd / rtd->codec_dais.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- it is more readable because of [07/14]

 sound/soc/soc-core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index ecc22b8..f6a01ae 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -370,7 +370,6 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 	if (!rtd)
 		return;
 
-	kfree(rtd->codec_dais);
 	list_del(&rtd->list);
 
 	/*
@@ -384,7 +383,6 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 	 *	soc_new_pcm_runtime()
 	 */
 	device_unregister(rtd->dev);
-	kfree(rtd);
 }
 
 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
@@ -416,7 +414,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	/*
 	 * for rtd
 	 */
-	rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
+	rtd = devm_kzalloc(dev, sizeof(*rtd), GFP_KERNEL);
 	if (!rtd)
 		goto free_rtd;
 
@@ -426,7 +424,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	/*
 	 * for rtd->codec_dais
 	 */
-	rtd->codec_dais = kcalloc(dai_link->num_codecs,
+	rtd->codec_dais = devm_kcalloc(dev, dai_link->num_codecs,
 					sizeof(struct snd_soc_dai *),
 					GFP_KERNEL);
 	if (!rtd->codec_dais)
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 10/14] ASoC: soc-core: remove soc_remove_dai_links()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (8 preceding siblings ...)
  2019-09-12  4:43 ` [alsa-devel] [PATCH v2 09/14] ASoC: soc-core: use devm_kzalloc() for rtd Kuninori Morimoto
@ 2019-09-12  4:43 ` Kuninori Morimoto
  2019-09-12  4:43 ` [alsa-devel] [PATCH v2 11/14] ASoC: soc-core: add soc_setup_card_name() Kuninori Morimoto
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

It is easy to read code if it is cleanly using paired function/naming,
like start <-> stop, register <-> unregister, etc, etc.
But, current ALSA SoC code is very random, unbalance, not paired, etc.
It is easy to create bug at the such code, and it will be difficult to
debug.

soc_cleanup_card_resources() (a) which is paired function of
snd_soc_instantiate_card() (A) is calling soc_remove_dai_links() (*)
to remove card related resources, but it is breaking
add/remove balance (B)(b)(C)(c)(D)(d), in other words
these should be called from soc_cleanup_card_resources() (a)
from balance point of view.

More headacke is that it is using original removing method for
dai_link even though we already have snd_soc_remove_dai_link()
which is the function for it (d).

This patch removes snd_soc_remove_dai_links() and balance up code.

	static void soc_remove_dai_links(...)
	{
		...
(b)		soc_remove_link_dais(card);
(c)		soc_remove_link_components(card);

		for_each_card_links_safe(card, link, _link) {
			...
			/* it should use snd_soc_remove_dai_link() here */
(d)			list_del(&link->list);
		}
	}

(a)	static int soc_cleanup_card_resources(...)
	{
		...

		/* remove and free each DAI */
(*)		soc_remove_dai_links(card);
		...
	}

(A)	static int snd_soc_instantiate_card(struct snd_soc_card *card)
	{
		...
		/* add predefined DAI links to the list */
		for_each_card_prelinks(card, i, dai_link)
(B)			snd_soc_add_dai_link(card, dai_link);
		...
		/* probe all components used by DAI links on this card */
(C)		ret = soc_probe_link_components(card);
		...
		/* probe all DAI links on this card */
(D)		ret = soc_probe_link_dais(card);
		...
	}

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- no change

 sound/soc/soc-core.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index f6a01ae..430ed33 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1275,23 +1275,6 @@ static int soc_probe_link_components(struct snd_soc_card *card)
 	return 0;
 }
 
-static void soc_remove_dai_links(struct snd_soc_card *card)
-{
-	struct snd_soc_dai_link *link, *_link;
-
-	soc_remove_link_dais(card);
-
-	soc_remove_link_components(card);
-
-	for_each_card_links_safe(card, link, _link) {
-		if (link->dobj.type == SND_SOC_DOBJ_DAI_LINK)
-			dev_warn(card->dev, "Topology forgot to remove link %s?\n",
-				link->name);
-
-		list_del(&link->list);
-	}
-}
-
 static int soc_init_dai_link(struct snd_soc_card *card,
 			     struct snd_soc_dai_link *link)
 {
@@ -1924,6 +1907,8 @@ static void soc_check_tplg_fes(struct snd_soc_card *card)
 
 static void soc_cleanup_card_resources(struct snd_soc_card *card)
 {
+	struct snd_soc_dai_link *link, *_link;
+
 	/* free the ALSA card at first; this syncs with pending operations */
 	if (card->snd_card) {
 		snd_card_free(card->snd_card);
@@ -1931,7 +1916,12 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card)
 	}
 
 	/* remove and free each DAI */
-	soc_remove_dai_links(card);
+	soc_remove_link_dais(card);
+	soc_remove_link_components(card);
+
+	for_each_card_links_safe(card, link, _link)
+		snd_soc_remove_dai_link(card, link);
+
 	soc_remove_pcm_runtimes(card);
 
 	/* remove auxiliary devices */
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 11/14] ASoC: soc-core: add soc_setup_card_name()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (9 preceding siblings ...)
  2019-09-12  4:43 ` [alsa-devel] [PATCH v2 10/14] ASoC: soc-core: remove soc_remove_dai_links() Kuninori Morimoto
@ 2019-09-12  4:43 ` Kuninori Morimoto
  2019-09-12  4:44 ` [alsa-devel] [PATCH v2 12/14] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

ALSA needs to setup shortname, longname, and driver.
These methods are very similar.
This patch adds new soc_setup_card_name() and setup these.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- no change

 sound/soc/soc-core.c | 60 ++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 42 insertions(+), 18 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 430ed33..8220bac 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1905,6 +1905,42 @@ static void soc_check_tplg_fes(struct snd_soc_card *card)
 	}
 }
 
+#define soc_setup_card_name(name, name1, name2, norm)		\
+	__soc_setup_card_name(name, sizeof(name), name1, name2, norm)
+static void __soc_setup_card_name(char *name, int len,
+				  const char *name1, const char *name2,
+				  int normalization)
+{
+	int i;
+
+	snprintf(name, len, "%s", name1 ? name1 : name2);
+
+	if (!normalization)
+		return;
+
+	/*
+	 * Name normalization
+	 *
+	 * The driver name is somewhat special, as it's used as a key for
+	 * searches in the user-space.
+	 *
+	 * ex)
+	 *	"abcd??efg" -> "abcd__efg"
+	 */
+	for (i = 0; i < len; i++) {
+		switch (name[i]) {
+		case '_':
+		case '-':
+		case '\0':
+			break;
+		default:
+			if (!isalnum(name[i]))
+				name[i] = '_';
+			break;
+		}
+	}
+}
+
 static void soc_cleanup_card_resources(struct snd_soc_card *card)
 {
 	struct snd_soc_dai_link *link, *_link;
@@ -2070,24 +2106,12 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
 	/* try to set some sane longname if DMI is available */
 	snd_soc_set_dmi_name(card, NULL);
 
-	snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
-		 "%s", card->name);
-	snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
-		 "%s", card->long_name ? card->long_name : card->name);
-	snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
-		 "%s", card->driver_name ? card->driver_name : card->name);
-	for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
-		switch (card->snd_card->driver[i]) {
-		case '_':
-		case '-':
-		case '\0':
-			break;
-		default:
-			if (!isalnum(card->snd_card->driver[i]))
-				card->snd_card->driver[i] = '_';
-			break;
-		}
-	}
+	soc_setup_card_name(card->snd_card->shortname,
+			    card->name, NULL, 0);
+	soc_setup_card_name(card->snd_card->longname,
+			    card->long_name, card->name, 0);
+	soc_setup_card_name(card->snd_card->driver,
+			    card->driver_name, card->name, 1);
 
 	if (card->late_probe) {
 		ret = card->late_probe(card);
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 12/14] ASoC: soc-core: use devm_xxx for component related resource
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (10 preceding siblings ...)
  2019-09-12  4:43 ` [alsa-devel] [PATCH v2 11/14] ASoC: soc-core: add soc_setup_card_name() Kuninori Morimoto
@ 2019-09-12  4:44 ` Kuninori Morimoto
  2019-09-12  4:44 ` [alsa-devel] [PATCH v2 13/14] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card() Kuninori Morimoto
  2019-09-12  4:44 ` [alsa-devel] [PATCH v2 14/14] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume() Kuninori Morimoto
  13 siblings, 0 replies; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:44 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

dai / component related resources are created when component is
registered, and it will be freed when component was unregistered.
These resources are not re-used after that.
This means, we can use devm_xxx for dai / component, without
thinking about kfree().
This patch uses devm_xxx for these.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- no change

 sound/soc/soc-core.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 8220bac..2b12b49 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2506,7 +2506,7 @@ static char *fmt_single_name(struct device *dev, int *id)
 			*id = 0;
 	}
 
-	return kstrdup(name, GFP_KERNEL);
+	return devm_kstrdup(dev, name, GFP_KERNEL);
 }
 
 /*
@@ -2523,7 +2523,7 @@ static inline char *fmt_multiple_name(struct device *dev,
 		return NULL;
 	}
 
-	return kstrdup(dai_drv->name, GFP_KERNEL);
+	return devm_kstrdup(dev, dai_drv->name, GFP_KERNEL);
 }
 
 /**
@@ -2539,8 +2539,6 @@ static void snd_soc_unregister_dais(struct snd_soc_component *component)
 		dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
 			dai->name);
 		list_del(&dai->list);
-		kfree(dai->name);
-		kfree(dai);
 	}
 }
 
@@ -2554,7 +2552,7 @@ static struct snd_soc_dai *soc_add_dai(struct snd_soc_component *component,
 
 	dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
 
-	dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
+	dai = devm_kzalloc(dev, sizeof(*dai), GFP_KERNEL);
 	if (dai == NULL)
 		return NULL;
 
@@ -2576,10 +2574,8 @@ static struct snd_soc_dai *soc_add_dai(struct snd_soc_component *component,
 		else
 			dai->id = component->num_dai;
 	}
-	if (dai->name == NULL) {
-		kfree(dai);
+	if (!dai->name)
 		return NULL;
-	}
 
 	dai->component = component;
 	dai->dev = dev;
@@ -2765,7 +2761,6 @@ static void snd_soc_component_add(struct snd_soc_component *component)
 static void snd_soc_component_cleanup(struct snd_soc_component *component)
 {
 	snd_soc_unregister_dais(component);
-	kfree(component->name);
 }
 
 static void snd_soc_component_del_unlocked(struct snd_soc_component *component)
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 13/14] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (11 preceding siblings ...)
  2019-09-12  4:44 ` [alsa-devel] [PATCH v2 12/14] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
@ 2019-09-12  4:44 ` Kuninori Morimoto
  2019-09-12  4:44 ` [alsa-devel] [PATCH v2 14/14] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume() Kuninori Morimoto
  13 siblings, 0 replies; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:44 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

card->rtd_num is used to count rtd. Initialize it at
snd_soc_instantiate_card() is very natural and less confusion.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- no change

 sound/soc/soc-core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 2b12b49..7271fe7 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -462,8 +462,6 @@ static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
 
 	for_each_card_rtds_safe(card, rtd, _rtd)
 		soc_free_pcm_runtime(rtd);
-
-	card->num_rtd = 0;
 }
 
 struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
@@ -2008,6 +2006,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
 		goto probe_end;
 
 	/* add predefined DAI links to the list */
+	card->num_rtd = 0;
 	for_each_card_prelinks(card, i, dai_link) {
 		ret = snd_soc_add_dai_link(card, dai_link);
 		if (ret < 0)
@@ -2418,7 +2417,6 @@ int snd_soc_register_card(struct snd_soc_card *card)
 	INIT_LIST_HEAD(&card->dapm_dirty);
 	INIT_LIST_HEAD(&card->dobj_list);
 
-	card->num_rtd = 0;
 	card->instantiated = 0;
 	mutex_init(&card->mutex);
 	mutex_init(&card->dapm_mutex);
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] [PATCH v2 14/14] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume()
  2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (12 preceding siblings ...)
  2019-09-12  4:44 ` [alsa-devel] [PATCH v2 13/14] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card() Kuninori Morimoto
@ 2019-09-12  4:44 ` Kuninori Morimoto
  13 siblings, 0 replies; 23+ messages in thread
From: Kuninori Morimoto @ 2019-09-12  4:44 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

snd_soc_limit_volume() is finding snd_kcontrol by using original coding,
but we already have snd_soc_card_get_kcontrol().
Let's use existing function.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

	- new patch

 sound/soc/soc-ops.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index f4dc3d4..652657d 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -592,23 +592,16 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
 int snd_soc_limit_volume(struct snd_soc_card *card,
 	const char *name, int max)
 {
-	struct snd_card *snd_card = card->snd_card;
 	struct snd_kcontrol *kctl;
 	struct soc_mixer_control *mc;
-	int found = 0;
 	int ret = -EINVAL;
 
 	/* Sanity check for name and max */
 	if (unlikely(!name || max <= 0))
 		return -EINVAL;
 
-	list_for_each_entry(kctl, &snd_card->controls, list) {
-		if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
-			found = 1;
-			break;
-		}
-	}
-	if (found) {
+	kctl = snd_soc_card_get_kcontrol(card, name);
+	if (kctl) {
 		mc = (struct soc_mixer_control *)kctl->private_value;
 		if (max <= mc->max) {
 			mc->platform_max = max;
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: remove snd_soc_rtdcom_del_all()" to the asoc tree
  2019-09-12  4:42 ` [alsa-devel] [PATCH v2 08/14] ASoC: soc-core: remove snd_soc_rtdcom_del_all() Kuninori Morimoto
@ 2019-10-01 11:40   ` Mark Brown
  0 siblings, 0 replies; 23+ messages in thread
From: Mark Brown @ 2019-10-01 11:40 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: remove snd_soc_rtdcom_del_all()

has been applied to the asoc tree at

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

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

From 353e16bf60458fae5927cf04ff668fc152fff465 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Thu, 12 Sep 2019 13:42:44 +0900
Subject: [PATCH] ASoC: soc-core: remove snd_soc_rtdcom_del_all()

If we can use devm_kzalloc(rtd->dev, xxx) for rtdcom,
we don't need to call snd_soc_rtdcom_del_all() for kfree().
This patch uses devm_kzalloc(rtd->dev, xxx) for rtdcom,
and remove snd_soc_rtdcom_del_all().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/875zlyf7ln.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-core.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index b72207412c73..d2842a383846 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -288,28 +288,29 @@ static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
 			return 0;
 	}
 
-	rtdcom = kmalloc(sizeof(*rtdcom), GFP_KERNEL);
+	/*
+	 * created rtdcom here will be freed when rtd->dev was freed.
+	 * see
+	 *	soc_free_pcm_runtime() :: device_unregister(rtd->dev)
+	 */
+	rtdcom = devm_kzalloc(rtd->dev, sizeof(*rtdcom), GFP_KERNEL);
 	if (!rtdcom)
 		return -ENOMEM;
 
 	rtdcom->component = component;
 	INIT_LIST_HEAD(&rtdcom->list);
 
+	/*
+	 * When rtd was freed, created rtdcom here will be
+	 * also freed.
+	 * And we don't need to call list_del(&rtdcom->list)
+	 * when freed, because rtd is also freed.
+	 */
 	list_add_tail(&rtdcom->list, &rtd->component_list);
 
 	return 0;
 }
 
-static void snd_soc_rtdcom_del_all(struct snd_soc_pcm_runtime *rtd)
-{
-	struct snd_soc_rtdcom_list *rtdcom1, *rtdcom2;
-
-	for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2)
-		kfree(rtdcom1);
-
-	INIT_LIST_HEAD(&rtd->component_list);
-}
-
 struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
 						const char *driver_name)
 {
@@ -370,7 +371,6 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 		return;
 
 	kfree(rtd->codec_dais);
-	snd_soc_rtdcom_del_all(rtd);
 	list_del(&rtd->list);
 
 	/*
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order" to the asoc tree
  2019-09-12  4:42 ` [alsa-devel] [PATCH v2 07/14] ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order Kuninori Morimoto
@ 2019-10-01 11:40   ` Mark Brown
  0 siblings, 0 replies; 23+ messages in thread
From: Mark Brown @ 2019-10-01 11:40 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order

has been applied to the asoc tree at

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

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

From d918a37610b1bf71faa86f589bd7604f71c1e05f Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Thu, 12 Sep 2019 13:42:30 +0900
Subject: [PATCH] ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order

This patch allocs dev first at soc_new_pcm_runtime().
This is prepare for rtd->dev, rtd->codec_dais alloc cleanup

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/877e6ef7m1.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-core.c | 55 ++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 8a37850291bd..b72207412c73 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -125,6 +125,9 @@ static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
 	struct device *dev = kobj_to_dev(kobj);
 	struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
 
+	if (!rtd)
+		return 0;
+
 	if (attr == &dev_attr_pmdown_time.attr)
 		return attr->mode; /* always visible */
 	return rtd->num_codecs ? attr->mode : 0; /* enabled only with codec */
@@ -374,9 +377,13 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 	 * we don't need to call kfree() for rtd->dev
 	 * see
 	 *	soc_release_rtd_dev()
+	 *
+	 * We don't need rtd->dev NULL check, because
+	 * it is alloced *before* rtd.
+	 * see
+	 *	soc_new_pcm_runtime()
 	 */
-	if (rtd->dev)
-		device_unregister(rtd->dev);
+	device_unregister(rtd->dev);
 	kfree(rtd);
 }
 
@@ -384,8 +391,28 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
 {
 	struct snd_soc_pcm_runtime *rtd;
+	struct device *dev;
 	int ret;
 
+	/*
+	 * for rtd->dev
+	 */
+	dev = kzalloc(sizeof(struct device), GFP_KERNEL);
+	if (!dev)
+		return NULL;
+
+	dev->parent	= card->dev;
+	dev->release	= soc_release_rtd_dev;
+	dev->groups	= soc_dev_attr_groups;
+
+	dev_set_name(dev, "%s", dai_link->name);
+
+	ret = device_register(dev);
+	if (ret < 0) {
+		put_device(dev); /* soc_release_rtd_dev */
+		return NULL;
+	}
+
 	/*
 	 * for rtd
 	 */
@@ -393,6 +420,9 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	if (!rtd)
 		goto free_rtd;
 
+	rtd->dev = dev;
+	dev_set_drvdata(dev, rtd);
+
 	/*
 	 * for rtd->codec_dais
 	 */
@@ -402,27 +432,6 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	if (!rtd->codec_dais)
 		goto free_rtd;
 
-	/*
-	 * for rtd->dev
-	 */
-	rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
-	if (!rtd->dev)
-		goto free_rtd;
-
-	rtd->dev->parent = card->dev;
-	rtd->dev->release = soc_release_rtd_dev;
-	rtd->dev->groups = soc_dev_attr_groups;
-
-	dev_set_name(rtd->dev, "%s", dai_link->name);
-	dev_set_drvdata(rtd->dev, rtd);
-
-	ret = device_register(rtd->dev);
-	if (ret < 0) {
-		put_device(rtd->dev); /* soc_release_rtd_dev */
-		rtd->dev = NULL;
-		goto free_rtd;
-	}
-
 	/*
 	 * rtd remaining settings
 	 */
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free()" to the asoc tree
  2019-09-12  4:41 ` [alsa-devel] [PATCH v2 06/14] ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free() Kuninori Morimoto
@ 2019-10-01 11:40   ` Mark Brown
  0 siblings, 0 replies; 23+ messages in thread
From: Mark Brown @ 2019-10-01 11:40 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free()

has been applied to the asoc tree at

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

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

From b7c5bc45ee94a03a0dc45a862180e17db8ea8e9d Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Thu, 12 Sep 2019 13:41:01 +0900
Subject: [PATCH] ASoC: soc-core: merge soc_free_pcm_runtime() and
 soc_rtd_free()

"rtd"      is handled by soc_xxx_pcm_runtime(), and
"rtd->dev" is handled by soc_rtd_xxx().

There is no reason to separate these, and it makes code complex.
We can free these in the same time.

Here soc_rtd_free() (A) which frees rtd->dev is called from
soc_remove_link_dais() many times (1).
Then, it is using dev_registered flags to avoid multi kfree() (2).
This is no longer needed if we can merge these functions.

	static void soc_remove_link_dais(...)
	{
		...
(1)		for_each_comp_order(order) {
(1)			for_each_card_rtds(card, rtd) {

(A)				soc_rtd_free(rtd);
				...
			}
		}
	}

(A)	static void soc_rtd_free(...)
	{
(2)		if (rtd->dev_registered) {
			/* we don't need to call kfree() for rtd->dev */
			device_unregister(rtd->dev);
(2)			rtd->dev_registered = 0;
		}
	}

This patch merges soc_rtd_free() into soc_free_pcm_runtime().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/878squf7oi.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 include/sound/soc.h  |  1 -
 sound/soc/soc-core.c | 24 ++++++++----------------
 2 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index f264c6509f00..d93cb46c536d 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1148,7 +1148,6 @@ struct snd_soc_pcm_runtime {
 	struct list_head component_list; /* list of connected components */
 
 	/* bit field */
-	unsigned int dev_registered:1;
 	unsigned int pop_wait:1;
 	unsigned int fe_compr:1; /* for Dynamic PCM */
 };
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 6abc1bc9a236..8a37850291bd 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -369,6 +369,14 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 	kfree(rtd->codec_dais);
 	snd_soc_rtdcom_del_all(rtd);
 	list_del(&rtd->list);
+
+	/*
+	 * we don't need to call kfree() for rtd->dev
+	 * see
+	 *	soc_release_rtd_dev()
+	 */
+	if (rtd->dev)
+		device_unregister(rtd->dev);
 	kfree(rtd);
 }
 
@@ -434,8 +442,6 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	rtd->num = card->num_rtd;
 	card->num_rtd++;
 
-	rtd->dev_registered = 1;
-
 	return rtd;
 
 free_rtd:
@@ -1169,7 +1175,6 @@ static int soc_probe_dai(struct snd_soc_dai *dai, int order)
 	return 0;
 }
 
-static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd); /* remove me */
 static void soc_remove_link_dais(struct snd_soc_card *card)
 {
 	int i;
@@ -1179,10 +1184,6 @@ static void soc_remove_link_dais(struct snd_soc_card *card)
 
 	for_each_comp_order(order) {
 		for_each_card_rtds(card, rtd) {
-
-			/* finalize rtd device */
-			soc_rtd_free(rtd);
-
 			/* remove the CODEC DAI */
 			for_each_rtd_codec_dai(rtd, i, codec_dai)
 				soc_remove_dai(codec_dai, order);
@@ -1460,15 +1461,6 @@ void snd_soc_remove_dai_link(struct snd_soc_card *card,
 }
 EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link);
 
-static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd)
-{
-	if (rtd->dev_registered) {
-		/* we don't need to call kfree() for rtd->dev */
-		device_unregister(rtd->dev);
-		rtd->dev_registered = 0;
-	}
-}
-
 static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais,
 				struct snd_soc_pcm_runtime *rtd)
 {
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init()" to the asoc tree
  2019-09-12  4:40 ` [alsa-devel] [PATCH v2 05/14] ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init() Kuninori Morimoto
@ 2019-10-01 11:40   ` Mark Brown
  0 siblings, 0 replies; 23+ messages in thread
From: Mark Brown @ 2019-10-01 11:40 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init()

has been applied to the asoc tree at

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

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

From 6e864344873f19120f742c19d15a8c53e7247c6a Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Thu, 12 Sep 2019 13:40:08 +0900
Subject: [PATCH] ASoC: soc-core: merge soc_new_pcm_runtime() and
 soc_rtd_init()

"rtd"      is handled by soc_xxx_pcm_runtime(), and
"rtd->dev" is handled by soc_rtd_xxx().

There is no reason to separate these, and it makes code complex.
We can create these in the same time.

This patch merges soc_rtd_init() into soc_new_pcm_runtime().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87a7baf7pz.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-core.c | 95 ++++++++++++++++++++++++--------------------
 1 file changed, 53 insertions(+), 42 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index bc45b0db05ab..6abc1bc9a236 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -355,8 +355,17 @@ EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
 
 static const struct snd_soc_ops null_snd_soc_ops;
 
+static void soc_release_rtd_dev(struct device *dev)
+{
+	/* "dev" means "rtd->dev" */
+	kfree(dev);
+}
+
 static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 {
+	if (!rtd)
+		return;
+
 	kfree(rtd->codec_dais);
 	snd_soc_rtdcom_del_all(rtd);
 	list_del(&rtd->list);
@@ -367,20 +376,54 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
 {
 	struct snd_soc_pcm_runtime *rtd;
+	int ret;
 
+	/*
+	 * for rtd
+	 */
 	rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
 	if (!rtd)
-		return NULL;
+		goto free_rtd;
 
+	/*
+	 * for rtd->codec_dais
+	 */
 	rtd->codec_dais = kcalloc(dai_link->num_codecs,
 					sizeof(struct snd_soc_dai *),
 					GFP_KERNEL);
-	if (!rtd->codec_dais) {
-		kfree(rtd);
-		return NULL;
+	if (!rtd->codec_dais)
+		goto free_rtd;
+
+	/*
+	 * for rtd->dev
+	 */
+	rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
+	if (!rtd->dev)
+		goto free_rtd;
+
+	rtd->dev->parent = card->dev;
+	rtd->dev->release = soc_release_rtd_dev;
+	rtd->dev->groups = soc_dev_attr_groups;
+
+	dev_set_name(rtd->dev, "%s", dai_link->name);
+	dev_set_drvdata(rtd->dev, rtd);
+
+	ret = device_register(rtd->dev);
+	if (ret < 0) {
+		put_device(rtd->dev); /* soc_release_rtd_dev */
+		rtd->dev = NULL;
+		goto free_rtd;
 	}
 
+	/*
+	 * rtd remaining settings
+	 */
 	INIT_LIST_HEAD(&rtd->component_list);
+	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
+	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
+	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
+	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
+
 	rtd->card = card;
 	rtd->dai_link = dai_link;
 	if (!rtd->dai_link->ops)
@@ -391,7 +434,13 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	rtd->num = card->num_rtd;
 	card->num_rtd++;
 
+	rtd->dev_registered = 1;
+
 	return rtd;
+
+free_rtd:
+	soc_free_pcm_runtime(rtd);
+	return NULL;
 }
 
 static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
@@ -1420,40 +1469,6 @@ static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd)
 	}
 }
 
-static void soc_rtd_release(struct device *dev)
-{
-	kfree(dev);
-}
-
-static int soc_rtd_init(struct snd_soc_pcm_runtime *rtd, const char *name)
-{
-	int ret = 0;
-
-	/* register the rtd device */
-	rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
-	if (!rtd->dev)
-		return -ENOMEM;
-	rtd->dev->parent = rtd->card->dev;
-	rtd->dev->release = soc_rtd_release;
-	rtd->dev->groups = soc_dev_attr_groups;
-	dev_set_name(rtd->dev, "%s", name);
-	dev_set_drvdata(rtd->dev, rtd);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
-	ret = device_register(rtd->dev);
-	if (ret < 0) {
-		/* calling put_device() here to free the rtd->dev */
-		put_device(rtd->dev);
-		dev_err(rtd->card->dev,
-			"ASoC: failed to register runtime device: %d\n", ret);
-		return ret;
-	}
-	rtd->dev_registered = 1;
-	return 0;
-}
-
 static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais,
 				struct snd_soc_pcm_runtime *rtd)
 {
@@ -1503,10 +1518,6 @@ static int soc_link_init(struct snd_soc_card *card,
 			return ret;
 	}
 
-	ret = soc_rtd_init(rtd, dai_link->name);
-	if (ret)
-		return ret;
-
 	/* add DPCM sysfs entries */
 	soc_dpcm_debugfs_add(rtd);
 
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime()" to the asoc tree
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 03/14] ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime() Kuninori Morimoto
@ 2019-10-01 11:40   ` Mark Brown
  0 siblings, 0 replies; 23+ messages in thread
From: Mark Brown @ 2019-10-01 11:40 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime()

has been applied to the asoc tree at

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

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

From 753ace0a34fbd39ac2ec654c6859823db420f69e Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Thu, 12 Sep 2019 13:38:50 +0900
Subject: [PATCH] ASoC: soc-core: call list_del(&rtd->list) at
 soc_free_pcm_runtime()

Current ALSA SoC is calling list_del(&rtd->list) at (1)

	static void soc_remove_pcm_runtimes(...)
	{
		...
		for_each_card_rtds_safe(card, rtd, _rtd) {
(1)			list_del(&rtd->list);
(2)			soc_free_pcm_runtime(rtd);
		}
		...
	}

But, we will call soc_free_pcm_runtime() after that (2).
&rtd->list is         connected at soc_new_pcm_runtime(),
Thus, it should be disconnected at soc_free_pcm_runtime().

This patch calls list_del(&rtd->list) at soc_free_pcm_runtime().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87d0g6f7s5.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index cadf96bc0097..7a3f4783adf6 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -359,6 +359,7 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 {
 	kfree(rtd->codec_dais);
 	snd_soc_rtdcom_del_all(rtd);
+	list_del(&rtd->list);
 	kfree(rtd);
 }
 
@@ -397,10 +398,8 @@ static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
 {
 	struct snd_soc_pcm_runtime *rtd, *_rtd;
 
-	for_each_card_rtds_safe(card, rtd, _rtd) {
-		list_del(&rtd->list);
+	for_each_card_rtds_safe(card, rtd, _rtd)
 		soc_free_pcm_runtime(rtd);
-	}
 
 	card->num_rtd = 0;
 }
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: create rtd->codec_dais first" to the asoc tree
  2019-09-12  4:39 ` [alsa-devel] [PATCH v2 04/14] ASoC: soc-core: create rtd->codec_dais first Kuninori Morimoto
@ 2019-10-01 11:40   ` Mark Brown
  0 siblings, 0 replies; 23+ messages in thread
From: Mark Brown @ 2019-10-01 11:40 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: create rtd->codec_dais first

has been applied to the asoc tree at

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

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

From 929deb849b9e4319015070ead7ca976a4f16e303 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Thu, 12 Sep 2019 13:39:32 +0900
Subject: [PATCH] ASoC: soc-core: create rtd->codec_dais first

soc_new_pcm_runtime() allocs rtd and rtd->codec_dais.
This patch allocs both first, and setup these after that.
This is prepare for soc_new_pcm_runtime() cleanup.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87blvqf7qz.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 7a3f4783adf6..bc45b0db05ab 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -372,12 +372,6 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	if (!rtd)
 		return NULL;
 
-	INIT_LIST_HEAD(&rtd->component_list);
-	rtd->card = card;
-	rtd->dai_link = dai_link;
-	if (!rtd->dai_link->ops)
-		rtd->dai_link->ops = &null_snd_soc_ops;
-
 	rtd->codec_dais = kcalloc(dai_link->num_codecs,
 					sizeof(struct snd_soc_dai *),
 					GFP_KERNEL);
@@ -386,6 +380,12 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 		return NULL;
 	}
 
+	INIT_LIST_HEAD(&rtd->component_list);
+	rtd->card = card;
+	rtd->dai_link = dai_link;
+	if (!rtd->dai_link->ops)
+		rtd->dai_link->ops = &null_snd_soc_ops;
+
 	/* see for_each_card_rtds */
 	list_add_tail(&rtd->list, &card->rtd_list);
 	rtd->num = card->num_rtd;
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime()" to the asoc tree
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 02/14] ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime() Kuninori Morimoto
@ 2019-10-01 11:40   ` Mark Brown
  0 siblings, 0 replies; 23+ messages in thread
From: Mark Brown @ 2019-10-01 11:40 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime()

has been applied to the asoc tree at

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

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

From a848125e320a154dfc17b9a377361b4b0df87363 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Thu, 12 Sep 2019 13:38:34 +0900
Subject: [PATCH] ASoC: soc-core: merge soc_add_pcm_runtime() into
 soc_new_pcm_runtime()

We have soc_new_pcm_runtime() which allocs rtd and its related memory,
and     soc_add_pcm_runtime() which connects rtd to card.

But we don't need to separate these, we can alloc and connect rtd
in the same time.

Current implementation is just makes code complex.
This patch merges these into one.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87ef0mf7sl.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-core.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 96d38db8b578..cadf96bc0097 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -385,16 +385,12 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 		return NULL;
 	}
 
-	return rtd;
-}
-
-static void soc_add_pcm_runtime(struct snd_soc_card *card,
-		struct snd_soc_pcm_runtime *rtd)
-{
 	/* see for_each_card_rtds */
 	list_add_tail(&rtd->list, &card->rtd_list);
 	rtd->num = card->num_rtd;
 	card->num_rtd++;
+
+	return rtd;
 }
 
 static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
@@ -930,7 +926,6 @@ static int soc_bind_dai_link(struct snd_soc_card *card,
 		}
 	}
 
-	soc_add_pcm_runtime(card, rtd);
 	return 0;
 
 _err_defer:
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: move soc_free_pcm_runtime()" to the asoc tree
  2019-09-12  4:38 ` [alsa-devel] [PATCH v2 01/14] ASoC: soc-core: move soc_free_pcm_runtime() Kuninori Morimoto
@ 2019-10-01 11:40   ` Mark Brown
  0 siblings, 0 replies; 23+ messages in thread
From: Mark Brown @ 2019-10-01 11:40 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: move soc_free_pcm_runtime()

has been applied to the asoc tree at

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

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

From 1c93a9e00e40e3a084ebbcaa4a8f412b83f1fa0d Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Thu, 12 Sep 2019 13:38:22 +0900
Subject: [PATCH] ASoC: soc-core: move soc_free_pcm_runtime()

This patch moves soc_free_pcm_runtime() next to soc_new_pcm_runtime().
This is prepare for soc_xxx_pcm_runtime() cleanup.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87ftl2f7sx.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 88978a3036c4..96d38db8b578 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -355,6 +355,13 @@ EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
 
 static const struct snd_soc_ops null_snd_soc_ops;
 
+static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
+{
+	kfree(rtd->codec_dais);
+	snd_soc_rtdcom_del_all(rtd);
+	kfree(rtd);
+}
+
 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
 {
@@ -381,13 +388,6 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	return rtd;
 }
 
-static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
-{
-	kfree(rtd->codec_dais);
-	snd_soc_rtdcom_del_all(rtd);
-	kfree(rtd);
-}
-
 static void soc_add_pcm_runtime(struct snd_soc_card *card,
 		struct snd_soc_pcm_runtime *rtd)
 {
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2019-10-01 11:56 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-12  4:37 [alsa-devel] [PATCH v2 00/14] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
2019-09-12  4:38 ` [alsa-devel] [PATCH v2 01/14] ASoC: soc-core: move soc_free_pcm_runtime() Kuninori Morimoto
2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: move soc_free_pcm_runtime()" to the asoc tree Mark Brown
2019-09-12  4:38 ` [alsa-devel] [PATCH v2 02/14] ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime() Kuninori Morimoto
2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: merge soc_add_pcm_runtime() into soc_new_pcm_runtime()" to the asoc tree Mark Brown
2019-09-12  4:38 ` [alsa-devel] [PATCH v2 03/14] ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime() Kuninori Morimoto
2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: call list_del(&rtd->list) at soc_free_pcm_runtime()" to the asoc tree Mark Brown
2019-09-12  4:39 ` [alsa-devel] [PATCH v2 04/14] ASoC: soc-core: create rtd->codec_dais first Kuninori Morimoto
2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: create rtd->codec_dais first" to the asoc tree Mark Brown
2019-09-12  4:40 ` [alsa-devel] [PATCH v2 05/14] ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init() Kuninori Morimoto
2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: merge soc_new_pcm_runtime() and soc_rtd_init()" to the asoc tree Mark Brown
2019-09-12  4:41 ` [alsa-devel] [PATCH v2 06/14] ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free() Kuninori Morimoto
2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: merge soc_free_pcm_runtime() and soc_rtd_free()" to the asoc tree Mark Brown
2019-09-12  4:42 ` [alsa-devel] [PATCH v2 07/14] ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order Kuninori Morimoto
2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order" to the asoc tree Mark Brown
2019-09-12  4:42 ` [alsa-devel] [PATCH v2 08/14] ASoC: soc-core: remove snd_soc_rtdcom_del_all() Kuninori Morimoto
2019-10-01 11:40   ` [alsa-devel] Applied "ASoC: soc-core: remove snd_soc_rtdcom_del_all()" to the asoc tree Mark Brown
2019-09-12  4:43 ` [alsa-devel] [PATCH v2 09/14] ASoC: soc-core: use devm_kzalloc() for rtd Kuninori Morimoto
2019-09-12  4:43 ` [alsa-devel] [PATCH v2 10/14] ASoC: soc-core: remove soc_remove_dai_links() Kuninori Morimoto
2019-09-12  4:43 ` [alsa-devel] [PATCH v2 11/14] ASoC: soc-core: add soc_setup_card_name() Kuninori Morimoto
2019-09-12  4:44 ` [alsa-devel] [PATCH v2 12/14] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
2019-09-12  4:44 ` [alsa-devel] [PATCH v2 13/14] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card() Kuninori Morimoto
2019-09-12  4:44 ` [alsa-devel] [PATCH v2 14/14] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume() Kuninori Morimoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).