Re: [PATCH] ALSA: hda: intel: Don't free card in the probe work

From: Takashi Iwai

Date: Mon Oct 12 2026 - 11:21:46 EST


On Mon, 12 Oct 2026 16:35:05 +0200,
Ali Ahmet Memiş wrote:
>
> On Mon, 12 Oct 2026 09:19:36 +0200, Takashi Iwai wrote:
> > For avoiding the card free, can it be the refcounting like below
> > instead?
>
> I tried it in QEMU and it hangs on every failed delayed probe even
> without a remove. snd_card_free() waits for the release of card_dev,
> but the reference taken in azx_probe_work() is dropped only after
> azx_probe_continue() returns, so the work never finishes:
>
> kworker/1:1+events:
> [<0>] snd_card_free+0x107/0x160
> [<0>] azx_probe_work+0x57d/0x1fa0
> [<0>] process_one_work+0x937/0x1800
> [<0>] worker_thread+0x4ba/0xd20
> [<0>] kthread+0x331/0x420
>
> It also doesn't help azx_remove() which reads the card without a
> reference before cancel_delayed_work_sync() and frees it again after
> the work.

OK, that's a problem, indeed. How about replacing snd_card_free()
with *_when_closed() version that doesn't block in addition?

--- a/sound/hda/controllers/intel.c
+++ b/sound/hda/controllers/intel.c
@@ -2450,7 +2450,7 @@ static int azx_probe_continue(struct azx *chip, bool free_on_error)
dev_warn(&pci->dev, "GPU sound probed, but not operational: please add a quirk to driver_denylist\n");
if (free_on_error) {
pci_set_drvdata(pci, NULL);
- snd_card_free(chip->card);
+ snd_card_free_when_closed(chip->card);
}
return err;
}

> Which user-visible change did you mean? The card now stays until the
> device is removed instead of being freed in the work.

Staying the card means that the card slot will be kept, then if you
probe another card afterwards, it'll end up with assignment on another
card slot.


thanks,

Takashi