alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH 0/6][resend] ASoC: soc-core cleanup - step 3
@ 2019-10-02  5:22 Kuninori Morimoto
  2019-10-02  5:22 ` [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd Kuninori Morimoto
                   ` (6 more replies)
  0 siblings, 7 replies; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-02  5:22 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


Hi Mark

Some soc-core cleanup patch step3 are accepted, but not all.
These are remains.

Kuninori Morimoto (6):
  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()

 sound/soc/soc-core.c | 109 +++++++++++++++++++++++++++------------------------
 sound/soc/soc-ops.c  |  11 +-----
 2 files changed, 59 insertions(+), 61 deletions(-)

-- 
2.7.4





Thank you for your help !!
Best regards
---
Kuninori Morimoto
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd
  2019-10-02  5:22 [alsa-devel] [PATCH 0/6][resend] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
@ 2019-10-02  5:22 ` Kuninori Morimoto
  2019-10-02 18:55   ` Mark Brown
  2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: use devm_kzalloc() for rtd" to the asoc tree Mark Brown
  2019-10-02  5:22 ` [alsa-devel] [PATCH 2/6] ASoC: soc-core: remove soc_remove_dai_links() Kuninori Morimoto
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-02  5:22 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>
---
 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 4a47ba9..b16a9422 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] 19+ messages in thread

* [alsa-devel] [PATCH 2/6] ASoC: soc-core: remove soc_remove_dai_links()
  2019-10-02  5:22 [alsa-devel] [PATCH 0/6][resend] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
  2019-10-02  5:22 ` [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd Kuninori Morimoto
@ 2019-10-02  5:22 ` Kuninori Morimoto
  2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: remove soc_remove_dai_links()" to the asoc tree Mark Brown
  2019-10-02  5:22 ` [alsa-devel] [PATCH 3/6] ASoC: soc-core: add soc_setup_card_name() Kuninori Morimoto
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-02  5:22 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>
---
 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 b16a9422..a34000d 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] 19+ messages in thread

* [alsa-devel] [PATCH 3/6] ASoC: soc-core: add soc_setup_card_name()
  2019-10-02  5:22 [alsa-devel] [PATCH 0/6][resend] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
  2019-10-02  5:22 ` [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd Kuninori Morimoto
  2019-10-02  5:22 ` [alsa-devel] [PATCH 2/6] ASoC: soc-core: remove soc_remove_dai_links() Kuninori Morimoto
@ 2019-10-02  5:22 ` Kuninori Morimoto
  2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: add soc_setup_card_name()" to the asoc tree Mark Brown
  2019-10-02  5:22 ` [alsa-devel] [PATCH 4/6] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-02  5:22 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>
---
 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 a34000d..f79ffc4 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] 19+ messages in thread

* [alsa-devel] [PATCH 4/6] ASoC: soc-core: use devm_xxx for component related resource
  2019-10-02  5:22 [alsa-devel] [PATCH 0/6][resend] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (2 preceding siblings ...)
  2019-10-02  5:22 ` [alsa-devel] [PATCH 3/6] ASoC: soc-core: add soc_setup_card_name() Kuninori Morimoto
@ 2019-10-02  5:22 ` Kuninori Morimoto
  2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: use devm_xxx for component related resource" to the asoc tree Mark Brown
  2019-10-02  5:23 ` [alsa-devel] [PATCH 4/6] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-02  5:22 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>
---
 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 f79ffc4..2c2803e 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] 19+ messages in thread

* [alsa-devel] [PATCH 4/6] ASoC: soc-core: use devm_xxx for component related resource
  2019-10-02  5:22 [alsa-devel] [PATCH 0/6][resend] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (3 preceding siblings ...)
  2019-10-02  5:22 ` [alsa-devel] [PATCH 4/6] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
@ 2019-10-02  5:23 ` Kuninori Morimoto
  2019-10-02  5:23 ` [alsa-devel] [PATCH 5/6] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card() Kuninori Morimoto
  2019-10-02  5:23 ` [alsa-devel] [PATCH 6/6] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume() Kuninori Morimoto
  6 siblings, 0 replies; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-02  5:23 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>
---
 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 f79ffc4..2c2803e 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] 19+ messages in thread

* [alsa-devel] [PATCH 5/6] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()
  2019-10-02  5:22 [alsa-devel] [PATCH 0/6][resend] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (4 preceding siblings ...)
  2019-10-02  5:23 ` [alsa-devel] [PATCH 4/6] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
