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

ALSA: aw2: 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() manually on the error
from the probe callback.

Fixes: 33631012cd06 ("ALSA: aw2: Allocate resources with device-managed APIs")
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20220412102636.16000-32-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+6 -2
+6 -2
sound/pci/aw2/aw2-alsa.c
··· 275 275 /* (3) Create main component */ 276 276 err = snd_aw2_create(card, pci); 277 277 if (err < 0) 278 - return err; 278 + goto error; 279 279 280 280 /* initialize mutex */ 281 281 mutex_init(&chip->mtx); ··· 294 294 /* (6) Register card instance */ 295 295 err = snd_card_register(card); 296 296 if (err < 0) 297 - return err; 297 + goto error; 298 298 299 299 /* (7) Set PCI driver data */ 300 300 pci_set_drvdata(pci, card); 301 301 302 302 dev++; 303 303 return 0; 304 + 305 + error: 306 + snd_card_free(card); 307 + return err; 304 308 } 305 309 306 310 /* open callback */