ASoC: topology: Fix kcontrol name string handling.
PATCH 1/1 ASoC: topology: Fix kcontrol name string handling.
Fix the topology kcontrol string handling so that string pointer references are strdup()ed instead of being copied. This fixes issues with kcontrol templates on the stack or ones that are freed. Remember and free the strings too when topology is unloaded.
--- sound/soc/soc-topology.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
sound/soc/soc-topology.c +18 -5
@@ -530,6 +530,7 @@ static void remove_widget(struct snd_soc_component *comp,kfree (se->dobj.control.dtexts[j]);kfree (se); +kfree (w->kcontrol_news[i].name); } }else {/* volume mixer or bytes controls */
@@ -546,6 +547,7 @@ static void remove_widget(struct snd_soc_component *comp,*/ kfree ((void *)kcontrol->private_value);snd_ctl_remove (card, kcontrol); +kfree (w->kcontrol_news[i].name); } }
@@ -1256,7 +1258,9 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create(dev_dbg (tplg->dev," adding DAPM widget mixer control %s at %d\n" , mc->hdr.name, i); - kc[i].name = mc->hdr.name; + kc[i].name =kstrdup (mc->hdr.name,GFP_KERNEL ); +if (kc[i].name ==NULL ) + goto err_str; kc[i].private_value = (long )sm; kc[i].iface =SNDRV_CTL_ELEM_IFACE_MIXER ; kc[i].access = mc->hdr.access;
@@ -1304,8 +1308,10 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create( err_str:kfree (sm); err: -for (--i; i >=0 ; i--) +for (--i; i >=0 ; i--) {kfree ((void *)kc[i].private_value); +kfree (kc[i].name); + }kfree (kc);return NULL ; }
@@ -1336,7 +1342,9 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_denum_create(dev_dbg (tplg->dev," adding DAPM widget enum control %s\n" , ec->hdr.name); - kc[i].name = ec->hdr.name; + kc[i].name =kstrdup (ec->hdr.name,GFP_KERNEL ); +if (kc[i].name ==NULL ) + goto err_se; kc[i].private_value = (long )se; kc[i].iface =SNDRV_CTL_ELEM_IFACE_MIXER ; kc[i].access = ec->hdr.access;
@@ -1412,6 +1420,7 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_denum_create(kfree (se->dobj.control.dtexts[j]);kfree (se); +kfree (kc[i].name); } err:kfree (kc);
@@ -1450,7 +1459,9 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create("ASoC: adding bytes kcontrol %s with access 0x%x\n" , be->hdr.name, be->hdr.access); - kc[i].name = be->hdr.name; + kc[i].name =kstrdup (be->hdr.name,GFP_KERNEL ); +if (kc[i].name ==NULL ) + goto err; kc[i].private_value = (long )sbe; kc[i].iface =SNDRV_CTL_ELEM_IFACE_MIXER ; kc[i].access = be->hdr.access;
@@ -1480,8 +1491,10 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create(return kc; err: -for (--i; i >=0 ; i--) +for (--i; i >=0 ; i--) {kfree ((void *)kc[i].private_value); +kfree (kc[i].name); + }kfree (kc);return NULL ;
Signature · 1 line
2.14.1
Mark Brown
maintainerQuoted 4 lines · Liam Girdwood
Fix the topology kcontrol string handling so that string pointer references are strdup()ed instead of being copied. This fixes issues with kcontrol templates on the stack or ones that are freed. Remember and free the strings too when topology is unloaded.
This doesn't seem to apply against current code (I was going to apply it as a fix but it doesn't seem to apply against -next either).
Quoted 10 lines · Mark Brown
Quoted 4 lines · Liam Girdwood
Fix the topology kcontrol string handling so that string pointer references are strdup()ed instead of being copied. This fixes issues with kcontrol templates on the stack or ones that are freed. Remember and free the strings too when topology is unloaded.
This doesn't seem to apply against current code (I was going to apply it as a fix but it doesn't seem to apply against -next either).
_______________________________________________
Ok will do, Fwiw I did them against -next when you were at ELC, I guess there have been some updates between now and then.
Thanks
Liam
Mark Brown
maintainerQuoted 7 lines · Liam Girdwood
Quoted 2 lines · Mark Brown
This doesn't seem to apply against current code (I was going to apply it as a fix but it doesn't seem to apply against -next either).
Ok will do, Fwiw I did them against -next when you were at ELC, I guess there have been some updates between now and then.
It's also possible you have interdependencies between the patches - you didn't send them as a series so any ordering requirements got lost.