aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/videobuf-core.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2010-03-28 08:22:53 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-05-19 11:57:53 -0400
commit37111039c9521c751ce0597c129fe6d45ba72818 (patch)
tree00e6d6e75a4604a95d1062e6a2846196fd2054e8 /drivers/media/video/videobuf-core.c
parentf4fce60e8b1559306fa1112287bc8765f6977de3 (diff)
V4L/DVB: v4l videobuf: move video_copy_to_user and copy_stream to core
The video_copy_to_user and copy_stream ops are almost identical for all videobuf memtype variants. All that is needed is to use the new vaddr op and these functions can be moved into the core, ensuring we have just one single implementation instead of three. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/videobuf-core.c')
-rw-r--r--drivers/media/video/videobuf-core.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
index fabe45c4163e..f1dfcff44e1b 100644
--- a/drivers/media/video/videobuf-core.c
+++ b/drivers/media/video/videobuf-core.c
@@ -793,6 +793,49 @@ done:
793 return retval; 793 return retval;
794} 794}
795 795
796static int __videobuf_copy_to_user(struct videobuf_queue *q,
797 struct videobuf_buffer *buf,
798 char __user *data, size_t count,
799 int nonblocking)
800{
801 void *vaddr = CALL(q, vaddr, buf);
802
803 /* copy to userspace */
804 if (count > buf->size - q->read_off)
805 count = buf->size - q->read_off;
806
807 if (copy_to_user(data, vaddr + q->read_off, count))
808 return -EFAULT;
809
810 return count;
811}
812
813static int __videobuf_copy_stream(struct videobuf_queue *q,
814 struct videobuf_buffer *buf,
815 char __user *data, size_t count, size_t pos,
816 int vbihack, int nonblocking)
817{
818 unsigned int *fc = CALL(q, vaddr, buf);
819
820 if (vbihack) {
821 /* dirty, undocumented hack -- pass the frame counter
822 * within the last four bytes of each vbi data block.
823 * We need that one to maintain backward compatibility
824 * to all vbi decoding software out there ... */
825 fc += (buf->size >> 2) - 1;
826 *fc = buf->field_count >> 1;
827 dprintk(1, "vbihack: %d\n", *fc);
828 }
829
830 /* copy stuff using the common method */
831 count = __videobuf_copy_to_user(q, buf, data, count, nonblocking);
832
833 if ((count == -EFAULT) && (pos == 0))
834 return -EFAULT;
835
836 return count;
837}
838
796ssize_t videobuf_read_one(struct videobuf_queue *q, 839ssize_t videobuf_read_one(struct videobuf_queue *q,
797 char __user *data, size_t count, loff_t *ppos, 840 char __user *data, size_t count, loff_t *ppos,
798 int nonblocking) 841 int nonblocking)
@@ -861,7 +904,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
861 } 904 }
862 905
863 /* Copy to userspace */ 906 /* Copy to userspace */
864 retval = CALL(q, video_copy_to_user, q, data, count, nonblocking); 907 retval = __videobuf_copy_to_user(q, q->read_buf, data, count, nonblocking);
865 if (retval < 0) 908 if (retval < 0)
866 goto done; 909 goto done;
867 910
@@ -1003,7 +1046,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
1003 } 1046 }
1004 1047
1005 if (q->read_buf->state == VIDEOBUF_DONE) { 1048 if (q->read_buf->state == VIDEOBUF_DONE) {
1006 rc = CALL(q, copy_stream, q, data + retval, count, 1049 rc = __videobuf_copy_stream(q, q->read_buf, data + retval, count,
1007 retval, vbihack, nonblocking); 1050 retval, vbihack, nonblocking);
1008 if (rc < 0) { 1051 if (rc < 0) {
1009 retval = rc; 1052 retval = rc;