Skip to content

Commit eea3dd4

Browse files
mengdonglinbroonie
authored andcommitted
ASoC: topology: Only free TLV for volume mixers of a widget
This patch will check the type of embedded controls for a widget, and only free the TLV of volume mixers. Bytes controls don't have TLV. Just free the private value which is used as struct soc_mixer_control for volume mixers or soc_bytes_ext for bytes controls. No need to cast to these types before freeing it. Signed-off-by: Mengdong Lin <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 1a7dd6e commit eea3dd4

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

include/sound/soc-topology.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct snd_soc_dobj_control {
5353

5454
/* dynamic widget object */
5555
struct snd_soc_dobj_widget {
56-
unsigned int kcontrol_enum:1; /* this widget is an enum kcontrol */
56+
unsigned int kcontrol_type; /* kcontrol type: mixer, enum, bytes */
5757
};
5858

5959
/* generic dynamic object - all dynamic objects belong to this struct */

sound/soc/soc-topology.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static void remove_widget(struct snd_soc_component *comp,
489489
* Dynamic Widgets either have 1..N enum kcontrols or mixers.
490490
* The enum may either have an array of values or strings.
491491
*/
492-
if (dobj->widget.kcontrol_enum) {
492+
if (dobj->widget.kcontrol_type == SND_SOC_TPLG_TYPE_ENUM) {
493493
/* enumerated widget mixer */
494494
for (i = 0; i < w->num_kcontrols; i++) {
495495
struct snd_kcontrol *kcontrol = w->kcontrols[i];
@@ -506,16 +506,21 @@ static void remove_widget(struct snd_soc_component *comp,
506506
}
507507
kfree(w->kcontrol_news);
508508
} else {
509-
/* non enumerated widget mixer */
509+
/* volume mixer or bytes controls */
510510
for (i = 0; i < w->num_kcontrols; i++) {
511511
struct snd_kcontrol *kcontrol = w->kcontrols[i];
512-
struct soc_mixer_control *sm =
513-
(struct soc_mixer_control *) kcontrol->private_value;
514512

515-
kfree(w->kcontrols[i]->tlv.p);
513+
if (dobj->widget.kcontrol_type
514+
== SND_SOC_TPLG_TYPE_MIXER)
515+
kfree(kcontrol->tlv.p);
516516

517-
snd_ctl_remove(card, w->kcontrols[i]);
518-
kfree(sm);
517+
snd_ctl_remove(card, kcontrol);
518+
519+
/* Private value is used as struct soc_mixer_control
520+
* for volume mixers or soc_bytes_ext for bytes
521+
* controls.
522+
*/
523+
kfree((void *)kcontrol->private_value);
519524
}
520525
kfree(w->kcontrol_news);
521526
}
@@ -1439,6 +1444,7 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
14391444
struct snd_soc_dapm_widget template, *widget;
14401445
struct snd_soc_tplg_ctl_hdr *control_hdr;
14411446
struct snd_soc_card *card = tplg->comp->card;
1447+
unsigned int kcontrol_type;
14421448
int ret = 0;
14431449

14441450
if (strnlen(w->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
@@ -1494,6 +1500,7 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
14941500
case SND_SOC_TPLG_CTL_VOLSW_XR_SX:
14951501
case SND_SOC_TPLG_CTL_RANGE:
14961502
case SND_SOC_TPLG_DAPM_CTL_VOLSW:
1503+
kcontrol_type = SND_SOC_TPLG_TYPE_MIXER; /* volume mixer */
14971504
template.num_kcontrols = w->num_kcontrols;
14981505
template.kcontrol_news =
14991506
soc_tplg_dapm_widget_dmixer_create(tplg,
@@ -1508,7 +1515,7 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
15081515
case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE:
15091516
case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT:
15101517
case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE:
1511-
template.dobj.widget.kcontrol_enum = 1;
1518+
kcontrol_type = SND_SOC_TPLG_TYPE_ENUM; /* enumerated mixer */
15121519
template.num_kcontrols = w->num_kcontrols;
15131520
template.kcontrol_news =
15141521
soc_tplg_dapm_widget_denum_create(tplg,
@@ -1519,6 +1526,7 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
15191526
}
15201527
break;
15211528
case SND_SOC_TPLG_CTL_BYTES:
1529+
kcontrol_type = SND_SOC_TPLG_TYPE_BYTES; /* bytes control */
15221530
template.num_kcontrols = w->num_kcontrols;
15231531
template.kcontrol_news =
15241532
soc_tplg_dapm_widget_dbytes_create(tplg,
@@ -1555,6 +1563,7 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
15551563
}
15561564

15571565
widget->dobj.type = SND_SOC_DOBJ_WIDGET;
1566+
widget->dobj.widget.kcontrol_type = kcontrol_type;
15581567
widget->dobj.ops = tplg->ops;
15591568
widget->dobj.index = tplg->index;
15601569
kfree(template.sname);

0 commit comments

Comments
 (0)