Re: [PATCH] ALSA: ice1712: Fix missing snd_card_free() at probe error
Takashi Iwai <[email protected]>
| Newsgroups | gmane.linux.sound,gmane.linux.kernel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 19 Aug 2026 14:53:17 +0200,
Takashi Iwai wrote:
>
> On Wed, 19 Aug 2026 10:49:59 +0200,
> Haotian Zhang wrote:
> >
> > snd_ice1712_probe() performs multiple initialization steps after
> > snd_card_new(), but directly returns on failures from later steps
> > without releasing the ALSA card, causing resource leaks when
> > probing fails.
> >
> > Route all initialization failures after snd_card_new() to a
> > common error path and call snd_card_free() before returning
> > the original error code.
> >
> > Fixes: ca642da4b33d ("ALSA: ice1712: Allocate resources with device-managed APIs")
> > Signed-off-by: Haotian Zhang <[email protected]>
>
> Actually, this was rather a forgotten replacement of snd_card_new()
> with snd_devm_card_new(), as implemented in a similar code ice1724.c.
> But the error handling before the registration is still needed (it was
> fixed later for ice1724.c, too), so it'll be something like below.
On the second thought, a more elegant alternative would be to use the
auto-cleanup with snd_card_unref. A totally untested patch below.
Takashi
-- 8< --
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -2523,7 +2523,7 @@ static int snd_ice1712_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
{
static int dev;
- struct snd_card *card;
+ struct snd_card *card __free(snd_card_unref) = NULL;
struct snd_ice1712 *ice;
int pcm_dev = 0, err;
const struct snd_ice1712_card_info * const *tbl, *c;
@@ -2535,8 +2535,8 @@ static int snd_ice1712_probe(struct pci_dev *pci,
return -ENOENT;
}
- err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
- sizeof(*ice), &card);
+ err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
+ sizeof(*ice), &card);
if (err < 0)
return err;
ice = card->private_data;
@@ -2640,6 +2640,7 @@ static int snd_ice1712_probe(struct pci_dev *pci,
if (err < 0)
return err;
pci_set_drvdata(pci, card);
+ card = NULL; /* probe succeeded, don't release as error */
dev++;
return 0;
}