aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_realtek.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-10-31 10:01:37 -0400
committerTakashi Iwai <tiwai@suse.de>2008-10-31 12:24:21 -0400
commitd88897eaea53f0fae62d528a24e76b8643082db3 (patch)
tree64e4956ed1a4246b0c215a11c98c2cfb2d3eaab5 /sound/pci/hda/patch_realtek.c
parentafecd78cd2ec81512d6ec451906f71d9671a0b3b (diff)
ALSA: hda - Use macros to check array overflow
Use macro to add mixer and verb elements to check the possible array overflow. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/patch_realtek.c')
-rw-r--r--sound/pci/hda/patch_realtek.c113
1 files changed, 53 insertions, 60 deletions
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index d300fc49f7e1..51479fba960e 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -716,6 +716,22 @@ static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
716#endif /* CONFIG_SND_DEBUG */ 716#endif /* CONFIG_SND_DEBUG */
717 717
718/* 718/*
719 */
720static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
721{
722 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
723 return;
724 spec->mixers[spec->num_mixers++] = mix;
725}
726
727static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
728{
729 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
730 return;
731 spec->init_verbs[spec->num_init_verbs++] = verb;
732}
733
734/*
719 * set up from the preset table 735 * set up from the preset table
720 */ 736 */
721static void setup_preset(struct alc_spec *spec, 737static void setup_preset(struct alc_spec *spec,
@@ -724,11 +740,10 @@ static void setup_preset(struct alc_spec *spec,
724 int i; 740 int i;
725 741
726 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++) 742 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
727 spec->mixers[spec->num_mixers++] = preset->mixers[i]; 743 add_mixer(spec, preset->mixers[i]);
728 for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i]; 744 for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
729 i++) 745 i++)
730 spec->init_verbs[spec->num_init_verbs++] = 746 add_verb(spec, preset->init_verbs[i]);
731 preset->init_verbs[i];
732 747
733 spec->channel_mode = preset->channel_mode; 748 spec->channel_mode = preset->channel_mode;
734 spec->num_channel_mode = preset->num_channel_mode; 749 spec->num_channel_mode = preset->num_channel_mode;
@@ -1244,7 +1259,6 @@ static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1244 .get = alc_mux_enum_get, 1259 .get = alc_mux_enum_get,
1245 .put = alc_mux_enum_put, 1260 .put = alc_mux_enum_put,
1246 }, 1261 },
1247 { } /* end */
1248}; 1262};
1249 1263
1250 1264
@@ -3893,9 +3907,9 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
3893 spec->dig_in_nid = ALC880_DIGIN_NID; 3907 spec->dig_in_nid = ALC880_DIGIN_NID;
3894 3908
3895 if (spec->kctls.list) 3909 if (spec->kctls.list)
3896 spec->mixers[spec->num_mixers++] = spec->kctls.list; 3910 add_mixer(spec, spec->kctls.list);
3897 3911
3898 spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs; 3912 add_verb(spec, alc880_volume_init_verbs);
3899 3913
3900 spec->num_mux_defs = 1; 3914 spec->num_mux_defs = 1;
3901 spec->input_mux = &spec->private_imux; 3915 spec->input_mux = &spec->private_imux;
@@ -3974,14 +3988,11 @@ static int patch_alc880(struct hda_codec *codec)
3974 if (wcap != AC_WID_AUD_IN) { 3988 if (wcap != AC_WID_AUD_IN) {
3975 spec->adc_nids = alc880_adc_nids_alt; 3989 spec->adc_nids = alc880_adc_nids_alt;
3976 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt); 3990 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3977 spec->mixers[spec->num_mixers] = 3991 add_mixer(spec, alc880_capture_alt_mixer);
3978 alc880_capture_alt_mixer;
3979 spec->num_mixers++;
3980 } else { 3992 } else {
3981 spec->adc_nids = alc880_adc_nids; 3993 spec->adc_nids = alc880_adc_nids;
3982 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids); 3994 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3983 spec->mixers[spec->num_mixers] = alc880_capture_mixer; 3995 add_mixer(spec, alc880_capture_mixer);
3984 spec->num_mixers++;
3985 } 3996 }
3986 } 3997 }
3987 3998
@@ -5298,9 +5309,9 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
5298 if (spec->autocfg.dig_out_pin) 5309 if (spec->autocfg.dig_out_pin)
5299 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID; 5310 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5300 if (spec->kctls.list) 5311 if (spec->kctls.list)
5301 spec->mixers[spec->num_mixers++] = spec->kctls.list; 5312 add_mixer(spec, spec->kctls.list);
5302 5313
5303 spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs; 5314 add_verb(spec, alc260_volume_init_verbs);
5304 5315
5305 spec->num_mux_defs = 1; 5316 spec->num_mux_defs = 1;
5306 spec->input_mux = &spec->private_imux; 5317 spec->input_mux = &spec->private_imux;
@@ -5311,13 +5322,12 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
5311 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) { 5322 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5312 spec->adc_nids = alc260_adc_nids_alt; 5323 spec->adc_nids = alc260_adc_nids_alt;
5313 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt); 5324 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5314 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer; 5325 add_mixer(spec, alc260_capture_alt_mixer);
5315 } else { 5326 } else {
5316 spec->adc_nids = alc260_adc_nids; 5327 spec->adc_nids = alc260_adc_nids;
5317 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids); 5328 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5318 spec->mixers[spec->num_mixers] = alc260_capture_mixer; 5329 add_mixer(spec, alc260_capture_mixer);
5319 } 5330 }
5320 spec->num_mixers++;
5321 5331
5322 store_pin_configs(codec); 5332 store_pin_configs(codec);
5323 return 1; 5333 return 1;
@@ -6834,15 +6844,12 @@ static int patch_alc882(struct hda_codec *codec)
6834 spec->adc_nids = alc882_adc_nids_alt; 6844 spec->adc_nids = alc882_adc_nids_alt;
6835 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt); 6845 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6836 spec->capsrc_nids = alc882_capsrc_nids_alt; 6846 spec->capsrc_nids = alc882_capsrc_nids_alt;
6837 spec->mixers[spec->num_mixers] = 6847 add_mixer(spec, alc882_capture_alt_mixer);
6838 alc882_capture_alt_mixer;
6839 spec->num_mixers++;
6840 } else { 6848 } else {
6841 spec->adc_nids = alc882_adc_nids; 6849 spec->adc_nids = alc882_adc_nids;
6842 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids); 6850 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6843 spec->capsrc_nids = alc882_capsrc_nids; 6851 spec->capsrc_nids = alc882_capsrc_nids;
6844 spec->mixers[spec->num_mixers] = alc882_capture_mixer; 6852 add_mixer(spec, alc882_capture_mixer);
6845 spec->num_mixers++;
6846 } 6853 }
6847 } 6854 }
6848 6855
@@ -8854,8 +8861,7 @@ static int alc883_parse_auto_config(struct hda_codec *codec)
8854 8861
8855 /* hack - override the init verbs */ 8862 /* hack - override the init verbs */
8856 spec->init_verbs[0] = alc883_auto_init_verbs; 8863 spec->init_verbs[0] = alc883_auto_init_verbs;
8857 spec->mixers[spec->num_mixers] = alc883_capture_mixer; 8864 add_mixer(spec, alc883_capture_mixer);
8858 spec->num_mixers++;
8859 8865
8860 return 1; /* config found */ 8866 return 1; /* config found */
8861} 8867}
@@ -10373,9 +10379,9 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
10373 spec->dig_in_nid = ALC262_DIGIN_NID; 10379 spec->dig_in_nid = ALC262_DIGIN_NID;
10374 10380
10375 if (spec->kctls.list) 10381 if (spec->kctls.list)
10376 spec->mixers[spec->num_mixers++] = spec->kctls.list; 10382 add_mixer(spec, spec->kctls.list);
10377 10383
10378 spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs; 10384 add_verb(spec, alc262_volume_init_verbs);
10379 spec->num_mux_defs = 1; 10385 spec->num_mux_defs = 1;
10380 spec->input_mux = &spec->private_imux; 10386 spec->input_mux = &spec->private_imux;
10381 10387
@@ -10752,15 +10758,12 @@ static int patch_alc262(struct hda_codec *codec)
10752 spec->adc_nids = alc262_adc_nids_alt; 10758 spec->adc_nids = alc262_adc_nids_alt;
10753 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt); 10759 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10754 spec->capsrc_nids = alc262_capsrc_nids_alt; 10760 spec->capsrc_nids = alc262_capsrc_nids_alt;
10755 spec->mixers[spec->num_mixers] = 10761 add_mixer(spec, alc262_capture_alt_mixer);
10756 alc262_capture_alt_mixer;
10757 spec->num_mixers++;
10758 } else { 10762 } else {
10759 spec->adc_nids = alc262_adc_nids; 10763 spec->adc_nids = alc262_adc_nids;
10760 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids); 10764 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10761 spec->capsrc_nids = alc262_capsrc_nids; 10765 spec->capsrc_nids = alc262_capsrc_nids;
10762 spec->mixers[spec->num_mixers] = alc262_capture_mixer; 10766 add_mixer(spec, alc262_capture_mixer);
10763 spec->num_mixers++;
10764 } 10767 }
10765 } 10768 }
10766 10769
@@ -11505,12 +11508,12 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
11505 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID; 11508 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11506 11509
11507 if (spec->kctls.list) 11510 if (spec->kctls.list)
11508 spec->mixers[spec->num_mixers++] = spec->kctls.list; 11511 add_mixer(spec, spec->kctls.list);
11509 11512
11510 if (spec->autocfg.speaker_pins[0] != 0x1d) 11513 if (spec->autocfg.speaker_pins[0] != 0x1d)
11511 spec->mixers[spec->num_mixers++] = alc268_beep_mixer; 11514 add_mixer(spec, alc268_beep_mixer);
11512 11515
11513 spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs; 11516 add_verb(spec, alc268_volume_init_verbs);
11514 spec->num_mux_defs = 1; 11517 spec->num_mux_defs = 1;
11515 spec->input_mux = &spec->private_imux; 11518 spec->input_mux = &spec->private_imux;
11516 11519
@@ -11779,15 +11782,11 @@ static int patch_alc268(struct hda_codec *codec)
11779 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) { 11782 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11780 spec->adc_nids = alc268_adc_nids_alt; 11783 spec->adc_nids = alc268_adc_nids_alt;
11781 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt); 11784 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11782 spec->mixers[spec->num_mixers] = 11785 add_mixer(spec, alc268_capture_alt_mixer);
11783 alc268_capture_alt_mixer;
11784 spec->num_mixers++;
11785 } else { 11786 } else {
11786 spec->adc_nids = alc268_adc_nids; 11787 spec->adc_nids = alc268_adc_nids;
11787 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids); 11788 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11788 spec->mixers[spec->num_mixers] = 11789 add_mixer(spec, alc268_capture_mixer);
11789 alc268_capture_mixer;
11790 spec->num_mixers++;
11791 } 11790 }
11792 spec->capsrc_nids = alc268_capsrc_nids; 11791 spec->capsrc_nids = alc268_capsrc_nids;
11793 /* set default input source */ 11792 /* set default input source */
@@ -12296,16 +12295,16 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
12296 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID; 12295 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12297 12296
12298 if (spec->kctls.list) 12297 if (spec->kctls.list)
12299 spec->mixers[spec->num_mixers++] = spec->kctls.list; 12298 add_mixer(spec, spec->kctls.list);
12300 12299
12301 /* create a beep mixer control if the pin 0x1d isn't assigned */ 12300 /* create a beep mixer control if the pin 0x1d isn't assigned */
12302 for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++) 12301 for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12303 if (spec->autocfg.input_pins[i] == 0x1d) 12302 if (spec->autocfg.input_pins[i] == 0x1d)
12304 break; 12303 break;
12305 if (i >= ARRAY_SIZE(spec->autocfg.input_pins)) 12304 if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12306 spec->mixers[spec->num_mixers++] = alc269_beep_mixer; 12305 add_mixer(spec, alc269_beep_mixer);
12307 12306
12308 spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs; 12307 add_verb(spec, alc269_init_verbs);
12309 spec->num_mux_defs = 1; 12308 spec->num_mux_defs = 1;
12310 spec->input_mux = &spec->private_imux; 12309 spec->input_mux = &spec->private_imux;
12311 /* set default input source */ 12310 /* set default input source */
@@ -12317,8 +12316,7 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
12317 if (err < 0) 12316 if (err < 0)
12318 return err; 12317 return err;
12319 12318
12320 spec->mixers[spec->num_mixers] = alc269_capture_mixer; 12319 add_mixer(spec, alc269_capture_mixer);
12321 spec->num_mixers++;
12322 12320
12323 store_pin_configs(codec); 12321 store_pin_configs(codec);
12324 return 1; 12322 return 1;
@@ -13395,17 +13393,16 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
13395 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID; 13393 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13396 13394
13397 if (spec->kctls.list) 13395 if (spec->kctls.list)
13398 spec->mixers[spec->num_mixers++] = spec->kctls.list; 13396 add_mixer(spec, spec->kctls.list);
13399 13397
13400 spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs; 13398 add_verb(spec, alc861_auto_init_verbs);
13401 13399
13402 spec->num_mux_defs = 1; 13400 spec->num_mux_defs = 1;
13403 spec->input_mux = &spec->private_imux; 13401 spec->input_mux = &spec->private_imux;
13404 13402
13405 spec->adc_nids = alc861_adc_nids; 13403 spec->adc_nids = alc861_adc_nids;
13406 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids); 13404 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13407 spec->mixers[spec->num_mixers] = alc861_capture_mixer; 13405 add_mixer(spec, alc861_capture_mixer);
13408 spec->num_mixers++;
13409 13406
13410 store_pin_configs(codec); 13407 store_pin_configs(codec);
13411 return 1; 13408 return 1;
@@ -14507,10 +14504,9 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
14507 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID; 14504 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14508 14505
14509 if (spec->kctls.list) 14506 if (spec->kctls.list)
14510 spec->mixers[spec->num_mixers++] = spec->kctls.list; 14507 add_mixer(spec, spec->kctls.list);
14511 14508
14512 spec->init_verbs[spec->num_init_verbs++] 14509 add_verb(spec, alc861vd_volume_init_verbs);
14513 = alc861vd_volume_init_verbs;
14514 14510
14515 spec->num_mux_defs = 1; 14511 spec->num_mux_defs = 1;
14516 spec->input_mux = &spec->private_imux; 14512 spec->input_mux = &spec->private_imux;
@@ -14577,7 +14573,7 @@ static int patch_alc861vd(struct hda_codec *codec)
14577 spec->stream_name_analog = "ALC660-VD Analog"; 14573 spec->stream_name_analog = "ALC660-VD Analog";
14578 spec->stream_name_digital = "ALC660-VD Digital"; 14574 spec->stream_name_digital = "ALC660-VD Digital";
14579 /* always turn on EAPD */ 14575 /* always turn on EAPD */
14580 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs; 14576 add_verb(spec, alc660vd_eapd_verbs);
14581 } else { 14577 } else {
14582 spec->stream_name_analog = "ALC861VD Analog"; 14578 spec->stream_name_analog = "ALC861VD Analog";
14583 spec->stream_name_digital = "ALC861VD Digital"; 14579 spec->stream_name_digital = "ALC861VD Digital";
@@ -14593,8 +14589,7 @@ static int patch_alc861vd(struct hda_codec *codec)
14593 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids); 14589 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14594 spec->capsrc_nids = alc861vd_capsrc_nids; 14590 spec->capsrc_nids = alc861vd_capsrc_nids;
14595 14591
14596 spec->mixers[spec->num_mixers] = alc861vd_capture_mixer; 14592 add_mixer(spec, alc861vd_capture_mixer);
14597 spec->num_mixers++;
14598 14593
14599 spec->vmaster_nid = 0x02; 14594 spec->vmaster_nid = 0x02;
14600 14595
@@ -16335,22 +16330,20 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
16335 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID; 16330 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16336 16331
16337 if (spec->kctls.list) 16332 if (spec->kctls.list)
16338 spec->mixers[spec->num_mixers++] = spec->kctls.list; 16333 add_mixer(spec, spec->kctls.list);
16339 16334
16340 spec->num_mux_defs = 1; 16335 spec->num_mux_defs = 1;
16341 spec->input_mux = &spec->private_imux; 16336 spec->input_mux = &spec->private_imux;
16342 16337
16343 spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs; 16338 add_verb(spec, alc662_auto_init_verbs);
16344 if (codec->vendor_id == 0x10ec0663) 16339 if (codec->vendor_id == 0x10ec0663)
16345 spec->init_verbs[spec->num_init_verbs++] = 16340 add_verb(spec, alc663_auto_init_verbs);
16346 alc663_auto_init_verbs;
16347 16341
16348 err = alc_auto_add_mic_boost(codec); 16342 err = alc_auto_add_mic_boost(codec);
16349 if (err < 0) 16343 if (err < 0)
16350 return err; 16344 return err;
16351 16345
16352 spec->mixers[spec->num_mixers] = alc662_capture_mixer; 16346 add_mixer(spec, alc662_capture_mixer);
16353 spec->num_mixers++;
16354 16347
16355 store_pin_configs(codec); 16348 store_pin_configs(codec);
16356 return 1; 16349 return 1;