ALSA: hda - Refactor alc_kcontrol_new() usages
authorTakashi Iwai <tiwai@suse.de>
Thu, 29 Nov 2012 13:10:17 +0000 (14:10 +0100)
committerTakashi Iwai <tiwai@suse.de>
Fri, 30 Nov 2012 09:55:44 +0000 (10:55 +0100)
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>
sound/pci/hda/patch_realtek.c

index c7369a6764effe230dea39c965a60d6105069af9..6d57547aecac723329a8370ca234d8317fe4ee79 100644 (file)
@@ -903,22 +903,25 @@ static const struct snd_kcontrol_new alc_automute_mode_enum = {
        .put = alc_automute_mode_put,
 };
 
-static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
+static struct snd_kcontrol_new *
+alc_kcontrol_new(struct alc_spec *spec, const char *name,
+                const struct snd_kcontrol_new *temp)
 {
-       return snd_array_new(&spec->kctls);
+       struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
+       if (!knew)
+               return NULL;
+       *knew = *temp;
+       knew->name = kstrdup(name, GFP_KERNEL);
+       if (!knew->name)
+               return NULL;
+       return knew;
 }
 
 static int alc_add_automute_mode_enum(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
-       struct snd_kcontrol_new *knew;
 
-       knew = alc_kcontrol_new(spec);
-       if (!knew)
-               return -ENOMEM;
-       *knew = alc_automute_mode_enum;
-       knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
-       if (!knew->name)
+       if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
                return -ENOMEM;
        return 0;
 }
@@ -1756,12 +1759,9 @@ static const struct snd_kcontrol_new alc_inv_dmic_sw = {
 static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
 {
        struct alc_spec *spec = codec->spec;
-       struct snd_kcontrol_new *knew = alc_kcontrol_new(spec);
-       if (!knew)
-               return -ENOMEM;
-       *knew = alc_inv_dmic_sw;
-       knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL);
-       if (!knew->name)
+
+       if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
+                             &alc_inv_dmic_sw))
                return -ENOMEM;
        spec->inv_dmic_fixup = 1;
        spec->inv_dmic_muted = 0;
@@ -2537,13 +2537,9 @@ static int add_control(struct alc_spec *spec, int type, const char *name,
 {
        struct snd_kcontrol_new *knew;
 
-       knew = alc_kcontrol_new(spec);
+       knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
        if (!knew)
                return -ENOMEM;
-       *knew = alc_control_templates[type];
-       knew->name = kstrdup(name, GFP_KERNEL);
-       if (!knew->name)
-               return -ENOMEM;
        knew->index = cidx;
        if (get_amp_nid_(val))
                knew->subdevice = HDA_SUBDEV_AMP_FLAG;
@@ -3986,14 +3982,8 @@ static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
        struct alc_spec *spec = codec->spec;
 
        if (spec->multi_ios > 0) {
-               struct snd_kcontrol_new *knew;
-
-               knew = alc_kcontrol_new(spec);
-               if (!knew)
-                       return -ENOMEM;
-               *knew = alc_auto_channel_mode_enum;
-               knew->name = kstrdup("Channel Mode", GFP_KERNEL);
-               if (!knew->name)
+               if (!alc_kcontrol_new(spec, "Channel Mode",
+                                     &alc_auto_channel_mode_enum))
                        return -ENOMEM;
        }
        return 0;