Commit db870875 authored by Jean-Francois Moine's avatar Jean-Francois Moine Committed by Mauro Carvalho Chehab

V4L/DVB (13865): gspca - main: Optimize code.

Signed-off-by: default avatarJean-Francois Moine <moinejf@free.fr>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 3205e4fe
...@@ -108,11 +108,8 @@ static const struct vm_operations_struct gspca_vm_ops = { ...@@ -108,11 +108,8 @@ static const struct vm_operations_struct gspca_vm_ops = {
struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev) struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev)
{ {
struct gspca_frame *frame; struct gspca_frame *frame;
int i;
i = gspca_dev->fr_i; frame = gspca_dev->cur_frame;
i = gspca_dev->fr_queue[i];
frame = &gspca_dev->frame[i];
if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS) if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS)
!= V4L2_BUF_FLAG_QUEUED) != V4L2_BUF_FLAG_QUEUED)
return NULL; return NULL;
...@@ -534,26 +531,22 @@ static int create_urbs(struct gspca_dev *gspca_dev, ...@@ -534,26 +531,22 @@ static int create_urbs(struct gspca_dev *gspca_dev,
nurbs = 1; nurbs = 1;
} }
gspca_dev->nurbs = nurbs;
for (n = 0; n < nurbs; n++) { for (n = 0; n < nurbs; n++) {
urb = usb_alloc_urb(npkt, GFP_KERNEL); urb = usb_alloc_urb(npkt, GFP_KERNEL);
if (!urb) { if (!urb) {
err("usb_alloc_urb failed"); err("usb_alloc_urb failed");
destroy_urbs(gspca_dev);
return -ENOMEM; return -ENOMEM;
} }
gspca_dev->urb[n] = urb;
urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev, urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev,
bsize, bsize,
GFP_KERNEL, GFP_KERNEL,
&urb->transfer_dma); &urb->transfer_dma);
if (urb->transfer_buffer == NULL) { if (urb->transfer_buffer == NULL) {
usb_free_urb(urb); err("usb_buffer_alloc failed");
err("usb_buffer_urb failed");
destroy_urbs(gspca_dev);
return -ENOMEM; return -ENOMEM;
} }
gspca_dev->urb[n] = urb;
urb->dev = gspca_dev->dev; urb->dev = gspca_dev->dev;
urb->context = gspca_dev; urb->context = gspca_dev;
urb->transfer_buffer_length = bsize; urb->transfer_buffer_length = bsize;
...@@ -585,6 +578,7 @@ static int create_urbs(struct gspca_dev *gspca_dev, ...@@ -585,6 +578,7 @@ static int create_urbs(struct gspca_dev *gspca_dev,
static int gspca_init_transfer(struct gspca_dev *gspca_dev) static int gspca_init_transfer(struct gspca_dev *gspca_dev)
{ {
struct usb_host_endpoint *ep; struct usb_host_endpoint *ep;
struct urb *urb;
int n, ret; int n, ret;
if (mutex_lock_interruptible(&gspca_dev->usb_lock)) if (mutex_lock_interruptible(&gspca_dev->usb_lock))
...@@ -615,8 +609,10 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) ...@@ -615,8 +609,10 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
for (;;) { for (;;) {
PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt); PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt);
ret = create_urbs(gspca_dev, ep); ret = create_urbs(gspca_dev, ep);
if (ret < 0) if (ret < 0) {
destroy_urbs(gspca_dev);
goto out; goto out;
}
/* clear the bulk endpoint */ /* clear the bulk endpoint */
if (gspca_dev->cam.bulk) if (gspca_dev->cam.bulk)
...@@ -636,8 +632,11 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) ...@@ -636,8 +632,11 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
break; break;
/* submit the URBs */ /* submit the URBs */
for (n = 0; n < gspca_dev->nurbs; n++) { for (n = 0; n < MAX_NURBS; n++) {
ret = usb_submit_urb(gspca_dev->urb[n], GFP_KERNEL); urb = gspca_dev->urb[n];
if (urb == NULL)
break;
ret = usb_submit_urb(urb, GFP_KERNEL);
if (ret < 0) if (ret < 0)
break; break;
} }
......
...@@ -187,7 +187,6 @@ struct gspca_dev { ...@@ -187,7 +187,6 @@ struct gspca_dev {
char users; /* number of opens */ char users; /* number of opens */
char present; /* device connected */ char present; /* device connected */
char nbufread; /* number of buffers for read() */ char nbufread; /* number of buffers for read() */
char nurbs; /* number of allocated URBs */
char memory; /* memory type (V4L2_MEMORY_xxx) */ char memory; /* memory type (V4L2_MEMORY_xxx) */
__u8 iface; /* USB interface number */ __u8 iface; /* USB interface number */
__u8 alt; /* USB alternate setting */ __u8 alt; /* USB alternate setting */
......
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