Commit 0e4ff5c8 authored by Mark Brown's avatar Mark Brown

ASoC: core: Add devm_snd_soc_register_card()

Simplify error handling and remove repetitive (and rarely executed) code
for unregistration by providing a devm_snd_soc_register() card.
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
Acked-by: default avatarLiam Girdwood <liam.r.girdwood@linux.intel.com>
parent a0b03a61
...@@ -369,6 +369,7 @@ int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, ...@@ -369,6 +369,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_register_card(struct snd_soc_card *card);
int snd_soc_unregister_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_suspend(struct device *dev);
int snd_soc_resume(struct device *dev); int snd_soc_resume(struct device *dev);
int snd_soc_poweroff(struct device *dev); int snd_soc_poweroff(struct device *dev);
......
...@@ -50,3 +50,37 @@ int devm_snd_soc_register_component(struct device *dev, ...@@ -50,3 +50,37 @@ int devm_snd_soc_register_component(struct device *dev,
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(devm_snd_soc_register_component); 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);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment