Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: uvcvideo: Fix allocation for small frame sizes

If a frame has size of less or equal than one packet size
uvc_alloc_urb_buffers() is unable to allocate memory for it due to a
off-by-one error.

Fix the off-by-one-error and now that we are at it, make sure that
stream->urb_size has always a valid value when we return from the
function, even when an error happens.

Fixes: efdc8a9585ce ("V4L/DVB (10295): uvcvideo: Retry URB buffers allocation when the system is low on memory.")
Reported-by: Itay Chamiel <itay.chamiel@q.ai>
Closes: https://lore.kernel.org/linux-media/CANiDSCsSoZf2LsCCoWAUbCg6tJT-ypXR1B85aa6rAdMVYr2iBQ@mail.gmail.com/T/#t
Co-developed-by: Itay Chamiel <itay.chamiel@q.ai>
Signed-off-by: Itay Chamiel <itay.chamiel@q.ai>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Itay Chamiel <itay.chamiel@q.ai>
Link: https://patch.msgid.link/20260114-uvc-alloc-urb-v1-1-cedf3fb66711@chromium.org
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Ricardo Ribalda and committed by
Hans Verkuil
40d3ac25 4cf3b6fd

+2 -1
+2 -1
drivers/media/usb/uvc/uvc_video.c
··· 1812 1812 npackets = UVC_MAX_PACKETS; 1813 1813 1814 1814 /* Retry allocations until one succeed. */ 1815 - for (; npackets > 1; npackets /= 2) { 1815 + for (; npackets > 0; npackets /= 2) { 1816 1816 stream->urb_size = psize * npackets; 1817 1817 1818 1818 for (i = 0; i < UVC_URBS; ++i) { ··· 1837 1837 uvc_dbg(stream->dev, VIDEO, 1838 1838 "Failed to allocate URB buffers (%u bytes per packet)\n", 1839 1839 psize); 1840 + stream->urb_size = 0; 1840 1841 return 0; 1841 1842 } 1842 1843