Skip to content

Commit

Permalink
ALSA: hda/via - Rewrite with error goto
Browse files Browse the repository at this point in the history
Currently VIA codec driver invokes via_free() at each place of the
error path.  Move the error handling to the end of each function
commonly and do goto-error as a standard idiom.

This is a preliminary patch for the further cleanups, and no
functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Jun 25, 2018
1 parent 0785b0e commit fcbdcc1
Showing 1 changed file with 60 additions and 40 deletions.
100 changes: 60 additions & 40 deletions sound/pci/hda/patch_via.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,8 @@ static int patch_vt1708(struct hda_codec *codec)

/* automatic parse from the BIOS config */
err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

/* add jack detect on/off control */
spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
Expand All @@ -700,6 +698,10 @@ static int patch_vt1708(struct hda_codec *codec)
codec->jackpoll_interval = 0;

return 0;

error:
via_free(codec);
return err;
}

static int patch_vt1709(struct hda_codec *codec)
Expand All @@ -715,12 +717,14 @@ static int patch_vt1709(struct hda_codec *codec)
spec->gen.mixer_nid = 0x18;

err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

return 0;

error:
via_free(codec);
return err;
}

static int patch_vt1708S(struct hda_codec *codec);
Expand All @@ -741,12 +745,14 @@ static int patch_vt1708B(struct hda_codec *codec)

/* automatic parse from the BIOS config */
err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

return 0;

error:
via_free(codec);
return err;
}

/* Patch for VT1708S */
Expand Down Expand Up @@ -793,14 +799,16 @@ static int patch_vt1708S(struct hda_codec *codec)

/* automatic parse from the BIOS config */
err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;

return 0;

error:
via_free(codec);
return err;
}

/* Patch for VT1702 */
Expand Down Expand Up @@ -834,14 +842,16 @@ static int patch_vt1702(struct hda_codec *codec)

/* automatic parse from the BIOS config */
err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;

return 0;

error:
via_free(codec);
return err;
}

/* Patch for VT1718S */
Expand Down Expand Up @@ -906,14 +916,16 @@ static int patch_vt1718S(struct hda_codec *codec)

/* automatic parse from the BIOS config */
err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;

return 0;

error:
via_free(codec);
return err;
}

/* Patch for VT1716S */
Expand Down Expand Up @@ -1002,17 +1014,19 @@ static int patch_vt1716S(struct hda_codec *codec)

/* automatic parse from the BIOS config */
err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;

spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;

return 0;

error:
via_free(codec);
return err;
}

/* for vt2002P */
Expand Down Expand Up @@ -1109,17 +1123,19 @@ static int patch_vt2002P(struct hda_codec *codec)

/* automatic parse from the BIOS config */
err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

if (spec->codec_type == VT1802)
spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
else
spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;

return 0;

error:
via_free(codec);
return err;
}

/* for vt1812 */
Expand Down Expand Up @@ -1150,14 +1166,16 @@ static int patch_vt1812(struct hda_codec *codec)

/* automatic parse from the BIOS config */
err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;

return 0;

error:
via_free(codec);
return err;
}

/* patch for vt3476 */
Expand Down Expand Up @@ -1187,14 +1205,16 @@ static int patch_vt3476(struct hda_codec *codec)

/* automatic parse from the BIOS config */
err = via_parse_auto_config(codec);
if (err < 0) {
via_free(codec);
return err;
}
if (err < 0)
goto error;

spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;

return 0;

error:
via_free(codec);
return err;
}

/*
Expand Down

0 comments on commit fcbdcc1

Please sign in to comment.