linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jerome Brunet <jbrunet@baylibre.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
	Mark Brown <broonie@kernel.org>
Cc: Jerome Brunet <jbrunet@baylibre.com>,
	alsa-devel@alsa-project.org, Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org,
	linux-rpi-kernel <linux-rpi-kernel@lists.infradead.org>
Subject: [RFT/DONTMERGE] ASoC: devm_snd_soc_register_component fixup
Date: Mon, 17 Feb 2020 19:06:26 +0100	[thread overview]
Message-ID: <20200217180626.593909-1-jbrunet@baylibre.com> (raw)
In-Reply-To: <20557448-d6d2-7584-e2ac-c46d337e1778@samsung.com>

Hi Marek, would you mind trying the following patch. It should target the
component removal intead of removing them all. I'd like to comfirm this is
your problem before pushing in this direction. Thanks

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
 include/sound/soc.h                   |  1 +
 sound/soc/soc-core.c                  |  8 +++++++
 sound/soc/soc-devres.c                | 32 ++++++++++++++++++---------
 sound/soc/soc-generic-dmaengine-pcm.c |  2 +-
 4 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index f0e4f36f83bf..e5bfe2609110 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -442,6 +442,7 @@ int snd_soc_add_component(struct device *dev,
 		const struct snd_soc_component_driver *component_driver,
 		struct snd_soc_dai_driver *dai_drv,
 		int num_dai);
+void snd_soc_del_component(struct snd_soc_component *component);
 int snd_soc_register_component(struct device *dev,
 			 const struct snd_soc_component_driver *component_driver,
 			 struct snd_soc_dai_driver *dai_drv, int num_dai);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 6a58a8f6e3c4..bf6a64fbfa52 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2599,6 +2599,14 @@ static void snd_soc_del_component_unlocked(struct snd_soc_component *component)
 	list_del(&component->list);
 }
 
+void snd_soc_del_component(struct snd_soc_component *component)
+{
+	mutex_lock(&client_mutex);
+	snd_soc_del_component_unlocked(component);
+	mutex_unlock(&client_mutex);
+}
+EXPORT_SYMBOL_GPL(snd_soc_del_component);
+
 int snd_soc_add_component(struct device *dev,
 			struct snd_soc_component *component,
 			const struct snd_soc_component_driver *component_driver,
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
index a9ea172a66a7..d5e9e2bed2ce 100644
--- a/sound/soc/soc-devres.c
+++ b/sound/soc/soc-devres.c
@@ -11,7 +11,7 @@
 
 static void devm_component_release(struct device *dev, void *res)
 {
-	snd_soc_unregister_component(*(struct device **)res);
+	snd_soc_del_component(*(struct snd_soc_component **)res);
 }
 
 /**
@@ -28,21 +28,31 @@ int devm_snd_soc_register_component(struct device *dev,
 			 const struct snd_soc_component_driver *cmpnt_drv,
 			 struct snd_soc_dai_driver *dai_drv, int num_dai)
 {
-	struct device **ptr;
-	int ret;
+	struct snd_soc_component *component;
+	struct snd_soc_component **ptr;
+	int ret = -ENOMEM;
+
+	component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
+	if (!component)
+		return -ENOMEM;
 
 	ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
 	if (!ptr)
-		return -ENOMEM;
+	        goto err_devres;
 
-	ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
-	if (ret == 0) {
-		*ptr = dev;
-		devres_add(dev, ptr);
-	} else {
-		devres_free(ptr);
-	}
+	ret = snd_soc_add_component(dev, component, cmpnt_drv, dai_drv,
+				    num_dai);
+	if (ret)
+		goto err_add;
+
+	*ptr = component;
+	devres_add(dev, ptr);
+	return 0;
 
+err_add:
+	devres_free(ptr);
+err_devres:
+	devm_kfree(dev, component);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index 2cc25651661c..a33f21ce2d7a 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -474,7 +474,7 @@ void snd_dmaengine_pcm_unregister(struct device *dev)
 
 	pcm = soc_component_to_pcm(component);
 
-	snd_soc_unregister_component(dev);
+	snd_soc_del_component(component);
 	dmaengine_pcm_release_chan(pcm);
 	kfree(pcm);
 }
-- 
2.24.1


  parent reply	other threads:[~2020-02-17 18:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 13:47 [PATCH RFC] ASoC: core: ensure component names are unique Jerome Brunet
2020-02-14 20:56 ` Applied "ASoC: core: ensure component names are unique" to the asoc tree Mark Brown
     [not found]   ` <CGME20200217121336eucas1p2deb35417f5c4646a89762fd6146c3cf9@eucas1p2.samsung.com>
2020-02-17 12:13     ` Marek Szyprowski
2020-02-17 13:18       ` Jerome Brunet
2020-02-17 14:36         ` Marek Szyprowski
2020-02-17 17:23           ` Stefan Wahren
2020-02-17 18:06           ` Jerome Brunet [this message]
2020-02-18  6:47             ` [RFT/DONTMERGE] ASoC: devm_snd_soc_register_component fixup Marek Szyprowski
2020-02-18  9:32               ` Jerome Brunet
2020-02-17 13:22       ` [alsa-devel] Applied "ASoC: core: ensure component names are unique" to the asoc tree Peter Ujfalusi
2020-02-18 18:55   ` Jerome Brunet
2020-02-18 19:03     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200217180626.593909-1-jbrunet@baylibre.com \
    --to=jbrunet@baylibre.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=m.szyprowski@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).