Skip to content

Commit

Permalink
video1394: small optimizations to frame retrieval codepath
Browse files Browse the repository at this point in the history
Add some GCC branch prediction optimizations to unlikely error/safety
conditions in the ioctl handling code commonly called during an application's
capture loop.

Signed-off-by: Daniel Drake <ddrake@brontes3d.com>
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
  • Loading branch information
Daniel Drake authored and Stefan Richter committed Dec 7, 2006
1 parent c1c9c7c commit 3c21cfc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions drivers/ieee1394/video1394.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,21 +884,22 @@ static int __video1394_ioctl(struct file *file,
struct dma_iso_ctx *d;
int next_prg;

if (copy_from_user(&v, argp, sizeof(v)))
if (unlikely(copy_from_user(&v, argp, sizeof(v))))
return -EFAULT;

d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel);
if (d == NULL) return -EFAULT;
if (unlikely(d == NULL))
return -EFAULT;

if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) {
if (unlikely((v.buffer<0) || (v.buffer>=d->num_desc - 1))) {
PRINT(KERN_ERR, ohci->host->id,
"Buffer %d out of range",v.buffer);
return -EINVAL;
}

spin_lock_irqsave(&d->lock,flags);

if (d->buffer_status[v.buffer]==VIDEO1394_BUFFER_QUEUED) {
if (unlikely(d->buffer_status[v.buffer]==VIDEO1394_BUFFER_QUEUED)) {
PRINT(KERN_ERR, ohci->host->id,
"Buffer %d is already used",v.buffer);
spin_unlock_irqrestore(&d->lock,flags);
Expand Down Expand Up @@ -949,13 +950,14 @@ static int __video1394_ioctl(struct file *file,
struct dma_iso_ctx *d;
int i = 0;

if (copy_from_user(&v, argp, sizeof(v)))
if (unlikely(copy_from_user(&v, argp, sizeof(v))))
return -EFAULT;

d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel);
if (d == NULL) return -EFAULT;
if (unlikely(d == NULL))
return -EFAULT;

if ((v.buffer<0) || (v.buffer>d->num_desc - 1)) {
if (unlikely((v.buffer<0) || (v.buffer>d->num_desc - 1))) {
PRINT(KERN_ERR, ohci->host->id,
"Buffer %d out of range",v.buffer);
return -EINVAL;
Expand Down Expand Up @@ -1008,7 +1010,7 @@ static int __video1394_ioctl(struct file *file,
spin_unlock_irqrestore(&d->lock, flags);

v.buffer=i;
if (copy_to_user(argp, &v, sizeof(v)))
if (unlikely(copy_to_user(argp, &v, sizeof(v))))
return -EFAULT;

return 0;
Expand Down

0 comments on commit 3c21cfc

Please sign in to comment.