* [PATCH] ALSA: ice1712: Fix missing snd_card_free() at probe error
@ 2026-08-19 8:49 Haotian Zhang
2026-08-19 12:53 ` Takashi Iwai
0 siblings, 1 reply; 3+ messages in thread
From: Haotian Zhang @ 2026-08-19 8:49 UTC (permalink / raw)
To: perex, tiwai; +Cc: linux-sound, linux-kernel, Haotian Zhang
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>
---
sound/pci/ice1712/ice1712.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 1e39b985bef2..745af0c7020e 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -2539,7 +2539,7 @@ static int snd_ice1712_probe(struct pci_dev *pci,
err = snd_ice1712_create(card, pci, model[dev], omni[dev],
cs8427_timeout[dev], dxr_enable[dev]);
if (err < 0)
- return err;
+ goto error;
for (tbl = card_tables; *tbl; tbl++) {
for (c = *tbl; c->subvendor; c++) {
@@ -2550,7 +2550,7 @@ static int snd_ice1712_probe(struct pci_dev *pci,
if (c->chip_init) {
err = c->chip_init(ice);
if (err < 0)
- return err;
+ goto error;
}
ice->card_info = c;
goto __found;
@@ -2562,32 +2562,32 @@ static int snd_ice1712_probe(struct pci_dev *pci,
err = snd_ice1712_pcm_profi(ice, pcm_dev++);
if (err < 0)
- return err;
+ goto error;
if (ice_has_con_ac97(ice)) {
err = snd_ice1712_pcm(ice, pcm_dev++);
if (err < 0)
- return err;
+ goto error;
}
err = snd_ice1712_ac97_mixer(ice);
if (err < 0)
- return err;
+ goto error;
err = snd_ice1712_build_controls(ice);
if (err < 0)
- return err;
+ goto error;
if (c->build_controls) {
err = c->build_controls(ice);
if (err < 0)
- return err;
+ goto error;
}
if (ice_has_con_ac97(ice)) {
err = snd_ice1712_pcm_ds(ice, pcm_dev++);
if (err < 0)
- return err;
+ goto error;
}
if (!c->no_mpu401) {
@@ -2597,7 +2597,7 @@ static int snd_ice1712_probe(struct pci_dev *pci,
MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
-1, &ice->rmidi[0]);
if (err < 0)
- return err;
+ goto error;
if (c->mpu401_1_name)
/* Preferred name available in card_info */
snprintf(ice->rmidi[0]->name,
@@ -2613,7 +2613,7 @@ static int snd_ice1712_probe(struct pci_dev *pci,
-1, &ice->rmidi[1]);
if (err < 0)
- return err;
+ goto error;
if (c->mpu401_2_name)
/* Preferred name available in card_info */
snprintf(ice->rmidi[1]->name,
@@ -2630,10 +2630,13 @@ static int snd_ice1712_probe(struct pci_dev *pci,
err = snd_card_register(card);
if (err < 0)
- return err;
+ goto error;
pci_set_drvdata(pci, card);
dev++;
return 0;
+error:
+ snd_card_free(card);
+ return err;
}
#ifdef CONFIG_PM_SLEEP
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ALSA: ice1712: Fix missing snd_card_free() at probe error
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
0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2026-08-19 12:53 UTC (permalink / raw)
To: Haotian Zhang; +Cc: perex, tiwai, linux-sound, linux-kernel
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.
thanks,
Takashi
-- 8< --
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -2519,8 +2519,8 @@ static int snd_ice1712_create(struct snd_card *card,
static struct snd_ice1712_card_info no_matched;
-static int snd_ice1712_probe(struct pci_dev *pci,
- const struct pci_device_id *pci_id)
+static int __snd_ice1712_probe(struct pci_dev *pci,
+ const struct pci_device_id *pci_id)
{
static int dev;
struct snd_card *card;
@@ -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;
@@ -2644,6 +2644,12 @@ static int snd_ice1712_probe(struct pci_dev *pci,
return 0;
}
+static int snd_ice1712_probe(struct pci_dev *pci,
+ const struct pci_device_id *pci_id)
+{
+ return snd_card_free_on_error(&pci->dev, __snd_ice1712_probe(pci, pci_id));
+}
+
#ifdef CONFIG_PM_SLEEP
static int snd_ice1712_suspend(struct device *dev)
{
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ALSA: ice1712: Fix missing snd_card_free() at probe error
2026-08-19 12:53 ` Takashi Iwai
@ 2026-08-19 13:47 ` Takashi Iwai
0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2026-08-19 13:47 UTC (permalink / raw)
To: Haotian Zhang; +Cc: perex, tiwai, linux-sound, linux-kernel
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;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-19 13:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox