Skip to content

Commit

Permalink
V4L/DVB: v4l: videobuf: code cleanup
Browse files Browse the repository at this point in the history
Make videobuf pass checkpatch; minor code cleanups.

Signed-off-by: Pawel Osciak <[email protected]>
Reviewed-by: Kyungmin Park <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
Pawel Osciak authored and Mauro Carvalho Chehab committed May 18, 2010
1 parent 85e0921 commit 7a02264
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 281 deletions.
116 changes: 53 additions & 63 deletions drivers/media/video/videobuf-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
#include <media/videobuf-core.h>

#define MAGIC_BUFFER 0x20070728
#define MAGIC_CHECK(is, should) do { \
if (unlikely((is) != (should))) { \
printk(KERN_ERR "magic mismatch: %x (expected %x)\n", is, should); \
BUG(); } } while (0)
#define MAGIC_CHECK(is, should) \
do { \
if (unlikely((is) != (should))) { \
printk(KERN_ERR \
"magic mismatch: %x (expected %x)\n", \
is, should); \
BUG(); \
} \
} while (0)

static int debug;
module_param(debug, int, 0644);
Expand All @@ -36,9 +41,11 @@ MODULE_DESCRIPTION("helper module to manage video4linux buffers");
MODULE_AUTHOR("Mauro Carvalho Chehab <[email protected]>");
MODULE_LICENSE("GPL");

#define dprintk(level, fmt, arg...) do { \
if (debug >= level) \
printk(KERN_DEBUG "vbuf: " fmt , ## arg); } while (0)
#define dprintk(level, fmt, arg...) \
do { \
if (debug >= level) \
printk(KERN_DEBUG "vbuf: " fmt, ## arg); \
} while (0)

/* --------------------------------------------------------------------- */

Expand All @@ -57,14 +64,14 @@ void *videobuf_alloc(struct videobuf_queue *q)
}

vb = q->int_ops->alloc(q->msize);

if (NULL != vb) {
init_waitqueue_head(&vb->done);
vb->magic = MAGIC_BUFFER;
vb->magic = MAGIC_BUFFER;
}

return vb;
}
EXPORT_SYMBOL_GPL(videobuf_alloc);

#define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\
vb->state != VIDEOBUF_QUEUED)
Expand All @@ -86,6 +93,7 @@ int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)

return 0;
}
EXPORT_SYMBOL_GPL(videobuf_waiton);

int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
struct v4l2_framebuffer *fbuf)
Expand All @@ -95,9 +103,10 @@ int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,

return CALL(q, iolock, q, vb, fbuf);
}
EXPORT_SYMBOL_GPL(videobuf_iolock);

void *videobuf_queue_to_vmalloc (struct videobuf_queue *q,
struct videobuf_buffer *buf)
void *videobuf_queue_to_vmalloc(struct videobuf_queue *q,
struct videobuf_buffer *buf)
{
if (q->int_ops->vmalloc)
return q->int_ops->vmalloc(buf);
Expand Down Expand Up @@ -146,6 +155,7 @@ void videobuf_queue_core_init(struct videobuf_queue *q,
init_waitqueue_head(&q->wait);
INIT_LIST_HEAD(&q->stream);
}
EXPORT_SYMBOL_GPL(videobuf_queue_core_init);

/* Locking: Only usage in bttv unsafe find way to remove */
int videobuf_queue_is_busy(struct videobuf_queue *q)
Expand Down Expand Up @@ -184,6 +194,7 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
}
return 0;
}
EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);

/* Locking: Caller holds q->vb_lock */
void videobuf_queue_cancel(struct videobuf_queue *q)
Expand Down Expand Up @@ -216,6 +227,7 @@ void videobuf_queue_cancel(struct videobuf_queue *q)
}
INIT_LIST_HEAD(&q->stream);
}
EXPORT_SYMBOL_GPL(videobuf_queue_cancel);

/* --------------------------------------------------------------------- */

Expand All @@ -237,6 +249,7 @@ enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
}
return field;
}
EXPORT_SYMBOL_GPL(videobuf_next_field);

/* Locking: Caller holds q->vb_lock */
static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
Expand Down Expand Up @@ -305,8 +318,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)

MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);


rc = CALL(q, mmap_free, q);
rc = CALL(q, mmap_free, q);

q->is_mmapped = 0;

Expand All @@ -332,6 +344,7 @@ int videobuf_mmap_free(struct videobuf_queue *q)
mutex_unlock(&q->vb_lock);
return ret;
}
EXPORT_SYMBOL_GPL(videobuf_mmap_free);

