Re: [v2 PATCH 1/2] ALSA: hda/intel: Fix error handling in azx_probe()

Takashi Iwai
2023-07-18T12:17:46Z

On Tue, 18 Jul 2023 13:57:33 +0200,
Maarten Lankhorst wrote:
>
>
> Make sure azx is freed after azx_create() succeeded and an error was
> encountered.
>
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
> sound/pci/hda/hda_intel.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
> index 5af1138e745bc..196ca76ac43ad 100644
> --- a/sound/pci/hda/hda_intel.c
> +++ b/sound/pci/hda/hda_intel.c
> @@ -2150,7 +2150,7 @@ static int azx_probe(struct pci_dev *pci,
> err = register_vga_switcheroo(chip);
> if (err < 0) {
> dev_err(card->dev, "Error registering vga_switcheroo client\n");
> - goto out_free;
> + goto out_azx_free;
> }
>
> if (check_hdmi_disabled(pci)) {
> @@ -2169,7 +2169,7 @@ static int azx_probe(struct pci_dev *pci,
> &pci->dev, GFP_KERNEL, card,
> azx_firmware_cb);
> if (err < 0)
> - goto out_free;
> + goto out_azx_free;
> schedule_probe = false; /* continued in azx_firmware_cb() */
> }
> #endif /* CONFIG_SND_HDA_PATCH_LOADER */
> @@ -2187,6 +2187,9 @@ static int azx_probe(struct pci_dev *pci,
> complete_all(&hda->probe_wait);
> return 0;
>
> +out_azx_free:
> + azx_free(chip);

This is superfluous. Once when azx_create() succeeds, azx_free() is
called from snd_card_free(). That is...

> + pci_set_drvdata(pci, NULL);

... only this call was missing. And this can be put under out_free
label, as this is safe to call at any exit path. So, it'll be a
oneliner patch.

thanks,

Takashi

> out_free:
> snd_card_free(card);
> return err;
> --
> 2.39.2
>