Skip to content

Commit

Permalink
ALSA: hda - Refactor alc_kcontrol_new() usages
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Takashi Iwai committed Nov 30, 2012
1 parent b9030a0 commit 668d1e9
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions sound/pci/hda/patch_realtek.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 668d1e9

Please sign in to comment.