/* Locking: Caller holds q->vb_lock */
int __videobuf_mmap_setup(struct videobuf_queue *q,
Expand All @@ -351,7 +364,7 @@ int __videobuf_mmap_setup(struct videobuf_queue *q,
for (i = 0; i < bcount; i++) {
q->bufs[i] = videobuf_alloc(q);

if (q->bufs[i] == NULL)
if (NULL == q->bufs[i])
break;

q->bufs[i]->i = i;
Expand All @@ -372,11 +385,11 @@ int __videobuf_mmap_setup(struct videobuf_queue *q,
if (!i)
return -ENOMEM;

dprintk(1, "mmap setup: %d buffers, %d bytes each\n",
i, bsize);
dprintk(1, "mmap setup: %d buffers, %d bytes each\n", i, bsize);

return i;
}
EXPORT_SYMBOL_GPL(__videobuf_mmap_setup);

int videobuf_mmap_setup(struct videobuf_queue *q,
unsigned int bcount, unsigned int bsize,
Expand All @@ -388,6 +401,7 @@ int videobuf_mmap_setup(struct videobuf_queue *q,
mutex_unlock(&q->vb_lock);
return ret;
}
EXPORT_SYMBOL_GPL(videobuf_mmap_setup);

int videobuf_reqbufs(struct videobuf_queue *q,
struct v4l2_requestbuffers *req)
Expand Down Expand Up @@ -432,7 +446,7 @@ int videobuf_reqbufs(struct videobuf_queue *q,
q->ops->buf_setup(q, &count, &size);
dprintk(1, "reqbufs: bufs=%d, size=0x%x [%u pages total]\n",
count, size,
(unsigned int)((count*PAGE_ALIGN(size))>>PAGE_SHIFT) );
(unsigned int)((count * PAGE_ALIGN(size)) >> PAGE_SHIFT));

retval = __videobuf_mmap_setup(q, count, size, req->memory);
if (retval < 0) {
Expand All @@ -447,6 +461,7 @@ int videobuf_reqbufs(struct videobuf_queue *q,
mutex_unlock(&q->vb_lock);
return retval;
}
EXPORT_SYMBOL_GPL(videobuf_reqbufs);

int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
{
Expand All @@ -473,9 +488,9 @@ int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
mutex_unlock(&q->vb_lock);
return ret;
}
EXPORT_SYMBOL_GPL(videobuf_querybuf);

int videobuf_qbuf(struct videobuf_queue *q,
struct v4l2_buffer *b)
int videobuf_qbuf(struct videobuf_queue *q, struct v4l2_buffer *b)
{
struct videobuf_buffer *buf;
enum v4l2_field field;
Expand Down Expand Up @@ -571,15 +586,15 @@ int videobuf_qbuf(struct videobuf_queue *q,
retval = 0;
wake_up_interruptible_sync(&q->wait);

done:
done:
mutex_unlock(&q->vb_lock);

if (b->memory == V4L2_MEMORY_MMAP)
up_read(&current->mm->mmap_sem);

return retval;
}

EXPORT_SYMBOL_GPL(videobuf_qbuf);

/* Locking: Caller holds q->vb_lock */
static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
Expand Down Expand Up @@ -624,7 +639,6 @@ static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
return retval;
}


/* Locking: Caller holds q->vb_lock */
static int stream_next_buffer(struct videobuf_queue *q,
struct videobuf_buffer **vb, int nonblocking)
Expand All @@ -647,7 +661,7 @@ static int stream_next_buffer(struct videobuf_queue *q,
}

int videobuf_dqbuf(struct videobuf_queue *q,
struct v4l2_buffer *b, int nonblocking)
struct v4l2_buffer *b, int nonblocking)
{
struct videobuf_buffer *buf = NULL;
int retval;
Expand Down Expand Up @@ -682,11 +696,11 @@ int videobuf_dqbuf(struct videobuf_queue *q,
list_del(&buf->stream);
memset(b, 0, sizeof(*b));
videobuf_status(q, b, buf, q->type);

done:
done:
mutex_unlock(&q->vb_lock);
return retval;
}
EXPORT_SYMBOL_GPL(videobuf_dqbuf);

int videobuf_streamon(struct videobuf_queue *q)
{
Expand All @@ -709,10 +723,11 @@ int videobuf_streamon(struct videobuf_queue *q)
spin_unlock_irqrestore(q->irqlock, flags);

wake_up_interruptible_sync(&q->wait);
done:
done:
mutex_unlock(&q->vb_lock);
return retval;
}
EXPORT_SYMBOL_GPL(videobuf_streamon);

/* Locking: Caller holds q->vb_lock */
static int __videobuf_streamoff(struct videobuf_queue *q)
Expand All @@ -735,6 +750,7 @@ int videobuf_streamoff(struct videobuf_queue *q)

return retval;
}
EXPORT_SYMBOL_GPL(videobuf_streamoff);

/* Locking: Caller holds q->vb_lock */
static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
Expand Down Expand Up @@ -774,7 +790,7 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
retval = q->read_buf->size;
}

done:
done:
/* cleanup */
q->ops->buf_release(q, q->read_buf);
kfree(q->read_buf);
Expand Down Expand Up @@ -862,10 +878,11 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
q->read_buf = NULL;
}

done:
done:
mutex_unlock(&q->vb_lock);
return retval;
}
EXPORT_SYMBOL_GPL(videobuf_read_one);

/* Locking: Caller holds q->vb_lock */
static int __videobuf_read_start(struct videobuf_queue *q)
Expand Down Expand Up @@ -917,7 +934,6 @@ static void __videobuf_read_stop(struct videobuf_queue *q)
q->bufs[i] = NULL;
}
q->read_buf = NULL;

}

