aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Szyprowski <m.szyprowski@samsung.com>2011-12-15 03:53:06 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-12-30 13:07:43 -0500
commita00d02663735df4027809da4412280925c7c9453 (patch)
treef25e4a0c14e2ca6ddecd81057a367bcf8fcc377b
parent5931ffe3bee6216e59faf18b317dea4e637eef03 (diff)
[media] media: vb2: review mem_priv usage and fix potential bugs
This patch is a result of review of mem_priv entry usage in videobuf2 core. It fixes all all potential places where it was not checked against NULL or zeroed after freeing as well as a few style issues. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> CC: Pawel Osciak <pawel@osciak.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/video/videobuf2-core.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/drivers/media/video/videobuf2-core.c b/drivers/media/video/videobuf2-core.c
index 9dc887b2aac0..26cfbf5c9f8c 100644
--- a/drivers/media/video/videobuf2-core.c
+++ b/drivers/media/video/videobuf2-core.c
@@ -65,8 +65,10 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
65 return 0; 65 return 0;
66free: 66free:
67 /* Free already allocated memory if one of the allocations failed */ 67 /* Free already allocated memory if one of the allocations failed */
68 for (; plane > 0; --plane) 68 for (; plane > 0; --plane) {
69 call_memop(q, put, vb->planes[plane - 1].mem_priv); 69 call_memop(q, put, vb->planes[plane - 1].mem_priv);
70 vb->planes[plane - 1].mem_priv = NULL;
71 }
70 72
71 return -ENOMEM; 73 return -ENOMEM;
72} 74}
@@ -82,8 +84,8 @@ static void __vb2_buf_mem_free(struct vb2_buffer *vb)
82 for (plane = 0; plane < vb->num_planes; ++plane) { 84 for (plane = 0; plane < vb->num_planes; ++plane) {
83 call_memop(q, put, vb->planes[plane].mem_priv); 85 call_memop(q, put, vb->planes[plane].mem_priv);
84 vb->planes[plane].mem_priv = NULL; 86 vb->planes[plane].mem_priv = NULL;
85 dprintk(3, "Freed plane %d of buffer %d\n", 87 dprintk(3, "Freed plane %d of buffer %d\n", plane,
86 plane, vb->v4l2_buf.index); 88 vb->v4l2_buf.index);
87 } 89 }
88} 90}
89 91
@@ -97,12 +99,9 @@ static void __vb2_buf_userptr_put(struct vb2_buffer *vb)
97 unsigned int plane; 99 unsigned int plane;
98 100
99 for (plane = 0; plane < vb->num_planes; ++plane) { 101 for (plane = 0; plane < vb->num_planes; ++plane) {
100 void *mem_priv = vb->planes[plane].mem_priv; 102 if (vb->planes[plane].mem_priv)
101 103 call_memop(q, put_userptr, vb->planes[plane].mem_priv);
102 if (mem_priv) { 104 vb->planes[plane].mem_priv = NULL;
103 call_memop(q, put_userptr, mem_priv);
104 vb->planes[plane].mem_priv = NULL;
105 }
106 } 105 }
107} 106}
108 107
@@ -731,7 +730,7 @@ void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no)
731{ 730{
732 struct vb2_queue *q = vb->vb2_queue; 731 struct vb2_queue *q = vb->vb2_queue;
733 732
734 if (plane_no > vb->num_planes) 733 if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
735 return NULL; 734 return NULL;
736 735
737 return call_memop(q, vaddr, vb->planes[plane_no].mem_priv); 736 return call_memop(q, vaddr, vb->planes[plane_no].mem_priv);
@@ -754,7 +753,7 @@ void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no)
754{ 753{
755 struct vb2_queue *q = vb->vb2_queue; 754 struct vb2_queue *q = vb->vb2_queue;
756 755
757 if (plane_no > vb->num_planes) 756 if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
758 return NULL; 757 return NULL;
759 758
760 return call_memop(q, cookie, vb->planes[plane_no].mem_priv); 759 return call_memop(q, cookie, vb->planes[plane_no].mem_priv);
@@ -906,19 +905,16 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
906 vb->v4l2_planes[plane].length = 0; 905 vb->v4l2_planes[plane].length = 0;
907 906
908 /* Acquire each plane's memory */ 907 /* Acquire each plane's memory */
909 if (q->mem_ops->get_userptr) { 908 mem_priv = call_memop(q, get_userptr, q->alloc_ctx[plane],
910 mem_priv = q->mem_ops->get_userptr(q->alloc_ctx[plane], 909 planes[plane].m.userptr,
911 planes[plane].m.userptr, 910 planes[plane].length, write);
912 planes[plane].length, 911 if (IS_ERR_OR_NULL(mem_priv)) {
913 write); 912 dprintk(1, "qbuf: failed acquiring userspace "
914 if (IS_ERR(mem_priv)) {
915 dprintk(1, "qbuf: failed acquiring userspace "
916 "memory for plane %d\n", plane); 913 "memory for plane %d\n", plane);
917 ret = PTR_ERR(mem_priv); 914 ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
918 goto err; 915 goto err;
919 }
920 vb->planes[plane].mem_priv = mem_priv;
921 } 916 }
917 vb->planes[plane].mem_priv = mem_priv;
922 } 918 }
923 919
924 /* 920 /*
@@ -1553,7 +1549,6 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
1553int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) 1549int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
1554{ 1550{
1555 unsigned long off = vma->vm_pgoff << PAGE_SHIFT; 1551 unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
1556 struct vb2_plane *vb_plane;
1557 struct vb2_buffer *vb; 1552 struct vb2_buffer *vb;
1558 unsigned int buffer, plane; 1553 unsigned int buffer, plane;
1559 int ret; 1554 int ret;
@@ -1590,9 +1585,8 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
1590 return ret; 1585 return ret;
1591 1586
1592 vb = q->bufs[buffer]; 1587 vb = q->bufs[buffer];
1593 vb_plane = &vb->planes[plane];
1594 1588
1595 ret = q->mem_ops->mmap(vb_plane->mem_priv, vma); 1589 ret = call_memop(q, mmap, vb->planes[plane].mem_priv, vma);
1596 if (ret) 1590 if (ret)
1597 return ret; 1591 return ret;
1598 1592