Skip to content

Commit 9bcb4c4

Browse files
Xu Yanggregkh
authored andcommitted
usb: gadget: uvc: retry vb2_reqbufs() with vb_vmalloc_memops if use_sg fail
Based on the reality[1][2] that vb2_dma_sg_alloc() can't alloc buffer with device DMA limits, those device will always get below error: "swiotlb buffer is full (sz: 393216 bytes), total 65536 (slots), used 2358 (slots)" and the uvc gadget function can't work at all. The videobuf2-dma-sg.c driver doesn't has a formal improve about this issue till now. For UVC gadget, the videobuf2 subsystem doesn't do dma_map() on vmalloc returned big buffer when allocate the video buffers, however, it do it for dma_sg returned buffer. So the issue happens for vb2_dma_sg_alloc(). To workaround the issue, lets retry vb2_reqbufs() with vb_vmalloc_memops if it fails to allocate buffer with vb2_dma_sg_memops. If use vmalloced buffer, UVC gadget will allocate some small buffers for each usb_request to do dma transfer, then uvc driver will memcopy data from big buffer to small buffer. Link[1]: https://lore.kernel.org/linux-media/20230828075420.2009568-1-anle.pan@nxp.com/ Link[2]: https://lore.kernel.org/linux-media/20230914145812.12851-1-hui.fang@nxp.com/ Signed-off-by: Xu Yang <xu.yang_2@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260113-uvc-gadget-fix-patch-v2-4-62950ef5bcb5@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0bce8f1 commit 9bcb4c4

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

drivers/usb/gadget/function/uvc_queue.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,15 @@ int uvcg_alloc_buffers(struct uvc_video_queue *queue,
182182
{
183183
int ret;
184184

185+
retry:
185186
ret = vb2_reqbufs(&queue->queue, rb);
187+
if (ret < 0 && queue->use_sg) {
188+
uvc_trace(UVC_TRACE_IOCTL,
189+
"failed to alloc buffer with sg enabled, try non-sg mode\n");
190+
queue->use_sg = 0;
191+
queue->queue.mem_ops = &vb2_vmalloc_memops;
192+
goto retry;
193+
}
186194

187195
return ret ? ret : rb->count;
188196
}

0 commit comments

Comments
 (0)