Commit 30eb909d authored by Kieran Bingham's avatar Kieran Bingham Committed by Mauro Carvalho Chehab

media: uvcvideo: Utilise for_each_uvc_urb iterator

A new iterator is available for processing UVC URB structures. This
simplifies the processing of the internal stream data.

Convert the manual loop iterators to the new helper, adding an index
helper to keep the existing debug print.
Signed-off-by: default avatarKieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent fb58e16b
...@@ -1556,20 +1556,19 @@ static void uvc_video_complete(struct urb *urb) ...@@ -1556,20 +1556,19 @@ static void uvc_video_complete(struct urb *urb)
*/ */
static void uvc_free_urb_buffers(struct uvc_streaming *stream) static void uvc_free_urb_buffers(struct uvc_streaming *stream)
{ {
unsigned int i; struct uvc_urb *uvc_urb;
for (i = 0; i < UVC_URBS; ++i) { for_each_uvc_urb(uvc_urb, stream) {
struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; if (!uvc_urb->buffer)
continue;
if (uvc_urb->buffer) {
#ifndef CONFIG_DMA_NONCOHERENT #ifndef CONFIG_DMA_NONCOHERENT
usb_free_coherent(stream->dev->udev, stream->urb_size, usb_free_coherent(stream->dev->udev, stream->urb_size,
uvc_urb->buffer, uvc_urb->dma); uvc_urb->buffer, uvc_urb->dma);
#else #else
kfree(uvc_urb->buffer); kfree(uvc_urb->buffer);
#endif #endif
uvc_urb->buffer = NULL; uvc_urb->buffer = NULL;
}
} }
stream->urb_size = 0; stream->urb_size = 0;
...@@ -1701,7 +1700,8 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream, ...@@ -1701,7 +1700,8 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,
struct usb_host_endpoint *ep, gfp_t gfp_flags) struct usb_host_endpoint *ep, gfp_t gfp_flags)
{ {
struct urb *urb; struct urb *urb;
unsigned int npackets, i, j; struct uvc_urb *uvc_urb;
unsigned int npackets, i;
u16 psize; u16 psize;
u32 size; u32 size;
...@@ -1714,9 +1714,7 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream, ...@@ -1714,9 +1714,7 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,
size = npackets * psize; size = npackets * psize;
for (i = 0; i < UVC_URBS; ++i) { for_each_uvc_urb(uvc_urb, stream) {
struct uvc_urb *uvc_urb = &stream->uvc_urb[i];
urb = usb_alloc_urb(npackets, gfp_flags); urb = usb_alloc_urb(npackets, gfp_flags);
if (urb == NULL) { if (urb == NULL) {
uvc_video_stop_transfer(stream, 1); uvc_video_stop_transfer(stream, 1);
...@@ -1739,9 +1737,9 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream, ...@@ -1739,9 +1737,9 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,
urb->number_of_packets = npackets; urb->number_of_packets = npackets;
urb->transfer_buffer_length = size; urb->transfer_buffer_length = size;
for (j = 0; j < npackets; ++j) { for (i = 0; i < npackets; ++i) {
urb->iso_frame_desc[j].offset = j * psize; urb->iso_frame_desc[i].offset = i * psize;
urb->iso_frame_desc[j].length = psize; urb->iso_frame_desc[i].length = psize;
} }
uvc_urb->urb = urb; uvc_urb->urb = urb;
...@@ -1758,7 +1756,8 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream, ...@@ -1758,7 +1756,8 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream,
struct usb_host_endpoint *ep, gfp_t gfp_flags) struct usb_host_endpoint *ep, gfp_t gfp_flags)
{ {
struct urb *urb; struct urb *urb;
unsigned int npackets, pipe, i; struct uvc_urb *uvc_urb;
unsigned int npackets, pipe;
u16 psize; u16 psize;
u32 size; u32 size;
...@@ -1782,9 +1781,7 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream, ...@@ -1782,9 +1781,7 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream,
if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
size = 0; size = 0;
for (i = 0; i < UVC_URBS; ++i) { for_each_uvc_urb(uvc_urb, stream) {
struct uvc_urb *uvc_urb = &stream->uvc_urb[i];
urb = usb_alloc_urb(0, gfp_flags); urb = usb_alloc_urb(0, gfp_flags);
if (urb == NULL) { if (urb == NULL) {
uvc_video_stop_transfer(stream, 1); uvc_video_stop_transfer(stream, 1);
...@@ -1812,6 +1809,7 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, ...@@ -1812,6 +1809,7 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream,
{ {
struct usb_interface *intf = stream->intf; struct usb_interface *intf = stream->intf;
struct usb_host_endpoint *ep; struct usb_host_endpoint *ep;
struct uvc_urb *uvc_urb;
unsigned int i; unsigned int i;
int ret; int ret;
...@@ -1889,13 +1887,11 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, ...@@ -1889,13 +1887,11 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream,
return ret; return ret;
/* Submit the URBs. */ /* Submit the URBs. */
for (i = 0; i < UVC_URBS; ++i) { for_each_uvc_urb(uvc_urb, stream) {
struct uvc_urb *uvc_urb = &stream->uvc_urb[i];
ret = usb_submit_urb(uvc_urb->urb, gfp_flags); ret = usb_submit_urb(uvc_urb->urb, gfp_flags);
if (ret < 0) { if (ret < 0) {
uvc_printk(KERN_ERR, "Failed to submit URB %u " uvc_printk(KERN_ERR, "Failed to submit URB %u (%d).\n",
"(%d).\n", i, ret); uvc_urb_index(uvc_urb), ret);
uvc_video_stop_transfer(stream, 1); uvc_video_stop_transfer(stream, 1);
return ret; return ret;
} }
......
...@@ -620,6 +620,9 @@ struct uvc_streaming { ...@@ -620,6 +620,9 @@ struct uvc_streaming {
(uvc_urb) < &(uvc_streaming)->uvc_urb[UVC_URBS]; \ (uvc_urb) < &(uvc_streaming)->uvc_urb[UVC_URBS]; \
++(uvc_urb)) ++(uvc_urb))
#define uvc_urb_index(uvc_urb) \
(unsigned int)((uvc_urb) - (&(uvc_urb)->stream->uvc_urb[0]))
struct uvc_device_info { struct uvc_device_info {
u32 quirks; u32 quirks;
u32 meta_format; u32 meta_format;
......
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