Re: [PATCH 1/3] ALSA: hda: Stop unsol events and jack polling before codec unbind
From: Takashi Iwai
Date: Thu Oct 08 2026 - 08:05:16 EST
On Thu, 08 Oct 2026 13:52:42 +0200,
Cezary Rojewski wrote:
>
> On 10/8/2026 12:16 PM, Takashi Iwai wrote:
> > On Thu, 08 Oct 2026 11:08:13 +0200,
> > Cezary Rojewski wrote:
> >>
> >> On 10/7/2026 11:56 PM, Takashi Iwai wrote:
>
> >>> +++ b/sound/hda/common/bind.c
> >>> @@ -100,6 +100,9 @@ static int hda_codec_driver_probe(struct device *dev)
> >>> if (WARN_ON(!codec->preset))
> >>> return -EINVAL;
> >>>
> >>> + /* unsol events are still blocked until registered */
> >>> + codec->core.unsol_disabled = false;
> >>> +
> >>> err = snd_hda_codec_set_name(codec, codec->preset->name);
> >>> if (err < 0)
> >>> goto error;
> >>> @@ -160,6 +163,10 @@ static int hda_codec_driver_remove(struct device *dev)
> >>> return codec->bus->core.ext_ops->hdev_detach(&codec->core);
> >>> }
> >>>
> >>> + /* stop asynchronous jack handling before freeing driver resources */
> >>> + snd_hdac_device_disable_unsol(&codec->core);
> >>> + cancel_delayed_work_sync(&codec->jackpoll_work);
> >>
> >>
> >> IMHO this is a proof that ->registered flag doesn't do its job.
> >> snd_hda_codec_cleanup_for_unbind() is called right after and it does
> >> contain cancel_delayed_work_sync(&codec->jackpoll_work). It does
> >> contain snd_hda_codec_disconnect_pcms() and
> >> snd_hda_jack_tbl_disconnect() operations too.
> >
> > It's about the pending works, and the flag doesn't help there alone
> > unless they are synchronized; at the time point you flip the flag, the
> > work might be already in-flight, so the flag switch may miss the
> > chances.
>
> I agree, my suggestion was to make ->registered the sole owner of the
> subject, including the synchronization. At the same time, fixing the
> problem first and expanding the work later is also a valid approach.
>
> Do you have a method for reproducing the problem easily?
No, it's currently only hypothetical.
I guess it can be done with userfaltd, though. Maybe AI can help for
creating a reproducer.
> >> I'd say it is snd_hda_codec_cleanup_for_unbind() that needs an update
> >> and perhaps be responsible for calling driver->remove() too.
> >
> > Yeah, some code reorganization would be good.
Looking forward to seeing patches! ;)
Takashi