* [PATCH v2 1/2] ALSA: usb-audio: Don't read past the packet with pkt_offset_adj
[not found] <20261206065652.51981-1-yamane07ynct@gmail.com>
@ 2026-12-06 6:56 ` Daisuke Yamane
0 siblings, 0 replies; only message in thread
From: Daisuke Yamane @ 2026-12-06 6:56 UTC (permalink / raw)
To: Takashi Iwai, Jaroslav Kysela; +Cc: linux-sound, Daisuke Yamane, stable
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-06 6:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261206065652.51981-1-yamane07ynct@gmail.com>
2026-12-06 6:56 ` [PATCH v2 1/2] ALSA: usb-audio: Don't read past the packet with pkt_offset_adj Daisuke Yamane
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox