From: Sinan Turunc <enscrpt@pm.me>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ALSA: usx2y: Count completions apart from the URB array length
Date: Sun, 15 Nov 2026 12:16:33 +0000 [thread overview]
Message-ID: <20261115121602.151-1-enscrpt@pm.me> (raw)
usx2y_rate_set() allocates a snd_usx2y_urb_seq with len set to the
number of URBs, and i_usx2y_04int() decrements len once per completed
URB to know when all of them are done. Since len is also the
__counted_by() bound of the urb[] array, every access to the array after
the first completion is out of range for UBSAN, and the cleanup loop in
usx2y_rate_set() trips it on every prepare:
UBSAN: array-index-out-of-bounds in sound/usb/usx2y/usbusx2yaudio.c:694:18
index 0 is out of range for type 'urb *[*]'
Count the completions in a separate field and leave len as the array
length.
Tested on 7.3-rc7 with CONFIG_UBSAN_BOUNDS and an emulated US-122 over
USB/IP: before, the report appears on every prepare; after, a 30 s
capture stream prepares and runs without it and the rate sequence still
completes.
Fixes: f5cc9cdfc96f ("ALSA: usx2y: Annotate struct snd_usx2y_urb_seq with __counted_by")
Signed-off-by: Sinan Turunc <enscrpt@pm.me>
---
2 file(s) changed, 5 insertions(+), 3 deletions(-)
diff --git a/sound/usb/usx2y/usbusx2y.h b/sound/usb/usx2y/usbusx2y.h
index 7b6deed17d4..17edafdcc89 100644
--- a/sound/usb/usx2y/usbusx2y.h
+++ b/sound/usb/usx2y/usbusx2y.h
@@ -46,6 +46,7 @@ struct snd_usx2y_async_seq {
struct snd_usx2y_urb_seq {
int submitted;
int len;
+ int pending; /* completions still to come */
struct urb *urb[] __counted_by(len);
};
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index a3a0bc13632..e03f7e4e8cb 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -643,7 +643,7 @@ static void i_usx2y_04int(struct urb *urb)
if (urb->status)
dev_err(&urb->dev->dev, "%s() urb->status=%i\n",
__func__, urb->status);
- if (!--usx2y->us04->len)
+ if (!--usx2y->us04->pending)
wake_up(&usx2y->in04_wait_queue);
}
@@ -662,6 +662,7 @@ static int usx2y_rate_set(struct usx2ydev *usx2y, int rate)
goto cleanup;
}
us->len = NOOF_SETRATE_URBS;
+ us->pending = NOOF_SETRATE_URBS;
usbdata = kmalloc_objs(int, NOOF_SETRATE_URBS);
if (!usbdata) {
err = -ENOMEM;
@@ -683,9 +684,9 @@ static int usx2y_rate_set(struct usx2ydev *usx2y, int rate)
goto cleanup;
us->submitted = 0;
usx2y->us04 = us;
- wait_event_timeout(usx2y->in04_wait_queue, !us->len, HZ);
+ wait_event_timeout(usx2y->in04_wait_queue, !us->pending, HZ);
usx2y->us04 = NULL;
- if (us->len)
+ if (us->pending)
err = -ENODEV;
cleanup:
if (us) {
--
2.56.0
reply other threads:[~2026-11-15 12:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261115121602.151-1-enscrpt@pm.me \
--to=enscrpt@pm.me \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.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
all inboxes | Powered by JetHome®