[PATCH 07/13] ASoC: soc-core: tidyup soc_new_pcm_runtime() alloc order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>

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@xxxxxxxxxxx>
---
 sound/soc/soc-core.c | 47 ++++++++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 552f460..d6bc6e2 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 */
@@ -378,15 +381,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
 	 */
@@ -397,27 +423,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@xxxxxxxxxxxxxxxx
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux