[alsa-devel] USB Audio initialization race

Alan Stern stern at rowland.harvard.edu
Fri Sep 13 23:06:26 CEST 2013


On Fri, 13 Sep 2013, David Henningsson wrote:

> 2013-09-13 16:39, Alan Stern skrev:
> > On Fri, 13 Sep 2013, David Henningsson wrote:
> >
> >> I'm sometimes seeing that USB audio devices are not initialized
> >> correctly by PulseAudio, but I can't reproduce this myself.
> >>
> >> I have, however, spotted what I think is a race condition in the driver
> >> code, if a device has more than one interface. snd_card_register is
> >> called once for every interface, which means that it will be shown to
> >> userspace after the first interface has been probed. So the race could
> >> look like:
> >>
> >> 1) The first interface is probed, which might contain the mixer controls
> >> 2) snd_card_register is called, which sends a signal to userspace
> >> 3) PulseAudio probes the device and notices that it has no PCMs, so it
> >> ignores the device
> >> 4) The second interface is probed, which adds the PCMs
> >> 5) snd_card_register is again called, which is a no-op since the card
> >> already exist
> >> 6) User is unhappy because his plugged in sound card did not show up in
> >> PulseAudio.
> >>
> >> So, assuming all this is right, it seems like we need some type of
> >> callback from the usb driver when all the interfaces for the sound card
> >> has been probed, so we can call snd_card_register at that point instead.
> >> Thoughts?
> > The driver probably doesn't know when all the interfaces have been
> > probed.
> I'm unsure if you mean "the usb driver" or "the usb audio driver" in the 
> sentence above, but the USB driver would enumerate all interfaces and 
> call the usb audio driver for every interface, and so the USB driver 
> would know when all the interfaces have been probed, right?

I'm not sure what you mean by "the USB driver".  The USB core registers 
all the interfaces, which causes them to be probed.  The USB core does 
know when all the interfaces have been registered.

> Is there a way the USB audio driver can subscribe, or get an additional 
> callback of some sort, when that happens?

No, not currently.

> > Maybe it would be better to send a signal to userspace each
> > time snd_card_register is called, even if nothing is done.
> 
> That sounds very suboptimal, given that PulseAudio's probing mechanism 
> can be quite heavy (depending on the device).
> >
> > Alternatively, when the first interface is probed, the driver could
> > claim all the other interfaces belonging to the same association.
> Not sure how well that would work out with "composite" devices, e g 
> headset with volume up/down buttons?

Presumably the HID interface (with the button controls) would not be in 
the audio interface association.  Anyway, the audio driver wouldn't 
claim anything that wasn't an audio interface.

Alan Stern



More information about the Alsa-devel mailing list