int videobuf_read_start(struct videobuf_queue *q)
Expand All @@ -930,13 +946,15 @@ int videobuf_read_start(struct videobuf_queue *q)

return rc;
}
EXPORT_SYMBOL_GPL(videobuf_read_start);

void videobuf_read_stop(struct videobuf_queue *q)
{
mutex_lock(&q->vb_lock);
__videobuf_read_stop(q);
mutex_unlock(&q->vb_lock);
}
EXPORT_SYMBOL_GPL(videobuf_read_stop);

void videobuf_stop(struct videobuf_queue *q)
{
Expand All @@ -950,7 +968,7 @@ void videobuf_stop(struct videobuf_queue *q)

mutex_unlock(&q->vb_lock);
}

EXPORT_SYMBOL_GPL(videobuf_stop);

ssize_t videobuf_read_stream(struct videobuf_queue *q,
char __user *data, size_t count, loff_t *ppos,
Expand Down Expand Up @@ -1019,10 +1037,11 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
break;
}

done:
done:
mutex_unlock(&q->vb_lock);
return retval;
}
EXPORT_SYMBOL_GPL(videobuf_read_stream);

unsigned int videobuf_poll_stream(struct file *file,
struct videobuf_queue *q,
Expand Down Expand Up @@ -1062,9 +1081,9 @@ unsigned int videobuf_poll_stream(struct file *file,
mutex_unlock(&q->vb_lock);
return rc;
}
EXPORT_SYMBOL_GPL(videobuf_poll_stream);

int videobuf_mmap_mapper(struct videobuf_queue *q,
struct vm_area_struct *vma)
int videobuf_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma)
{
int retval;

Expand All @@ -1077,6 +1096,7 @@ int videobuf_mmap_mapper(struct videobuf_queue *q,

return retval;
}
EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);

#ifdef CONFIG_VIDEO_V4L1_COMPAT
int videobuf_cgmbuf(struct videobuf_queue *q,
Expand Down Expand Up @@ -1107,33 +1127,3 @@ int videobuf_cgmbuf(struct videobuf_queue *q,
EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
#endif

/* --------------------------------------------------------------------- */

EXPORT_SYMBOL_GPL(videobuf_waiton);
EXPORT_SYMBOL_GPL(videobuf_iolock);

EXPORT_SYMBOL_GPL(videobuf_alloc);

EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);

EXPORT_SYMBOL_GPL(videobuf_next_field);
EXPORT_SYMBOL_GPL(videobuf_reqbufs);
EXPORT_SYMBOL_GPL(videobuf_querybuf);
EXPORT_SYMBOL_GPL(videobuf_qbuf);
EXPORT_SYMBOL_GPL(videobuf_dqbuf);
EXPORT_SYMBOL_GPL(videobuf_streamon);
EXPORT_SYMBOL_GPL(videobuf_streamoff);

EXPORT_SYMBOL_GPL(videobuf_read_start);
EXPORT_SYMBOL_GPL(videobuf_read_stop);
EXPORT_SYMBOL_GPL(videobuf_stop);
EXPORT_SYMBOL_GPL(videobuf_read_stream);
EXPORT_SYMBOL_GPL(videobuf_read_one);
EXPORT_SYMBOL_GPL(videobuf_poll_stream);

EXPORT_SYMBOL_GPL(__videobuf_mmap_setup);
EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
EXPORT_SYMBOL_GPL(videobuf_mmap_free);
EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
Loading

0 comments on commit 7a02264

Please sign in to comment.