@ 2019-10-02  5:23 ` Kuninori Morimoto
  2019-10-02  7:42   ` Daniel Baluta
  2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()" to the asoc tree Mark Brown
  2019-10-02  5:23 ` [alsa-devel] [PATCH 6/6] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume() Kuninori Morimoto
  6 siblings, 2 replies; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-02  5:23 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>
---
 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 2c2803e..d39d908 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] 19+ messages in thread

* [alsa-devel] [PATCH 6/6] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume()
  2019-10-02  5:22 [alsa-devel] [PATCH 0/6][resend] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
                   ` (5 preceding siblings ...)
  2019-10-02  5:23 ` [alsa-devel] [PATCH 5/6] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card() Kuninori Morimoto
@ 2019-10-02  5:23 ` Kuninori Morimoto
  2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume()" to the asoc tree Mark Brown
  6 siblings, 1 reply; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-02  5:23 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>
---
 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] 19+ messages in thread

* Re: [alsa-devel] [PATCH 5/6] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()
  2019-10-02  5:23 ` [alsa-devel] [PATCH 5/6] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card() Kuninori Morimoto
@ 2019-10-02  7:42   ` Daniel Baluta
  2019-10-02  7:59     ` Kuninori Morimoto
  2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()" to the asoc tree Mark Brown
  1 sibling, 1 reply; 19+ messages in thread
From: Daniel Baluta @ 2019-10-02  7:42 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

On Wed, Oct 2, 2019 at 8:27 AM Kuninori Morimoto
<kuninori.morimoto.gx@renesas.com> wrote:
>
> 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>
> ---
>  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 2c2803e..d39d908 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;

Shouldn't this be placed before the comment above?

>         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
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH 5/6] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()
  2019-10-02  7:42   ` Daniel Baluta
