Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: echoaudio: Fix the missing snd_card_free() call at probe error

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: 9c211bf392bb ("ALSA: echoaudio: Allocate resources with device-managed APIs")
Reported-and-tested-by: Zheyu Ma <zheyuma97@gmail.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/CAMhUBjm2AdyEZ_-EgexdNDN7SvY4f89=4=FwAL+c0Mg0O+X50A@mail.gmail.com
Link: https://lore.kernel.org/r/20220412093141.8008-3-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+7 -2
+7 -2
sound/pci/echoaudio/echoaudio.c
··· 1970 1970 } 1971 1971 1972 1972 /* constructor */ 1973 - static int snd_echo_probe(struct pci_dev *pci, 1974 - const struct pci_device_id *pci_id) 1973 + static int __snd_echo_probe(struct pci_dev *pci, 1974 + const struct pci_device_id *pci_id) 1975 1975 { 1976 1976 static int dev; 1977 1977 struct snd_card *card; ··· 2139 2139 return 0; 2140 2140 } 2141 2141 2142 + static int snd_echo_probe(struct pci_dev *pci, 2143 + const struct pci_device_id *pci_id) 2144 + { 2145 + return snd_card_free_on_error(&pci->dev, __snd_echo_probe(pci, pci_id)); 2146 + } 2142 2147 2143 2148 2144 2149 #if defined(CONFIG_PM_SLEEP)