Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Volkov" <voilthuman@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 2/2] ALSA: usb-audio: Reuse active sync endpoint format for implicit feedback
Date: Wed, 02 Dec 2026 18:22:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-246430@kernel.org> (raw)
In-Reply-To: <20261202181013.145045-3-voilthuman@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ALSA: usb-audio: stale sync format in
  snd_usb_find_implicit_fb_sync_format()
--

commit 6b635db94b2380ef0172259cb4f8263eb84ae716
Author: Lee Volkov <voilthuman@gmail.com>

ALSA: usb-audio: Reuse active sync endpoint format for implicit feedback

This commit checks if the implicit-feedback sync endpoint is already open
with a compatible audioformat and reuses it instead of scanning
subs->fmt_list for a new altsetting.

> diff --git a/sound/usb/implicit.c b/sound/usb/implicit.c
> index bd4d569a8190c..56fb87345e9f5 100644
> --- a/sound/usb/implicit.c
> +++ b/sound/usb/implicit.c
[ ... ]
> @@ -475,6 +478,25 @@ snd_usb_find_implicit_fb_sync_format(struct snd_usb_audio *chip,
>  	if (!subs)
>  		goto end;
>  
> +	/*
> +	 * If the shared sync endpoint is already open in a compatible format,
> +	 * reuse that active audioformat instead of picking another altsetting
> +	 * and failing endpoint_compatible() later.
> +	 */
> +	scoped_guard(mutex, &chip->mutex) {
> +		ep = snd_usb_get_endpoint(chip, target->sync_ep);
> +		if (ep && ep->opened && ep->cur_audiofmt &&
> +		    match_endpoint_audioformats(subs, ep->cur_audiofmt,
> +						params_rate(params),
> +						params_channels(params),
> +						params_format(params)))
> +			active_fmt = ep->cur_audiofmt;
> +	}
> +	if (active_fmt) {
> +		sync_fmt = active_fmt;
> +		goto end;
> +	}

[Severity: Medium]
Can a repeated hw_params call without an intervening hw_free pin the sync
endpoint to the calling substream's own about-to-be-closed sync_fmt?

snd_usb_hw_params() calls snd_usb_find_implicit_fb_sync_format() before
closing the calling substream's previous endpoints:

sound/usb/pcm.c:snd_usb_hw_params() {
	...
	if (fmt->implicit_fb) {
		sync_fmt = snd_usb_find_implicit_fb_sync_format(chip, fmt,
								hw_params,
								!subs->direction,
								&sync_fixed_rate);
	...
	if (subs->data_endpoint) {
		if (snd_usb_endpoint_compatible(chip, subs->data_endpoint,
						fmt, hw_params))
			goto unlock;
		if (stop_endpoints(subs, false))
			sync_pending_stops(subs);
		close_endpoints(chip, subs);
	}
}

When the counterpart substream is not open, ep->opened is 1 from the
calling substream's own subs->sync_endpoint.  Because
match_endpoint_audioformats() returns 1 for any channel count when the
rate and PCM format match, this check matches the old ep->cur_audiofmt and
skips the subs->fmt_list scoring loop even when the caller is changing
channels and close_endpoints() is about to drop that reference.
Reopening the sync endpoint with the stale altsetting can then cause a
subsequent open of the counterpart substream with the new channel count to
fail in endpoint_compatible() with -EINVAL, or conflict with
data_endpoint's new altsetting when target->iface == target->sync_iface.

Should this check whether the endpoint is actually in use by the
counterpart stream (similar to how get_endpoint_in_use() checks
ep != ref_ep || ep->opened > 1) before reusing ep->cur_audiofmt?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202181013.145045-1-voilthuman@gmail.com?part=2

      reply	other threads:[~2026-12-02 18:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 18:10 [PATCH 0/2] ALSA: usb-audio: Fix Solid State Logic SSL 12 192 kHz duplex Lee Volkov
2026-12-02 18:10 ` [PATCH 1/2] ALSA: usb-audio: Filter invalid capture rates on Solid State Logic SSL 12 Lee Volkov
2026-12-02 18:10 ` [PATCH 2/2] ALSA: usb-audio: Reuse active sync endpoint format for implicit feedback Lee Volkov
2026-12-02 18:22   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-246430@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=voilthuman@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox