]> git.baikalelectronics.ru Git - kernel.git/commit
ALSA: usb-audio: Set callbacks via snd_usb_endpoint_set_callback()
authorTakashi Iwai <tiwai@suse.de>
Mon, 23 Nov 2020 08:53:28 +0000 (09:53 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 23 Nov 2020 14:14:44 +0000 (15:14 +0100)
commit0651f96e61929ad09c167f5eb0f0417adbcc2c05
tree97f8bcd1862e6c16f3b9ab9cedc2528dddbd4067
parented30c70cb27e8748dd36374a618176b8a2fc982c
ALSA: usb-audio: Set callbacks via snd_usb_endpoint_set_callback()

The prepare_data_urb and retire_data_urb fields of the endpoint object
are set dynamically at PCM trigger start/stop.  Those are evaluated in
the endpoint handler, but there can be a race, especially if two
different PCM substreams are handling the same endpoint for the
implicit feedback case.  Also, the data_subs field of the endpoint is
set and accessed dynamically, too, which has the same risk.

As a slight improvement for the concurrency, this patch introduces the
function to set the callbacks and the data in a shot with the memory
barrier.  In the reader side, it's also fetched with the memory
barrier.

There is still a room of race if prepare and retire callbacks are set
during executing the URB completion.  But such an inconsistency may
happen only for the implicit fb source, i.e. it's only about the
capture stream.  And luckily, the capture stream never sets the
prepare callback, hence the problem doesn't happen practically.

Tested-by: Keith Milner <kamilner@superlative.org>
Tested-by: Dylan Robinson <dylan_robinson@motu.com>
Link: https://lore.kernel.org/r/20201123085347.19667-23-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/endpoint.c
sound/usb/endpoint.h
sound/usb/pcm.c