ASoC: Add resource managed snd_soc_register_platform()
authorPeter Ujfalusi <peter.ujfalusi@ti.com>
Wed, 16 Apr 2014 12:46:11 +0000 (15:46 +0300)
committerMark Brown <broonie@linaro.org>
Fri, 18 Apr 2014 16:59:59 +0000 (17:59 +0100)
Simplify error handling and remove repetitive (and rarely executed) code
for unregistration by providing a devm_snd_soc_register_platform()
platform.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
include/sound/soc.h
sound/soc/soc-devres.c

index 0b83168d8ff45a2ff394057ef0d172ab783f84d8..34c34d6e095c6c47cd345198c71a8d65d48c596b 100644 (file)
@@ -377,6 +377,8 @@ int snd_soc_resume(struct device *dev);
 int snd_soc_poweroff(struct device *dev);
 int snd_soc_register_platform(struct device *dev,
                const struct snd_soc_platform_driver *platform_drv);
+int devm_snd_soc_register_platform(struct device *dev,
+               const struct snd_soc_platform_driver *platform_drv);
 void snd_soc_unregister_platform(struct device *dev);
 int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
                const struct snd_soc_platform_driver *platform_drv);
index 7ac745df1412689c6adf0bf246399870b79e44e7..e94aa0277250bb45dfce46338c81daa8d2ba1b32 100644 (file)
@@ -52,6 +52,40 @@ int devm_snd_soc_register_component(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
 
+static void devm_platform_release(struct device *dev, void *res)
+{
+       snd_soc_unregister_platform(*(struct device **)res);
+}
+
+/**
+ * devm_snd_soc_register_platform - resource managed platform registration
+ * @dev: Device used to manage platform
+ * @platform: platform to register
+ *
+ * Register a platform driver with automatic unregistration when the device is
+ * unregistered.
+ */
+int devm_snd_soc_register_platform(struct device *dev,
+                       const struct snd_soc_platform_driver *platform_drv)
+{
+       struct device **ptr;
+       int ret;
+
+       ptr = devres_alloc(devm_platform_release, sizeof(*ptr), GFP_KERNEL);
+       if (!ptr)
+               return -ENOMEM;
+
+       ret = snd_soc_register_platform(dev, platform_drv);
+       if (ret == 0) {
+               *ptr = dev;
+               devres_add(dev, ptr);
+       } else {
+               devres_free(ptr);
+       }
+
+       return ret;
+}
+
 static void devm_card_release(struct device *dev, void *res)
 {
        snd_soc_unregister_card(*(struct snd_soc_card **)res);