Skip to content

Commit

Permalink
ALSA: via82xx: Fix the missing snd_card_free() call at probe error
Browse files Browse the repository at this point in the history
The previous cleanup with devres may lead to the incorrect release
orders at the probe error handling due to the devres's nature.  Until
we register the card, snd_card_free() has to be called at first for
releasing the stuff properly when the driver tries to manage and
release the stuff via card->private_free().

This patch fixes it by calling snd_card_free() on the error from the
probe callback using a new helper function.

Fixes: afaf997 ("ALSA: via82xx: Allocate resources with device-managed APIs")
Cc: <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Apr 12, 2022
1 parent b087a38 commit 27a0963
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions sound/pci/via82xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2458,8 +2458,8 @@ static int check_dxs_list(struct pci_dev *pci, int revision)
return VIA_DXS_48K;
};

static int snd_via82xx_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
static int __snd_via82xx_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
{
struct snd_card *card;
struct via82xx *chip;
Expand Down Expand Up @@ -2569,6 +2569,12 @@ static int snd_via82xx_probe(struct pci_dev *pci,
return 0;
}

static int snd_via82xx_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
{
return snd_card_free_on_error(&pci->dev, __snd_via82xx_probe(pci, pci_id));
}

static struct pci_driver via82xx_driver = {
.name = KBUILD_MODNAME,
.id_table = snd_via82xx_ids,
Expand Down
10 changes: 8 additions & 2 deletions sound/pci/via82xx_modem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,8 @@ static int snd_via82xx_create(struct snd_card *card,
}


static int snd_via82xx_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
static int __snd_via82xx_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
{
struct snd_card *card;
struct via82xx_modem *chip;
Expand Down Expand Up @@ -1157,6 +1157,12 @@ static int snd_via82xx_probe(struct pci_dev *pci,
return 0;
}

static int snd_via82xx_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
{
return snd_card_free_on_error(&pci->dev, __snd_via82xx_probe(pci, pci_id));
}

static struct pci_driver via82xx_modem_driver = {
.name = KBUILD_MODNAME,
.id_table = snd_via82xx_modem_ids,
Expand Down

0 comments on commit 27a0963

Please sign in to comment.