Replace snd_soc_free_codec with snd_soc_unregister_codec
Subsystems (3)
PATCH v2 1/1 Replace snd_soc_free_codec with snd_soc_unregister_codec
The functions snd_soc_register_codec() and snd_soc_free_codec() are companion functions, but snd_soc_free_codec() releases resources (via kfree) that were not allocated by snd_soc_register_codec(). This means that the caller of snd_soc_register_codec() has to use a specific method to allocate these resources.
So we replace snd_soc_free_codec() with snd_soc_unregister_codec(). This new function only unregisters the codec but does not free the memory resources. The caller can now allocate and free the memory resources as it sees fit.
Also updated all callers of snd_soc_free_codec() to call snd_soc_unregister_codec() instead and free the resources themselves.
---
I cannot get ASoC V2 to compile on my machine, so this code is untested.
include/sound/soc-codec.h | 2 +- sound/soc/codecs/wm8350.c | 8 ++++++-- sound/soc/codecs/wm8731.c | 8 ++++++-- sound/soc/codecs/wm8750.c | 8 ++++++-- sound/soc/codecs/wm8753.c | 8 ++++++-- sound/soc/codecs/wm9712.c | 8 ++++++-- sound/soc/codecs/wm9713.c | 8 ++++++-- sound/soc/soc-core.c | 11 ++++------- 8 files changed, 41 insertions(+), 20 deletions(-)
include/sound/soc-codec.h +1 -1
@@ -160,7 +160,7 @@ struct snd_soc_codec *snd_soc_new_codec(int snd_soc_register_codec (struct snd_soc_codec *codec,struct device *dev); -void snd_soc_free_codec (struct snd_soc_codec *codec); +void snd_soc_unregister_codec (struct snd_soc_codec *codec); int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, struct snd_ac97_bus_ops *ops, struct snd_card *card,
sound/soc/codecs/wm8350.c +6 -2
@@ -1436,7 +1436,9 @@ static int wm8350_codec_probe(struct platform_device *pdev) codec_err:kfree (wm8350); prv_err: -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return ret; }
@@ -1446,7 +1448,9 @@ static int wm8350_codec_remove(struct platform_device *pdev)struct wm8350_data *wm8350 = codec->private_data;snd_soc_unregister_codec_dai (wm8350->dai); -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);kfree (wm8350);return 0 ; }
sound/soc/codecs/wm8731.c +6 -2
@@ -595,7 +595,9 @@ static int wm8731_codec_probe(struct platform_device *pdev) codec_err:kfree (wm8731); wm8731_err: -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return ret; }
@@ -606,7 +608,9 @@ static int wm8731_codec_remove(struct platform_device *pdev)snd_soc_unregister_codec_dai (wm8731->dai);kfree (wm8731); -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return 0 ; }
sound/soc/codecs/wm8750.c +6 -2
@@ -898,7 +898,9 @@ static int wm8750_codec_probe(struct platform_device *pdev) codec_err:kfree (wm8750); wm8750_err: -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return ret; }
@@ -909,7 +911,9 @@ static int wm8750_codec_remove(struct platform_device *pdev)snd_soc_unregister_codec_dai (wm8750->dai);kfree (wm8750); -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return 0 ; }static struct platform_driver wm8750_codec_driver = {
sound/soc/codecs/wm8753.c +6 -2
@@ -1584,7 +1584,9 @@ voice_err: codec_err:kfree (codec->private_data); err: -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return ret; }
@@ -1603,7 +1605,9 @@ static int wm8753_codec_remove(struct platform_device *pdev)/* free codec */ kfree (codec->private_data); -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return 0 ; }
sound/soc/codecs/wm9712.c +6 -2
@@ -715,7 +715,9 @@ aux_dai_err: codec_err:kfree (wm9712); priv_err: -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return ret; }
@@ -728,7 +730,9 @@ static int wm9712_codec_remove(struct platform_device *pdev)snd_soc_unregister_codec_dai (wm9712->aux_dai);kfree (codec->private_data); -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return 0 ; }
sound/soc/codecs/wm9713.c +6 -2
@@ -1154,7 +1154,9 @@ aux_dai_err: codec_err:kfree (wm9713); priv_err: -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return ret; }
@@ -1168,7 +1170,9 @@ static int wm9713_codec_remove(struct platform_device *pdev)snd_soc_unregister_codec_dai (wm9713->voice_dai);kfree (codec->private_data); -snd_soc_free_codec (codec); +snd_soc_unregister_codec (codec); +kfree (codec->reg_cache); +kfree (codec);return 0 ; }
sound/soc/soc-core.c +4 -7
@@ -1856,21 +1856,18 @@ int snd_soc_register_codec(struct snd_soc_codec *codec, struct device *dev)EXPORT_SYMBOL_GPL (snd_soc_register_codec);/** -* snd_soc_free_codec - unregister and free codec. +* snd_soc_unregister_codec - unregister a codec. * @codec: codec driver * -* Unregisters a codec driver with the core and frees all its resources. +* Unregisters a codec driver with the core. */ -void snd_soc_free_codec (struct snd_soc_codec *codec) +void snd_soc_unregister_codec (struct snd_soc_codec *codec) {mutex_lock (&client_mutex);list_del (&codec->list);mutex_unlock (&client_mutex); -if (codec->reg_cache) -kfree (codec->reg_cache); -kfree (codec); } -EXPORT_SYMBOL_GPL (snd_soc_free_codec); +EXPORT_SYMBOL_GPL (snd_soc_unregister_codec);/** * snd_soc_register_platform_dai - registers a platform DAI.
Signature · 1 line
1.5.5.1
Quoted 3 lines · Timur Tabi
So we replace
snd_soc_free_codec()withsnd_soc_unregister_codec(). This new function only unregisters the codec but does not free the memory resources. The caller can now allocate and free the memory resources as it sees fit.
Thanks! I've applied this locally and will push it out into the ASoC v2 git branch after some testing.
Quoted 2 lines
Also updated all callers of
snd_soc_free_codec()to callsnd_soc_unregister_codec()instead and free the resources themselves.
As discussed on IRC we should probably also convert all codec drivers to embed the struct snd_soc_codec in their private_data.