aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-09-16 13:02:05 -0400
committerMark Brown <broonie@linaro.org>2013-09-16 19:50:06 -0400
commit0e4ff5c806263bf40ee5409ac283b776f0c11e41 (patch)
treeeda5a0e77010c93620b288ded2b9b1cdff85a977
parenta0b03a616b08cf9d709812ff5cf7e9c0958d6807 (diff)
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: Mark Brown <broonie@linaro.org> Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
-rw-r--r--include/sound/soc.h1
-rw-r--r--sound/soc/soc-devres.c34
2 files changed, 35 insertions, 0 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index b970f019b452..d44728ab2be0 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -369,6 +369,7 @@ int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
369 369
370int snd_soc_register_card(struct snd_soc_card *card); 370int snd_soc_register_card(struct snd_soc_card *card);
371int snd_soc_unregister_card(struct snd_soc_card *card); 371int snd_soc_unregister_card(struct snd_soc_card *card);
372int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
372int snd_soc_suspend(struct device *dev); 373int snd_soc_suspend(struct device *dev);
373int snd_soc_resume(struct device *dev); 374int snd_soc_resume(struct device *dev);
374int snd_soc_poweroff(struct device *dev); 375int snd_soc_poweroff(struct device *dev);
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
index 13fe86f7c9a8..b1d732255c02 100644
--- a/sound/soc/soc-devres.c
+++ b/sound/soc/soc-devres.c
@@ -50,3 +50,37 @@ int devm_snd_soc_register_component(struct device *dev,
50 return ret; 50 return ret;
51} 51}
52EXPORT_SYMBOL_GPL(devm_snd_soc_register_component); 52EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
53
54static void devm_card_release(struct device *dev, void *res)
55{
56 snd_soc_unregister_card(*(struct snd_soc_card **)res);
57}
58
59/**
60 * devm_snd_soc_register_card - resource managed card registration
61 * @dev: Device used to manage card
62 * @card: Card to register
63 *
64 * Register a card with automatic unregistration when the device is
65 * unregistered.
66 */
67int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
68{
69 struct device **ptr;
70 int ret;
71
72 ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
73 if (!ptr)
74 return -ENOMEM;
75
76 ret = snd_soc_register_card(card);
77 if (ret == 0) {
78 *ptr = dev;
79 devres_add(dev, ptr);
80 } else {
81 devres_free(ptr);
82 }
83
84 return ret;
85}
86EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);