Skip to content

Commit 2ba0176

Browse files
committed
ALSA: hda/analog - Minor optimization for SPDIF mux connections
AD HD-audio codec driver has a few code lines invoking snd_get_num_conns() and using its return value as the array index without checking. This is basically safe in all those places; at the second and later calls snd_get_num_conns() returns the value cached from the first invocation, hence the value is always consistent. However, it looks a bit confusing as if a lack of the proper check. This patch introduces a new field num_smux_conns in ad198x_spec for simplifying the code. Now we store and refer to the value more locally without invoking the extra function at each time. Reported-by: Colin King <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent c249177 commit 2ba0176

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

sound/pci/hda/patch_analog.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct ad198x_spec {
2828
hda_nid_t eapd_nid;
2929

3030
unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
31+
int num_smux_conns;
3132
};
3233

3334

@@ -453,8 +454,7 @@ static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
453454
struct ad198x_spec *spec = codec->spec;
454455
static const char * const texts2[] = { "PCM", "ADC" };
455456
static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
456-
hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
457-
int num_conns = snd_hda_get_num_conns(codec, dig_out);
457+
int num_conns = spec->num_smux_conns;
458458

459459
if (num_conns == 2)
460460
return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
@@ -481,7 +481,7 @@ static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
481481
struct ad198x_spec *spec = codec->spec;
482482
unsigned int val = ucontrol->value.enumerated.item[0];
483483
hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
484-
int num_conns = snd_hda_get_num_conns(codec, dig_out);
484+
int num_conns = spec->num_smux_conns;
485485

486486
if (val >= num_conns)
487487
return -EINVAL;
@@ -512,6 +512,7 @@ static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
512512
num_conns = snd_hda_get_num_conns(codec, dig_out);
513513
if (num_conns != 2 && num_conns != 3)
514514
return 0;
515+
spec->num_smux_conns = num_conns;
515516
if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
516517
return -ENOMEM;
517518
return 0;
@@ -730,10 +731,12 @@ static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
730731
struct snd_ctl_elem_info *uinfo)
731732
{
732733
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
734+
struct ad198x_spec *spec = codec->spec;
733735
static const char * const texts[] = {
734736
"PCM", "ADC1", "ADC2", "ADC3",
735737
};
736-
int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
738+
int num_conns = spec->num_smux_conns;
739+
737740
if (num_conns > 4)
738741
num_conns = 4;
739742
return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
@@ -756,7 +759,7 @@ static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
756759
struct ad198x_spec *spec = codec->spec;
757760
unsigned int val = ucontrol->value.enumerated.item[0];
758761
struct nid_path *path;
759-
int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
762+
int num_conns = spec->num_smux_conns;
760763

761764
if (val >= num_conns)
762765
return -EINVAL;
@@ -847,6 +850,7 @@ static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
847850
num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
848851
if (num_conns != 3 && num_conns != 4)
849852
return 0;
853+
spec->num_smux_conns = num_conns;
850854

851855
for (i = 0; i < num_conns; i++) {
852856
struct nid_path *path = snd_array_new(&spec->gen.paths);

0 commit comments

Comments
 (0)