Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: dapm: Fix widget double free with auto-disable DAPM kcontrol
@ 2014-04-15 13:58 Jarkko Nikula
  2014-04-15 18:15 ` Lars-Peter Clausen
  2014-04-18 17:08 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Jarkko Nikula @ 2014-04-15 13:58 UTC (permalink / raw)
  To: alsa-devel
  Cc: Mark Brown, Lars-Peter Clausen, Liam Girdwood, Jarkko Nikula,
	stable

Commit 9e1fda4ae158 ("ASoC: dapm: Implement mixer input auto-disable") is trying to
free the widget it allocated by snd_soc_dapm_new_control() call in
dapm_kcontrol_data_alloc() by adding kfree(data->widget) to dapm_kcontrol_free().

This is causing a widget double free with auto-disabled DAPM kcontrols in sound card
unregistration because widgets are already freed before dapm_kcontrol_free() is
called.

Reason for that is all widgets are added into dapm->card->widgets list in
snd_soc_dapm_new_control() and freed in dapm_free_widgets() during execution of
snd_soc_dapm_free().

Now snd_soc_dapm_free() calls for different DAPM contexts happens before
snd_card_free() call from where the call chain to dapm_kcontrol_free() begins:

soc_cleanup_card_resources()
  soc_remove_dai_links()
    soc_remove_link_dais()
      snd_soc_dapm_free(&cpu_dai->dapm)
    soc_remove_link_components()
      soc_remove_platform()
        snd_soc_dapm_free(&platform->dapm)
      soc_remove_codec()
        snd_soc_dapm_free(&codec->dapm)
  snd_soc_dapm_free(&card->dapm)
  snd_card_free()
    snd_card_do_free()
      snd_device_free_all()
        snd_device_free()
          snd_ctl_dev_free()
            snd_ctl_remove()
              snd_ctl_free_one()
                dapm_kcontrol_free()

This wasn't making harm with ordinary DAPM kcontrols since data->widget is NULL for
them.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: stable <stable@vger.kernel.org> # 3.12+
---
 sound/soc/soc-dapm.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index c8a780d0d057..7769b0a2bc5a 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -254,7 +254,6 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
 static void dapm_kcontrol_free(struct snd_kcontrol *kctl)
 {
 	struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl);
-	kfree(data->widget);
 	kfree(data->wlist);
 	kfree(data);
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: dapm: Fix widget double free with auto-disable DAPM kcontrol
  2014-04-15 13:58 [PATCH] ASoC: dapm: Fix widget double free with auto-disable DAPM kcontrol Jarkko Nikula
@ 2014-04-15 18:15 ` Lars-Peter Clausen
  2014-04-18 17:08 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Lars-Peter Clausen @ 2014-04-15 18:15 UTC (permalink / raw)
  To: Jarkko Nikula; +Cc: alsa-devel, Mark Brown, Liam Girdwood, stable

On 04/15/2014 03:58 PM, Jarkko Nikula wrote:
> Commit 9e1fda4ae158 ("ASoC: dapm: Implement mixer input auto-disable") is trying to
> free the widget it allocated by snd_soc_dapm_new_control() call in
> dapm_kcontrol_data_alloc() by adding kfree(data->widget) to dapm_kcontrol_free().
>
> This is causing a widget double free with auto-disabled DAPM kcontrols in sound card
> unregistration because widgets are already freed before dapm_kcontrol_free() is
> called.
>
> Reason for that is all widgets are added into dapm->card->widgets list in
> snd_soc_dapm_new_control() and freed in dapm_free_widgets() during execution of
> snd_soc_dapm_free().
>
> Now snd_soc_dapm_free() calls for different DAPM contexts happens before
> snd_card_free() call from where the call chain to dapm_kcontrol_free() begins:
>
> soc_cleanup_card_resources()
>    soc_remove_dai_links()
>      soc_remove_link_dais()
>        snd_soc_dapm_free(&cpu_dai->dapm)
>      soc_remove_link_components()
>        soc_remove_platform()
>          snd_soc_dapm_free(&platform->dapm)
>        soc_remove_codec()
>          snd_soc_dapm_free(&codec->dapm)
>    snd_soc_dapm_free(&card->dapm)
>    snd_card_free()
>      snd_card_do_free()
>        snd_device_free_all()
>          snd_device_free()
>            snd_ctl_dev_free()
>              snd_ctl_remove()
>                snd_ctl_free_one()
>                  dapm_kcontrol_free()
>
> This wasn't making harm with ordinary DAPM kcontrols since data->widget is NULL for
> them.
>
> Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> Cc: stable <stable@vger.kernel.org> # 3.12+

Acked-by: Lars-Peter Clausen <lars@metafoo.de>

Thanks.

> ---
>   sound/soc/soc-dapm.c | 1 -
>   1 file changed, 1 deletion(-)
>
> diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
> index c8a780d0d057..7769b0a2bc5a 100644
> --- a/sound/soc/soc-dapm.c
> +++ b/sound/soc/soc-dapm.c
> @@ -254,7 +254,6 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
>   static void dapm_kcontrol_free(struct snd_kcontrol *kctl)
>   {
>   	struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl);
> -	kfree(data->widget);
>   	kfree(data->wlist);
>   	kfree(data);
>   }
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: dapm: Fix widget double free with auto-disable DAPM kcontrol
  2014-04-15 13:58 [PATCH] ASoC: dapm: Fix widget double free with auto-disable DAPM kcontrol Jarkko Nikula
  2014-04-15 18:15 ` Lars-Peter Clausen
@ 2014-04-18 17:08 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2014-04-18 17:08 UTC (permalink / raw)
  To: Jarkko Nikula; +Cc: alsa-devel, Lars-Peter Clausen, Liam Girdwood, stable

[-- Attachment #1: Type: text/plain, Size: 386 bytes --]

On Tue, Apr 15, 2014 at 04:58:09PM +0300, Jarkko Nikula wrote:
> Commit 9e1fda4ae158 ("ASoC: dapm: Implement mixer input auto-disable") is trying to
> free the widget it allocated by snd_soc_dapm_new_control() call in
> dapm_kcontrol_data_alloc() by adding kfree(data->widget) to dapm_kcontrol_free().

Applied, thanks.  Please keep your commit messages word wrapped within
80 columns.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-18 17:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-15 13:58 [PATCH] ASoC: dapm: Fix widget double free with auto-disable DAPM kcontrol Jarkko Nikula
2014-04-15 18:15 ` Lars-Peter Clausen
2014-04-18 17:08 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox