Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Daisuke Yamane <yamane07ynct@gmail.com>
To: Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>
Cc: linux-sound@vger.kernel.org,
	Daisuke Yamane <yamane07ynct@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH v2 1/2] ALSA: usb-audio: Don't read past the packet with pkt_offset_adj
Date: Sun,  6 Dec 2026 15:56:51 +0900	[thread overview]
Message-ID: <20261206065652.51981-2-yamane07ynct@gmail.com> (raw)
In-Reply-To: <20261206065652.51981-1-yamane07ynct@gmail.com>

retire_capture_urb() starts the copy pkt_offset_adj bytes into each
packet but derives the number of frames from the full actual_length,
so the copy ends pkt_offset_adj bytes after the received data. The
packets of a URB lie back to back in transfer_buffer, so for the last
packet of a URB that fills its slot, memcpy() reads past the end of
the buffer. A device can send such a packet regardless of the layout
that its quirk expects.

Subtract pkt_offset_adj from the byte count, as is already done for
stream_offset_adj. A packet shorter than the offset gives no frames.

For a packet of the offset followed by whole frames, the frame count
is unchanged when a frame is larger than the offset; otherwise
offset / frame size frames (rounded down) past the received data were
copied, which this drops.

This was found by the Sashiko AI review of a patch that adds a second
user of pkt_offset_adj; the change and this description were prepared
with the help of an AI coding assistant.

Fixes: 1539d4f82ad5 ("ALSA: usb: Add quirk for 192KHz recording on E-Mu devices")
Cc: stable@vger.kernel.org
Signed-off-by: Daisuke Yamane <yamane07ynct@gmail.com>
---
Tested only on the Yamaha ZG02 together with patch 2/2 (see there);
not tested on E-Mu hardware.

 sound/usb/pcm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 57a2649..d88ef29 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -1343,6 +1343,8 @@ static void retire_capture_urb(struct snd_usb_substream *subs,
 					     i, bytes, urb->iso_frame_desc[i].length);
 			continue;
 		}
+		/* the bytes skipped by pkt_offset_adj are not frames */
+		bytes -= min(subs->pkt_offset_adj, bytes);
 		if (subs->stream_offset_adj > 0) {
 			unsigned int adj = min(subs->stream_offset_adj, bytes);
 			cp += adj;
-- 
2.43.0


  reply	other threads:[~2026-12-06  6:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  6:56 [PATCH v2 0/2] ALSA: usb-audio: Fix Yamaha ZG02 capture Daisuke Yamane
2026-12-06  6:56 ` Daisuke Yamane [this message]
2026-12-06  6:56 ` [PATCH v2 2/2] ALSA: usb-audio: Skip packet header in Yamaha ZG02 capture stream Daisuke Yamane

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=20261206065652.51981-2-yamane07ynct@gmail.com \
    --to=yamane07ynct@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=stable@vger.kernel.org \
    --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