lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 20 Dec 2013 17:56:47 +0800
From:	Xiubo Li <Li.Xiubo@...escale.com>
To:	<lgirdwood@...il.com>, <broonie@...nel.org>, <perex@...ex.cz>,
	<tiwai@...e.de>, <alsa-devel@...a-project.org>
CC:	<linux-kernel@...r.kernel.org>
Subject: [PATCH] ASoC: Add resource managed devm_snd_soc_register_codec()

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@...escale.com>
---
 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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