@ 2019-10-02  7:59     ` Kuninori Morimoto
  0 siblings, 0 replies; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-02  7:59 UTC (permalink / raw)
  To: Daniel Baluta; +Cc: Linux-ALSA, Mark Brown


Hi Daniel

Thank you for your feedback

> > @@ -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;
> 
> Shouldn't this be placed before the comment above?
> 
> >         for_each_card_prelinks(card, i, dai_link) {
> >                 ret = snd_soc_add_dai_link(card, dai_link);
> >                 if (ret < 0)

It is used under this for_each_card_prelinks() loop.
card->num_rtd setup and this loop are 1 set.
Thus, I added it under comment.

Thank you for your help !!
Best regards
---
Kuninori Morimoto
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd
  2019-10-02  5:22 ` [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd Kuninori Morimoto
@ 2019-10-02 18:55   ` Mark Brown
  2019-10-03  0:31     ` Kuninori Morimoto
  2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: use devm_kzalloc() for rtd" to the asoc tree Mark Brown
  1 sibling, 1 reply; 19+ messages in thread
From: Mark Brown @ 2019-10-02 18:55 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA


[-- Attachment #1.1: Type: text/plain, Size: 694 bytes --]

On Wed, Oct 02, 2019 at 02:22:32PM +0900, Kuninori Morimoto wrote:

> 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().

These aren't using devm_ because they are done at card init time and so
might happen multiple times when other card components get removed and
added.  This shouldn't happen too much but if it does then it could end
up consuming a noticeable amount of memory.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

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

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

* Re: [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd
  2019-10-02 18:55   ` Mark Brown
@ 2019-10-03  0:31     ` Kuninori Morimoto
  2019-10-03  0:56       ` Kuninori Morimoto
  0 siblings, 1 reply; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-03  0:31 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


Hi Mark

> > 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().
> 
> These aren't using devm_ because they are done at card init time and so
> might happen multiple times when other card components get removed and
> added.  This shouldn't happen too much but if it does then it could end
> up consuming a noticeable amount of memory.

I see.
Actually my local patch which is not yet posted can solve this
multiple times issue.
Mergeing these can be good solution.
Please drop it so far.

Thank you for your help !!
Best regards
---
Kuninori Morimoto
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd
  2019-10-03  0:31     ` Kuninori Morimoto
@ 2019-10-03  0:56       ` Kuninori Morimoto
  0 siblings, 0 replies; 19+ messages in thread
From: Kuninori Morimoto @ 2019-10-03  0:56 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


Hi Mark, again

> > > 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().
> > 
> > These aren't using devm_ because they are done at card init time and so
> > might happen multiple times when other card components get removed and
> > added.  This shouldn't happen too much but if it does then it could end
> > up consuming a noticeable amount of memory.
> 
> I see.
> Actually my local patch which is not yet posted can solve this
> multiple times issue.
> Mergeing these can be good solution.
> Please drop it so far.

Oops, it was alreay posted and accepted :)

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

above rtd, rtd->codec_dais are devm_kzalloc() by original dev
(which will be rtd->dev) instead of card/component dev.

It is registered by device_register() at soc_new_pcm_runtime(),
and will be unregistered by device_unregister() at soc_free_pcm_runtime()
when card was removed.

It is a little bit tricky, but 
these are chain-freed when card was removed.
If my understanding was correct, we don't have memory leak
by multiple times card/components remove.
But, please double check.

	user removed card
	 -> snd_soc_unbind_card()
	  -> soc_cleanup_card_resources()
	   -> soc_remove_pcm_runtimes()
	    -> soc_free_pcm_runtime()
(*)	     -> device_unregister(rtd->dev);

rtd->dev will be kfree() by soc_release_rtd_dev at (*),
then, rtd, rtd->codec_dais will be kfree() via devm_

Thank you for your help !!
Best regards
---
Kuninori Morimoto
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* [alsa-devel] Applied "ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()" to the asoc tree
  2019-10-02  5:23 ` [alsa-devel] [PATCH 5/6] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card() Kuninori Morimoto
  2019-10-02  7:42   ` Daniel Baluta
@ 2019-10-04 17:52   ` Mark Brown
  1 sibling, 0 replies; 19+ messages in thread
From: Mark Brown @ 2019-10-04 17:52 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()

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 d8145989ff8c2a938be372b728f90e23de8557a2 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Wed, 2 Oct 2019 14:23:07 +0900
Subject: [PATCH] ASoC: soc-core: setup card->rtd_num at
 snd_soc_instantiate_card()

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>
Link: https://lore.kernel.org/r/87zhijafgk.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 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 2c2803e6544b..d39d908f3204 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.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] 19+ messages in thread

* [alsa-devel] Applied "ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume()" to the asoc tree
  2019-10-02  5:23 ` [alsa-devel] [PATCH 6/6] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume() Kuninori Morimoto
@ 2019-10-04 17:52   ` Mark Brown
  0 siblings, 0 replies; 19+ messages in thread
From: Mark Brown @ 2019-10-04 17:52 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume()

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 0881ab6e74b0be7df3da3abdf7caeb2552f907d2 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Wed, 2 Oct 2019 14:23:14 +0900
Subject: [PATCH] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at
 snd_soc_limit_volume()

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>
Link: https://lore.kernel.org/r/87y2y3afgd.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 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 f4dc3d445aae..652657dc6809 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.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] 19+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: use devm_xxx for component related resource" to the asoc tree
  2019-10-02  5:22 ` [alsa-devel] [PATCH 4/6] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
@ 2019-10-04 17:52   ` Mark Brown
  0 siblings, 0 replies; 19+ messages in thread
From: Mark Brown @ 2019-10-04 17:52 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: use devm_xxx for component related resource

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 50014499e6a45edd7ba1facf2133c03bbc7d8266 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Wed, 2 Oct 2019 14:22:57 +0900
Subject: [PATCH] ASoC: soc-core: use devm_xxx for component related resource

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>
Link: https://lore.kernel.org/r/8736gbbu1a.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 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 f79ffc4b5b57..2c2803e6544b 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.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] 19+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: add soc_setup_card_name()" to the asoc tree
  2019-10-02  5:22 ` [alsa-devel] [PATCH 3/6] ASoC: soc-core: add soc_setup_card_name() Kuninori Morimoto
@ 2019-10-04 17:52   ` Mark Brown
  0 siblings, 0 replies; 19+ messages in thread
From: Mark Brown @ 2019-10-04 17:52 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: add soc_setup_card_name()

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 0f23f718ecbc135866ac40db3424dd75f01c76ea Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Wed, 2 Oct 2019 14:22:49 +0900
Subject: [PATCH] ASoC: soc-core: add soc_setup_card_name()

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>
Link: https://lore.kernel.org/r/874l0rbu1i.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 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 a34000d08856..f79ffc4b5b57 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.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] 19+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: use devm_kzalloc() for rtd" to the asoc tree
  2019-10-02  5:22 ` [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd Kuninori Morimoto
  2019-10-02 18:55   ` Mark Brown
@ 2019-10-04 17:52   ` Mark Brown
  1 sibling, 0 replies; 19+ messages in thread
From: Mark Brown @ 2019-10-04 17:52 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: use devm_kzalloc() for rtd

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 4dc0e7df62839d052476de0f8447f29f857cecda Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Wed, 2 Oct 2019 14:22:32 +0900
Subject: [PATCH] ASoC: soc-core: use devm_kzalloc() for rtd

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>
Link: https://lore.kernel.org/r/877e5nbu1z.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 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 4a47ba94559f..b16a94228091 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.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] 19+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: remove soc_remove_dai_links()" to the asoc tree
  2019-10-02  5:22 ` [alsa-devel] [PATCH 2/6] ASoC: soc-core: remove soc_remove_dai_links() Kuninori Morimoto
@ 2019-10-04 17:52   ` Mark Brown
  0 siblings, 0 replies; 19+ messages in thread
From: Mark Brown @ 2019-10-04 17:52 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

The patch

   ASoC: soc-core: remove soc_remove_dai_links()

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 7ce6088f60624805a8d3127185e2830e299849f1 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Wed, 2 Oct 2019 14:22:40 +0900
Subject: [PATCH] ASoC: soc-core: remove soc_remove_dai_links()

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>
Link: https://lore.kernel.org/r/875zl7bu1r.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 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 b16a94228091..a34000d08856 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.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] 19+ messages in thread

end of thread, other threads:[~2019-10-04 17:57 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-02  5:22 [alsa-devel] [PATCH 0/6][resend] ASoC: soc-core cleanup - step 3 Kuninori Morimoto
2019-10-02  5:22 ` [alsa-devel] [PATCH 1/6] ASoC: soc-core: use devm_kzalloc() for rtd Kuninori Morimoto
2019-10-02 18:55   ` Mark Brown
2019-10-03  0:31     ` Kuninori Morimoto
2019-10-03  0:56       ` Kuninori Morimoto
2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: use devm_kzalloc() for rtd" to the asoc tree Mark Brown
2019-10-02  5:22 ` [alsa-devel] [PATCH 2/6] ASoC: soc-core: remove soc_remove_dai_links() Kuninori Morimoto
2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: remove soc_remove_dai_links()" to the asoc tree Mark Brown
2019-10-02  5:22 ` [alsa-devel] [PATCH 3/6] ASoC: soc-core: add soc_setup_card_name() Kuninori Morimoto
2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: add soc_setup_card_name()" to the asoc tree Mark Brown
2019-10-02  5:22 ` [alsa-devel] [PATCH 4/6] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: use devm_xxx for component related resource" to the asoc tree Mark Brown
2019-10-02  5:23 ` [alsa-devel] [PATCH 4/6] ASoC: soc-core: use devm_xxx for component related resource Kuninori Morimoto
2019-10-02  5:23 ` [alsa-devel] [PATCH 5/6] ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card() Kuninori Morimoto
2019-10-02  7:42   ` Daniel Baluta
2019-10-02  7:59     ` Kuninori Morimoto
2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-core: setup card->rtd_num at snd_soc_instantiate_card()" to the asoc tree Mark Brown
2019-10-02  5:23 ` [alsa-devel] [PATCH 6/6] ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume() Kuninori Morimoto
2019-10-04 17:52   ` [alsa-devel] Applied "ASoC: soc-ops: use snd_soc_card_get_kcontrol() at snd_soc_limit_volume()" to the asoc tree Mark Brown

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).