Skip to content

Commit

Permalink
ALSA: hda - Don't add elements of other codecs to vmaster slave
Browse files Browse the repository at this point in the history
When a virtual mater control is created, the driver looks for slave
elements from the assigned card instance.  But this may include the
elements of other codecs when multiple codecs are on the same HD-audio
bus.  This works at the first time, but it'll give Oops when it's once
freed and re-created via reconfig sysfs.

This patch changes the element-look-up strategy to limit only to the
mixer elements of the same codec.

Reported-by: David Henningsson <david.henningsson@canonical.com>
Cc: <stable@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Nov 10, 2011
1 parent 7fb4f39 commit aeb4b88
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions sound/pci/hda/hda_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,39 @@ int snd_hda_codec_reset(struct hda_codec *codec)
return 0;
}

typedef int (*map_slave_func_t)(void *, struct snd_kcontrol *);

/* apply the function to all matching slave ctls in the mixer list */
static int map_slaves(struct hda_codec *codec, const char * const *slaves,
map_slave_func_t func, void *data)
{
struct hda_nid_item *items;
const char * const *s;
int i, err;

items = codec->mixers.list;
for (i = 0; i < codec->mixers.used; i++) {
struct snd_kcontrol *sctl = items[i].kctl;
if (!sctl || !sctl->id.name ||
sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER)
continue;
for (s = slaves; *s; s++) {
if (!strcmp(sctl->id.name, *s)) {
err = func(data, sctl);
if (err)
return err;
break;
}
}
}
return 0;
}

static int check_slave_present(void *data, struct snd_kcontrol *sctl)
{
return 1;
}

/**
* snd_hda_add_vmaster - create a virtual master control and add slaves
* @codec: HD-audio codec
Expand All @@ -2351,12 +2384,10 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
unsigned int *tlv, const char * const *slaves)
{
struct snd_kcontrol *kctl;
const char * const *s;
int err;

for (s = slaves; *s && !snd_hda_find_mixer_ctl(codec, *s); s++)
;
if (!*s) {
err = map_slaves(codec, slaves, check_slave_present, NULL);
if (err != 1) {
snd_printdd("No slave found for %s\n", name);
return 0;
}
Expand All @@ -2367,23 +2398,10 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
if (err < 0)
return err;

for (s = slaves; *s; s++) {
struct snd_kcontrol *sctl;
int i = 0;
for (;;) {
sctl = _snd_hda_find_mixer_ctl(codec, *s, i);
if (!sctl) {
if (!i)
snd_printdd("Cannot find slave %s, "
"skipped\n", *s);
break;
}
err = snd_ctl_add_slave(kctl, sctl);
if (err < 0)
return err;
i++;
}
}
err = map_slaves(codec, slaves, (map_slave_func_t)snd_ctl_add_slave,
kctl);
if (err < 0)
return err;
return 0;
}
EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
Expand Down

0 comments on commit aeb4b88

Please sign in to comment.