Skip to contentSkip to conversation

ASoC: dapm: Fix widget double free with auto-disable DAPM kcontrol

PATCH Applied Jarkko Nikula 3 participants 3 messages Apr 15, 2014 – Apr 18, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: dapm: Fix widget double free with auto-disable DAPM kcontrol

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.

---
 sound/soc/soc-dapm.c | 1 -
 1 file changed, 1 deletion(-)
sound/soc/soc-dapm.c +0 -1
index c8a780d0d057..7769b0a2bc5a 100644
@@ -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);
 }
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 34 lines · Jarkko Nikula

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()
Quoted 5 lines

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

Thanks.

Quoted 17 lines
---
  sound/soc/soc-dapm.c | 1 -
  1 file changed, 1 deletion(-)
sound/soc/soc-dapm.c +0 -1
index c8a780d0d057..7769b0a2bc5a 100644
@@ -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);
  }
maintainer Applied
#2 lore raw
In reply to Jarkko Nikula
Quoted 3 lines · Jarkko Nikula

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.