stk1160_buffer_done() reports buf->bytesused as the payload of the frame, and bytesused is a running total of the bytes copied into the buffer. The total only matches the frame while a frame consists of exactly two fields: stk1160_process_isoc() restarts the field at every 0x80 and 0xc0 marker by resetting pos, but it leaves bytesused alone, and stk1160_copy_video() then writes the new field over the very same lines. A stream that repeats the 0x80 marker therefore copies a third field segment over lines that were already written, while bytesused keeps growing. Each segment can fill half of the buffer, so bytesused reaches 1.5 times the plane size and the WARN_ON_ONCE() in vb2_set_plane_payload() is triggered; a long enough stream can even wrap it. Account for the part of the buffer the frame actually covers instead of summing every copy. Setting bytesused to the end of the copied range keeps it within buf->length by construction, so the reported payload stays valid even when the device repeats a field marker, and the videobuf2 check keeps catching real accounting mistakes. Fixes: 9cb2173e6ea8 ("[media] media: Add stk1160 new driver (easycap replacement)") Cc: stable@vger.kernel.org Co-developed-by: Bin Yu Signed-off-by: Bin Yu Co-developed-by: Cheng Wen Signed-off-by: Cheng Wen Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> --- v2: - Fix the accounting in stk1160_copy_video() instead of clamping the payload in stk1160_buffer_done(). The clamp only silenced the videobuf2 warning, which already clamps the value by itself, and left bytesused counting bytes that were written twice. - Drop the claim that gspca_frame_add() does the same thing. It drops overflowing frames per packet and only trims page-align padding. drivers/media/usb/stk1160/stk1160-video.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/stk1160/stk1160-video.c b/drivers/media/usb/stk1160/stk1160-video.c index 020b75fc5b2d..e93b0a739cfd 100644 --- a/drivers/media/usb/stk1160/stk1160-video.c +++ b/drivers/media/usb/stk1160/stk1160-video.c @@ -167,7 +167,8 @@ void stk1160_copy_video(struct stk1160 *dev, u8 *src, int len) memcpy(dst, src, lencopy); - buf->bytesused += lencopy; + buf->bytesused = max_t(unsigned int, buf->bytesused, + offset + lencopy); buf->pos += lencopy; remain -= lencopy; @@ -212,7 +213,8 @@ void stk1160_copy_video(struct stk1160 *dev, u8 *src, int len) memcpy(dst, src, lencopy); remain -= lencopy; - buf->bytesused += lencopy; + buf->bytesused = max_t(unsigned int, buf->bytesused, + offset + lencopy); buf->pos += lencopy; } } -- 2.34.1