aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_realtek.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2012-11-29 08:10:17 -0500
committerTakashi Iwai <tiwai@suse.de>2012-11-30 04:55:44 -0500
commit668d1e9673eddf7df3232e24a69dec8deba7331b (patch)
treefaf753a3709e5bd9e1d5b07f2048c5f079d24be1 /sound/pci/hda/patch_realtek.c
parentb9030a005d5810ab9e3683469d928aa0b537a4c4 (diff)
ALSA: hda - Refactor alc_kcontrol_new() usages
Allocate the name string and assign the structure in alc_kcontrol_new() itself to reduce the code. 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.c46
1 files changed, 18 insertions, 28 deletions
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index c7369a6764ef..6d57547aecac 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -903,22 +903,25 @@ static const struct snd_kcontrol_new alc_automute_mode_enum = {
903 .put = alc_automute_mode_put, 903 .put = alc_automute_mode_put,
904}; 904};
905 905
906static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec) 906static struct snd_kcontrol_new *
907alc_kcontrol_new(struct alc_spec *spec, const char *name,
908 const struct snd_kcontrol_new *temp)
907{ 909{
908 return snd_array_new(&spec->kctls); 910 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
911 if (!knew)
912 return NULL;
913 *knew = *temp;
914 knew->name = kstrdup(name, GFP_KERNEL);
915 if (!knew->name)
916 return NULL;
917 return knew;
909} 918}
910 919
911static int alc_add_automute_mode_enum(struct hda_codec *codec) 920static int alc_add_automute_mode_enum(struct hda_codec *codec)
912{ 921{
913 struct alc_spec *spec = codec->spec; 922 struct alc_spec *spec = codec->spec;
914 struct snd_kcontrol_new *knew;
915 923
916 knew = alc_kcontrol_new(spec); 924 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
917 if (!knew)
918 return -ENOMEM;
919 *knew = alc_automute_mode_enum;
920 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
921 if (!knew->name)
922 return -ENOMEM; 925 return -ENOMEM;
923 return 0; 926 return 0;
924} 927}
@@ -1756,12 +1759,9 @@ static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1756static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid) 1759static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1757{ 1760{
1758 struct alc_spec *spec = codec->spec; 1761 struct alc_spec *spec = codec->spec;
1759 struct snd_kcontrol_new *knew = alc_kcontrol_new(spec); 1762
1760 if (!knew) 1763 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1761 return -ENOMEM; 1764 &alc_inv_dmic_sw))
1762 *knew = alc_inv_dmic_sw;
1763 knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL);
1764 if (!knew->name)
1765 return -ENOMEM; 1765 return -ENOMEM;
1766 spec->inv_dmic_fixup = 1; 1766 spec->inv_dmic_fixup = 1;
1767 spec->inv_dmic_muted = 0; 1767 spec->inv_dmic_muted = 0;
@@ -2537,13 +2537,9 @@ static int add_control(struct alc_spec *spec, int type, const char *name,
2537{ 2537{
2538 struct snd_kcontrol_new *knew; 2538 struct snd_kcontrol_new *knew;
2539 2539
2540 knew = alc_kcontrol_new(spec); 2540 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
2541 if (!knew) 2541 if (!knew)
2542 return -ENOMEM; 2542 return -ENOMEM;
2543 *knew = alc_control_templates[type];
2544 knew->name = kstrdup(name, GFP_KERNEL);
2545 if (!knew->name)
2546 return -ENOMEM;
2547 knew->index = cidx; 2543 knew->index = cidx;
2548 if (get_amp_nid_(val)) 2544 if (get_amp_nid_(val))
2549 knew->subdevice = HDA_SUBDEV_AMP_FLAG; 2545 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
@@ -3986,14 +3982,8 @@ static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3986 struct alc_spec *spec = codec->spec; 3982 struct alc_spec *spec = codec->spec;
3987 3983
3988 if (spec->multi_ios > 0) { 3984 if (spec->multi_ios > 0) {
3989 struct snd_kcontrol_new *knew; 3985 if (!alc_kcontrol_new(spec, "Channel Mode",
3990 3986 &alc_auto_channel_mode_enum))
3991 knew = alc_kcontrol_new(spec);
3992 if (!knew)
3993 return -ENOMEM;
3994 *knew = alc_auto_channel_mode_enum;
3995 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3996 if (!knew->name)
3997 return -ENOMEM; 3987 return -ENOMEM;
3998 } 3988 }
3999 return 0; 3989 return 0;