Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: usb-audio: Properly refcounting clock rate

We fixed the bug introduced by the patch for managing the shared
clocks at the commit 809f44a0cc5a ("ALSA: usb-audio: Clear fixed clock
rate at closing EP"), but it was merely a workaround. By this change,
the clock reference rate is cleared at each EP close, hence the still
remaining EP may need a re-setup of rate unnecessarily.

This patch introduces the proper refcounting for the clock reference
object so that the clock setup is done only when needed.

Fixes: 809f44a0cc5a ("ALSA: usb-audio: Clear fixed clock rate at closing EP")
Fixes: c11117b634f4 ("ALSA: usb-audio: Refcount multiple accesses on the single clock")
Link: https://lore.kernel.org/r/20220920181126.4912-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+7 -4
+7 -4
sound/usb/endpoint.c
··· 39 39 struct snd_usb_clock_ref { 40 40 unsigned char clock; 41 41 atomic_t locked; 42 + int opened; 42 43 int rate; 43 44 bool need_setup; 44 45 struct list_head list; ··· 804 803 ep = NULL; 805 804 goto unlock; 806 805 } 806 + ep->clock_ref->opened++; 807 807 } 808 808 809 809 ep->cur_audiofmt = fp; ··· 928 926 endpoint_set_interface(chip, ep, false); 929 927 930 928 if (!--ep->opened) { 931 - if (ep->clock_ref && !atomic_read(&ep->clock_ref->locked)) 932 - ep->clock_ref->rate = 0; 929 + if (ep->clock_ref) { 930 + if (!--ep->clock_ref->opened) 931 + ep->clock_ref->rate = 0; 932 + } 933 933 ep->iface = 0; 934 934 ep->altsetting = 0; 935 935 ep->cur_audiofmt = NULL; ··· 1653 1649 WRITE_ONCE(ep->sync_source->sync_sink, NULL); 1654 1650 stop_urbs(ep, false, keep_pending); 1655 1651 if (ep->clock_ref) 1656 - if (!atomic_dec_return(&ep->clock_ref->locked)) 1657 - ep->clock_ref->rate = 0; 1652 + atomic_dec(&ep->clock_ref->locked); 1658 1653 } 1659 1654 } 1660 1655