diff options
author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2014-04-16 15:46:11 +0300 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-04-18 17:59:59 +0100 |
commit | 8931bf6208776292b1b888dd8534229f63e2eaa2 (patch) | |
tree | f84ca5386a8cf40d361fd22a6c820a94a3066675 /sound/soc/soc-devres.c | |
parent | c9eaa447e77efe77b7fa4c953bd62de8297fd6c5 (diff) | |
download | linux-8931bf6208776292b1b888dd8534229f63e2eaa2.tar.bz2 |
ASoC: Add resource managed snd_soc_register_platform()
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>
Diffstat (limited to 'sound/soc/soc-devres.c')
-rw-r--r-- | sound/soc/soc-devres.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c index 7ac745df1412..e94aa0277250 100644 --- a/sound/soc/soc-devres.c +++ b/sound/soc/soc-devres.c @@ -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); |