[PATCH] ASoC: Add resource managed devm_snd_soc_register_codec()

From: Xiubo Li
Date: Fri Dec 20 2013 - 05:49:14 EST


Adds a resource managed version of snd_soc_register_codec() which makes
it possible to simplify the remove function as well as the error path
for codec drivers.

Signed-off-by: Xiubo Li <Li.Xiubo@xxxxxxxxxxxxx>
---
include/sound/soc.h | 3 +++
sound/soc/soc-devres.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 5a049d9..60d6c67 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -378,6 +378,9 @@ int snd_soc_register_codec(struct device *dev,
const struct snd_soc_codec_driver *codec_drv,
struct snd_soc_dai_driver *dai_drv, int num_dai);
void snd_soc_unregister_codec(struct device *dev);
+int devm_snd_soc_register_codec(struct device *dev,
+ const struct snd_soc_codec_driver *codec_drv,
+ struct snd_soc_dai_driver *dai_drv, int num_dai);
int 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);
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
index 7ac745d..3c8552f 100644
--- a/sound/soc/soc-devres.c
+++ b/sound/soc/soc-devres.c
@@ -125,3 +125,41 @@ int devm_snd_dmaengine_pcm_register(struct device *dev,
EXPORT_SYMBOL_GPL(devm_snd_dmaengine_pcm_register);

#endif
+
+static void devm_codec_release(struct device *dev, void *res)
+{
+ snd_soc_unregister_codec(*(struct device **)res);
+}
+
+/**
+ * devm_snd_soc_register_codec - resource managed codec registration
+ * @codec_drv: codec to register
+ * @dai_drv: DAI to register
+ * @num_dai: Number of DAIs
+ *
+ * Register a codec with automatic unregistration when the device is
+ * unregistered.
+ */
+int devm_snd_soc_register_codec(struct device *dev,
+ const struct snd_soc_codec_driver *codec_drv,
+ struct snd_soc_dai_driver *dai_drv,
+ int num_dai)
+{
+ struct device **ptr;
+ int ret;
+
+ ptr = devres_alloc(devm_codec_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ ret = snd_soc_register_codec(dev, codec_drv, dai_drv, num_dai);
+ if (ret == 0) {
+ *ptr = dev;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_snd_soc_register_codec);
--
1.8.4


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/