[PATCH v2 1/5] ALSA: line6: Fix handling of zero-length capture packets

From: Takashi Iwai

Date: Fri Oct 09 2026 - 09:33:56 EST


The LINE6 playback engine assumes that line6pcm->prev_fsize=0
indicates that there was no input packet to be processed, and
synthesizes the frames. But, when a capture stream receives a
zero-length (or a very small size) packet, it sets 0 to prev_fsize,
while playback engine still believes it's for synthesis, hence it
tries to copy the larger data than the actual input data.

As prev_fsize=0 can't be a good indication for "no input", change the
meaning slightly: now prev_fsize=-1 means no input, while prev_fsize=0
means it's a zero-length packet.

As a result, the outgoing packet length can be also zero, so the
corresponding check is dropped, too; otherwise the outgoing URB will
be lost.

Fixes: 1027f476f507 ("staging: line6: sync with upstream")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
---
v1->v2: drop the zero urb length check code, too

sound/usb/line6/pcm.c | 4 +++-
sound/usb/line6/playback.c | 10 ++--------
2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/sound/usb/line6/pcm.c b/sound/usb/line6/pcm.c
index 998869dc4613..e2b99e7a08e0 100644
--- a/sound/usb/line6/pcm.c
+++ b/sound/usb/line6/pcm.c
@@ -217,7 +217,7 @@ static void line6_stream_stop(struct snd_line6_pcm *line6pcm, int direction,
if (direction == SNDRV_PCM_STREAM_CAPTURE) {
guard(spinlock_irqsave)(&pstr->lock);
line6pcm->prev_fbuf = NULL;
- line6pcm->prev_fsize = 0;
+ line6pcm->prev_fsize = -1;
}
}

@@ -538,6 +538,8 @@ int line6_init_pcm(struct usb_line6 *line6,
line6pcm->volume_playback[0] = line6pcm->volume_playback[1] = 255;
line6pcm->volume_monitor = 255;
line6pcm->line6 = line6;
+ line6pcm->prev_fbuf = NULL;
+ line6pcm->prev_fsize = -1;

spin_lock_init(&line6pcm->out.lock);
spin_lock_init(&line6pcm->in.lock);
diff --git a/sound/usb/line6/playback.c b/sound/usb/line6/playback.c
index aa6ddf8746a0..8797f8b1577a 100644
--- a/sound/usb/line6/playback.c
+++ b/sound/usb/line6/playback.c
@@ -171,7 +171,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
&urb_out->iso_frame_desc[i];

fsize = line6pcm->prev_fsize;
- if (fsize == 0) {
+ if (fsize == -1) {
int n;

line6pcm->out.count += frame_increment;
@@ -194,12 +194,6 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
urb_size += fsize;
}

- if (urb_size == 0) {
- /* can't determine URB size */
- dev_err(line6pcm->line6->ifcdev, "driver bug: urb_size = 0\n");
- return -EINVAL;
- }
-
urb_frames = urb_size / bytes_per_frame;
urb_out->transfer_buffer =
line6pcm->out.buffer +
@@ -271,7 +265,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
bytes_per_frame);
}
line6pcm->prev_fbuf = NULL;
- line6pcm->prev_fsize = 0;
+ line6pcm->prev_fsize = -1;
}
spin_unlock(&line6pcm->in.lock);

--
2.55.0