aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/videobuf-vmalloc.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2007-09-27 17:25:44 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-10-09 23:02:55 -0400
commit851c0c96b2212f48fe51afc1589541b5eae3a544 (patch)
tree0ec4d6019033242fb75e717ca05c1f04d2eca934 /drivers/media/video/videobuf-vmalloc.c
parentcd4765efdd816ac14075fc7d5adf489502e75e1e (diff)
V4L/DVB (6266): videobuf cleanup: mmap check is common to all videobuf. Make it at core
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org> http://thread.gmane.org/gmane.comp.video.video4linux/34978/focus=34981 Reviewed-by: Ricardo Cerqueira <v4l@cerqueira.org>
Diffstat (limited to 'drivers/media/video/videobuf-vmalloc.c')
-rw-r--r--drivers/media/video/videobuf-vmalloc.c36
1 files changed, 10 insertions, 26 deletions
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index fd059cde63f..c9d6ae0d3b4 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -62,7 +62,6 @@ videobuf_vm_close(struct vm_area_struct *vma)
62{ 62{
63 struct videobuf_mapping *map = vma->vm_private_data; 63 struct videobuf_mapping *map = vma->vm_private_data;
64 struct videobuf_queue *q = map->q; 64 struct videobuf_queue *q = map->q;
65 struct videbuf_vmalloc_memory *mem;
66 int i; 65 int i;
67 66
68 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map, 67 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
@@ -75,19 +74,13 @@ videobuf_vm_close(struct vm_area_struct *vma)
75 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 74 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
76 if (NULL == q->bufs[i]) 75 if (NULL == q->bufs[i])
77 continue; 76 continue;
78 mem=q->bufs[i]->priv;
79 77
80 if (!mem) 78 if (q->bufs[i]->map != map)
81 continue;
82
83 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
84
85 if (mem->map != map)
86 continue; 79 continue;
87 80
88 q->ops->buf_release(q,q->bufs[i]); 81 q->ops->buf_release(q,q->bufs[i]);
89 82
90 mem->map = NULL; 83 q->bufs[i]->map = NULL;
91 q->bufs[i]->baddr = 0; 84 q->bufs[i]->baddr = 0;
92 } 85 }
93 mutex_unlock(&q->lock); 86 mutex_unlock(&q->lock);
@@ -191,8 +184,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
191 184
192 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 185 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
193 if (q->bufs[i]) { 186 if (q->bufs[i]) {
194 struct videbuf_vmalloc_memory *mem=q->bufs[i]->priv; 187 if (q->bufs[i]->map)
195 if (mem && mem->map)
196 return -EBUSY; 188 return -EBUSY;
197 } 189 }
198 } 190 }
@@ -227,12 +219,9 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
227 (vma->vm_pgoff << PAGE_SHIFT)); 219 (vma->vm_pgoff << PAGE_SHIFT));
228 return -EINVAL; 220 return -EINVAL;
229 } 221 }
230 mem=q->bufs[first]->priv;
231 BUG_ON (!mem);
232 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
233 222
234 /* create mapping + update buffer list */ 223 /* create mapping + update buffer list */
235 map = mem->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); 224 map = q->bufs[first]->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
236 if (NULL == map) 225 if (NULL == map)
237 return -ENOMEM; 226 return -ENOMEM;
238 227
@@ -246,14 +235,19 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
246 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; 235 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
247 vma->vm_private_data = map; 236 vma->vm_private_data = map;
248 237
238 mem=q->bufs[first]->priv;
239 BUG_ON (!mem);
240 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
241
249 /* Try to remap memory */ 242 /* Try to remap memory */
250 retval=remap_vmalloc_range(vma, mem->vmalloc,0); 243 retval=remap_vmalloc_range(vma, mem->vmalloc,0);
251 if (retval<0) { 244 if (retval<0) {
252 dprintk(1,"mmap: postponing remap_vmalloc_range\n"); 245 dprintk(1,"mmap: postponing remap_vmalloc_range\n");
246
253 mem->vma=kmalloc(sizeof(*vma),GFP_KERNEL); 247 mem->vma=kmalloc(sizeof(*vma),GFP_KERNEL);
254 if (!mem->vma) { 248 if (!mem->vma) {
255 kfree(map); 249 kfree(map);
256 mem->map=NULL; 250 q->bufs[first]->map=NULL;
257 return -ENOMEM; 251 return -ENOMEM;
258 } 252 }
259 memcpy(mem->vma,vma,sizeof(*vma)); 253 memcpy(mem->vma,vma,sizeof(*vma));
@@ -269,15 +263,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
269 return (0); 263 return (0);
270} 264}
271 265
272static int __videobuf_is_mmapped (struct videobuf_buffer *buf)
273{
274 struct videbuf_vmalloc_memory *mem=buf->priv;
275 BUG_ON (!mem);
276 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
277
278 return (mem->map)?1:0;
279}
280
281static int __videobuf_copy_to_user ( struct videobuf_queue *q, 266static int __videobuf_copy_to_user ( struct videobuf_queue *q,
282 char __user *data, size_t count, 267 char __user *data, size_t count,
283 int nonblocking ) 268 int nonblocking )
@@ -335,7 +320,6 @@ static struct videobuf_qtype_ops qops = {
335 .sync = __videobuf_sync, 320 .sync = __videobuf_sync,
336 .mmap_free = __videobuf_mmap_free, 321 .mmap_free = __videobuf_mmap_free,
337 .mmap_mapper = __videobuf_mmap_mapper, 322 .mmap_mapper = __videobuf_mmap_mapper,
338 .is_mmapped = __videobuf_is_mmapped,
339 .copy_to_user = __videobuf_copy_to_user, 323 .copy_to_user = __videobuf_copy_to_user,
340 .copy_stream = __videobuf_copy_stream, 324 .copy_stream = __videobuf_copy_stream,
341}; 325};