From: Takashi Iwai <tiwai@suse.de>
To: Haotian Zhang <vulab@iscas.ac.cn>
Cc: perex@perex.cz, tiwai@suse.com, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ALSA: ice1712: Fix missing snd_card_free() at probe error
Date: Wed, 19 Aug 2026 15:47:23 +0200 [thread overview]
Message-ID: <878q62nrx0.wl-tiwai@suse.de> (raw)
In-Reply-To: <87ik56nuf6.wl-tiwai@suse.de>
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 <vulab@iscas.ac.cn>
>
> 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;
}
next prev parent reply other threads:[~2026-08-19 13:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 8:49 [PATCH] ALSA: ice1712: Fix missing snd_card_free() at probe error Haotian Zhang
2026-08-19 12:53 ` Takashi Iwai
2026-08-19 13:47 ` Takashi Iwai [this message]
2026-08-20 1:41 ` [PATCH v2] ALSA: ice1712: Fix the card leak at probe error with the auto-cleanup Haotian Zhang
2026-08-20 8:55 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878q62nrx0.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
--cc=vulab@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.