Skip to content

Commit 2044161

Browse files
adambrickmanbroonie
authored andcommitted
ASoC: wm_adsp: Pass full name to snd_ctl_notify
A call to wm_adsp_write_ctl() could cause a kernel crash if it does not retrieve a valid kcontrol from snd_soc_card_get_kcontrol(). This can happen due to a missing control name prefix. Then, snd_ctl_notify() crashes when it tries to use the id field. Modified wm_adsp_write_ctl() to incorporate the name_prefix (if applicable) such that it is able to retrieve a valid id field from the kcontrol once the platform has booted. Fixes: eb65ccd ("ASoC: wm_adsp: Expose mixer control API") Signed-off-by: Adam Brickman <[email protected]> Signed-off-by: Charles Keepax <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 6bf28e8 commit 2044161

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

sound/soc/codecs/wm_adsp.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,7 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
20492049
{
20502050
struct wm_coeff_ctl *ctl;
20512051
struct snd_kcontrol *kcontrol;
2052+
char ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
20522053
int ret;
20532054

20542055
ctl = wm_adsp_get_ctl(dsp, name, type, alg);
@@ -2059,8 +2060,25 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
20592060
return -EINVAL;
20602061

20612062
ret = wm_coeff_write_ctrl(ctl, buf, len);
2063+
if (ret)
2064+
return ret;
2065+
2066+
if (ctl->flags & WMFW_CTL_FLAG_SYS)
2067+
return 0;
2068+
2069+
if (dsp->component->name_prefix)
2070+
snprintf(ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s %s",
2071+
dsp->component->name_prefix, ctl->name);
2072+
else
2073+
snprintf(ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s",
2074+
ctl->name);
2075+
2076+
kcontrol = snd_soc_card_get_kcontrol(dsp->component->card, ctl_name);
2077+
if (!kcontrol) {
2078+
adsp_err(dsp, "Can't find kcontrol %s\n", ctl_name);
2079+
return -EINVAL;
2080+
}
20622081

2063-
kcontrol = snd_soc_card_get_kcontrol(dsp->component->card, ctl->name);
20642082
snd_ctl_notify(dsp->component->card->snd_card,
20652083
SNDRV_CTL_EVENT_MASK_VALUE, &kcontrol->id);
20662084

0 commit comments

Comments
 (0)