Commit fd1b6bbb authored by Ming Lei's avatar Ming Lei Committed by Mauro Carvalho Chehab

V4L/DVB (13153): uvcvideo: Fix uvc_alloc_urb_buffers()

This patch sets stream->urb_size as psize*npackets
before calling uvc_alloc_urb_buffers, which may fix
a possible failure of usb_buffer_free in case usb_buffer_alloc
returns NULL. The patch is based on the ideas below:

1,If usb_buffer_alloc can't allocate a buffer sucessfully,
uvc_free_urb_buffers will be called to free the allocated
buffers, and stream->urb_size is required to be passed to
usb_buffer_free;

2,uvc_free_urb_buffers can reset stream->urb_size.

This patch is against linux-v2.6.31-next-20090926.
Signed-off-by: default avatarMing Lei <tom.leiming@gmail.com>
Acked-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 716fdee1
...@@ -770,8 +770,9 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, ...@@ -770,8 +770,9 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
/* Retry allocations until one succeed. */ /* Retry allocations until one succeed. */
for (; npackets > 1; npackets /= 2) { for (; npackets > 1; npackets /= 2) {
for (i = 0; i < UVC_URBS; ++i) { for (i = 0; i < UVC_URBS; ++i) {
stream->urb_size = psize * npackets;
stream->urb_buffer[i] = usb_buffer_alloc( stream->urb_buffer[i] = usb_buffer_alloc(
stream->dev->udev, psize * npackets, stream->dev->udev, stream->urb_size,
gfp_flags | __GFP_NOWARN, &stream->urb_dma[i]); gfp_flags | __GFP_NOWARN, &stream->urb_dma[i]);
if (!stream->urb_buffer[i]) { if (!stream->urb_buffer[i]) {
uvc_free_urb_buffers(stream); uvc_free_urb_buffers(stream);
...@@ -780,7 +781,6 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, ...@@ -780,7 +781,6 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
} }
if (i == UVC_URBS) { if (i == UVC_URBS) {
stream->urb_size = psize * npackets;
uvc_trace(UVC_TRACE_VIDEO, "Allocated %u URB buffers " uvc_trace(UVC_TRACE_VIDEO, "Allocated %u URB buffers "
"of %ux%u bytes each.\n", UVC_URBS, npackets, "of %ux%u bytes each.\n", UVC_URBS, npackets,
psize); psize);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment