From: Mark Brown <broonie@kernel.org>
To: Liam Girdwood <lgirdwood@gmail.com>, Sangbeom Kim <sbkim73@samsung.com>
Cc: alsa-devel@alsa-project.org, linux-samsung-soc@vger.kernel.org,
linaro-kernel@lists.linaro.org, Mark Brown <broonie@linaro.org>
Subject: [PATCH 1/2] ASoC: core: Add devm_snd_soc_register_card()
Date: Mon, 16 Sep 2013 18:03:42 +0100 [thread overview]
Message-ID: <1379351023-28996-1-git-send-email-broonie@kernel.org> (raw)
From: Mark Brown <broonie@linaro.org>
Simplify error handling and remove repetitive (and rarely executed) code
for unregistration by providing a devm_snd_soc_register() card.
Signed-off-by: Mark Brown <broonie@linaro.org>
---
include/sound/soc.h | 1 +
sound/soc/soc-devres.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/include/sound/soc.h b/include/sound/soc.h
index f126676..7ab5d2b 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -364,6 +364,7 @@ int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
int snd_soc_register_card(struct snd_soc_card *card);
int snd_soc_unregister_card(struct snd_soc_card *card);
+int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
int snd_soc_suspend(struct device *dev);
int snd_soc_resume(struct device *dev);
int snd_soc_poweroff(struct device *dev);
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
index 13fe86f..b1d7322 100644
--- a/sound/soc/soc-devres.c
+++ b/sound/soc/soc-devres.c
@@ -50,3 +50,37 @@ int devm_snd_soc_register_component(struct device *dev,
return ret;
}
EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
+
+static void devm_card_release(struct device *dev, void *res)
+{
+ snd_soc_unregister_card(*(struct snd_soc_card **)res);
+}
+
+/**
+ * devm_snd_soc_register_card - resource managed card registration
+ * @dev: Device used to manage card
+ * @card: Card to register
+ *
+ * Register a card with automatic unregistration when the device is
+ * unregistered.
+ */
+int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
+{
+ struct device **ptr;
+ int ret;
+
+ ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ ret = snd_soc_register_card(card);
+ if (ret == 0) {
+ *ptr = dev;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
--
1.8.4.rc3
next reply other threads:[~2013-09-16 17:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-16 17:03 Mark Brown [this message]
2013-09-16 17:03 ` [PATCH 2/2] ASoC: smdk_wm8994: Use devm_snd_soc_unregister_card() Mark Brown
2013-09-16 17:48 ` [alsa-devel] [PATCH 1/2] ASoC: core: Add devm_snd_soc_register_card() Liam Girdwood
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=1379351023-28996-1-git-send-email-broonie@kernel.org \
--to=broonie@kernel.org \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@linaro.org \
--cc=lgirdwood@gmail.com \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=sbkim73@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.