aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAlan Cox <alan@lxorguk.ukuu.org.uk>2006-03-20 11:59:42 -0500
committerMauro Carvalho Chehab <mchehab@infradead.org>2006-03-24 14:26:52 -0500
commit2ae151911e31e6a012a46431cc515cc251242573 (patch)
treeb0c10dad3622738f9f3e08d14f817d53c143dd59 /drivers
parentbc2c7c365bd18c00f5fefaf1a560c440f3ce13f3 (diff)
V4L/DVB (3569): PATCH: switch cpia2 to mutexes and use ioctl 32 compat lib func
Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/cpia2/cpia2.h2
-rw-r--r--drivers/media/video/cpia2/cpia2_core.c40
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c43
3 files changed, 43 insertions, 42 deletions
diff --git a/drivers/media/video/cpia2/cpia2.h b/drivers/media/video/cpia2/cpia2.h
index 95d3afa94a3d..8394283993f6 100644
--- a/drivers/media/video/cpia2/cpia2.h
+++ b/drivers/media/video/cpia2/cpia2.h
@@ -381,7 +381,7 @@ struct cpia2_fh {
381 381
382struct camera_data { 382struct camera_data {
383 /* locks */ 383 /* locks */
384 struct semaphore busy_lock; /* guard against SMP multithreading */ 384 struct mutex busy_lock; /* guard against SMP multithreading */
385 struct v4l2_prio_state prio; 385 struct v4l2_prio_state prio;
386 386
387 /* camera status */ 387 /* camera status */
diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
index 5dfb242d5b8c..fd771c7a2fe2 100644
--- a/drivers/media/video/cpia2/cpia2_core.c
+++ b/drivers/media/video/cpia2/cpia2_core.c
@@ -2238,7 +2238,7 @@ struct camera_data *cpia2_init_camera_struct(void)
2238 memset(cam, 0, sizeof(struct camera_data)); 2238 memset(cam, 0, sizeof(struct camera_data));
2239 2239
2240 cam->present = 1; 2240 cam->present = 1;
2241 init_MUTEX(&cam->busy_lock); 2241 mutex_init(&cam->busy_lock);
2242 init_waitqueue_head(&cam->wq_stream); 2242 init_waitqueue_head(&cam->wq_stream);
2243 2243
2244 return cam; 2244 return cam;
@@ -2371,12 +2371,12 @@ long cpia2_read(struct camera_data *cam,
2371 } 2371 }
2372 2372
2373 /* make this _really_ smp and multithread-safe */ 2373 /* make this _really_ smp and multithread-safe */
2374 if (down_interruptible(&cam->busy_lock)) 2374 if (mutex_lock_interruptible(&cam->busy_lock))
2375 return -ERESTARTSYS; 2375 return -ERESTARTSYS;
2376 2376
2377 if (!cam->present) { 2377 if (!cam->present) {
2378 LOG("%s: camera removed\n",__FUNCTION__); 2378 LOG("%s: camera removed\n",__FUNCTION__);
2379 up(&cam->busy_lock); 2379 mutex_unlock(&cam->busy_lock);
2380 return 0; /* EOF */ 2380 return 0; /* EOF */
2381 } 2381 }
2382 2382
@@ -2389,34 +2389,34 @@ long cpia2_read(struct camera_data *cam,
2389 /* Copy cam->curbuff in case it changes while we're processing */ 2389 /* Copy cam->curbuff in case it changes while we're processing */
2390 frame = cam->curbuff; 2390 frame = cam->curbuff;
2391 if (noblock && frame->status != FRAME_READY) { 2391 if (noblock && frame->status != FRAME_READY) {
2392 up(&cam->busy_lock); 2392 mutex_unlock(&cam->busy_lock);
2393 return -EAGAIN; 2393 return -EAGAIN;
2394 } 2394 }
2395 2395
2396 if(frame->status != FRAME_READY) { 2396 if(frame->status != FRAME_READY) {
2397 up(&cam->busy_lock); 2397 mutex_unlock(&cam->busy_lock);
2398 wait_event_interruptible(cam->wq_stream, 2398 wait_event_interruptible(cam->wq_stream,
2399 !cam->present || 2399 !cam->present ||
2400 (frame = cam->curbuff)->status == FRAME_READY); 2400 (frame = cam->curbuff)->status == FRAME_READY);
2401 if (signal_pending(current)) 2401 if (signal_pending(current))
2402 return -ERESTARTSYS; 2402 return -ERESTARTSYS;
2403 /* make this _really_ smp and multithread-safe */ 2403 /* make this _really_ smp and multithread-safe */
2404 if (down_interruptible(&cam->busy_lock)) { 2404 if (mutex_lock_interruptible(&cam->busy_lock)) {
2405 return -ERESTARTSYS; 2405 return -ERESTARTSYS;
2406 } 2406 }
2407 if(!cam->present) { 2407 if(!cam->present) {
2408 up(&cam->busy_lock); 2408 mutex_unlock(&cam->busy_lock);
2409 return 0; 2409 return 0;
2410 } 2410 }
2411 } 2411 }
2412 2412
2413 /* copy data to user space */ 2413 /* copy data to user space */
2414 if (frame->length > count) { 2414 if (frame->length > count) {
2415 up(&cam->busy_lock); 2415 mutex_unlock(&cam->busy_lock);
2416 return -EFAULT; 2416 return -EFAULT;
2417 } 2417 }
2418 if (copy_to_user(buf, frame->data, frame->length)) { 2418 if (copy_to_user(buf, frame->data, frame->length)) {
2419 up(&cam->busy_lock); 2419 mutex_unlock(&cam->busy_lock);
2420 return -EFAULT; 2420 return -EFAULT;
2421 } 2421 }
2422 2422
@@ -2424,7 +2424,7 @@ long cpia2_read(struct camera_data *cam,
2424 2424
2425 frame->status = FRAME_EMPTY; 2425 frame->status = FRAME_EMPTY;
2426 2426
2427 up(&cam->busy_lock); 2427 mutex_unlock(&cam->busy_lock);
2428 return count; 2428 return count;
2429} 2429}
2430 2430
@@ -2443,10 +2443,10 @@ unsigned int cpia2_poll(struct camera_data *cam, struct file *filp,
2443 return POLLERR; 2443 return POLLERR;
2444 } 2444 }
2445 2445
2446 down(&cam->busy_lock); 2446 mutex_lock(&cam->busy_lock);
2447 2447
2448 if(!cam->present) { 2448 if(!cam->present) {
2449 up(&cam->busy_lock); 2449 mutex_unlock(&cam->busy_lock);
2450 return POLLHUP; 2450 return POLLHUP;
2451 } 2451 }
2452 2452
@@ -2456,16 +2456,16 @@ unsigned int cpia2_poll(struct camera_data *cam, struct file *filp,
2456 cam->params.camera_state.stream_mode); 2456 cam->params.camera_state.stream_mode);
2457 } 2457 }
2458 2458
2459 up(&cam->busy_lock); 2459 mutex_unlock(&cam->busy_lock);
2460 poll_wait(filp, &cam->wq_stream, wait); 2460 poll_wait(filp, &cam->wq_stream, wait);
2461 down(&cam->busy_lock); 2461 mutex_lock(&cam->busy_lock);
2462 2462
2463 if(!cam->present) 2463 if(!cam->present)
2464 status = POLLHUP; 2464 status = POLLHUP;
2465 else if(cam->curbuff->status == FRAME_READY) 2465 else if(cam->curbuff->status == FRAME_READY)
2466 status = POLLIN | POLLRDNORM; 2466 status = POLLIN | POLLRDNORM;
2467 2467
2468 up(&cam->busy_lock); 2468 mutex_unlock(&cam->busy_lock);
2469 return status; 2469 return status;
2470} 2470}
2471 2471
@@ -2488,18 +2488,18 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
2488 DBG("mmap offset:%ld size:%ld\n", start_offset, size); 2488 DBG("mmap offset:%ld size:%ld\n", start_offset, size);
2489 2489
2490 /* make this _really_ smp-safe */ 2490 /* make this _really_ smp-safe */
2491 if (down_interruptible(&cam->busy_lock)) 2491 if (mutex_lock_interruptible(&cam->busy_lock))
2492 return -ERESTARTSYS; 2492 return -ERESTARTSYS;
2493 2493
2494 if (!cam->present) { 2494 if (!cam->present) {
2495 up(&cam->busy_lock); 2495 mutex_unlock(&cam->busy_lock);
2496 return -ENODEV; 2496 return -ENODEV;
2497 } 2497 }
2498 2498
2499 if (size > cam->frame_size*cam->num_frames || 2499 if (size > cam->frame_size*cam->num_frames ||
2500 (start_offset % cam->frame_size) != 0 || 2500 (start_offset % cam->frame_size) != 0 ||
2501 (start_offset+size > cam->frame_size*cam->num_frames)) { 2501 (start_offset+size > cam->frame_size*cam->num_frames)) {
2502 up(&cam->busy_lock); 2502 mutex_unlock(&cam->busy_lock);
2503 return -EINVAL; 2503 return -EINVAL;
2504 } 2504 }
2505 2505
@@ -2507,7 +2507,7 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
2507 while (size > 0) { 2507 while (size > 0) {
2508 page = kvirt_to_pa(pos); 2508 page = kvirt_to_pa(pos);
2509 if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, PAGE_SIZE, PAGE_SHARED)) { 2509 if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, PAGE_SIZE, PAGE_SHARED)) {
2510 up(&cam->busy_lock); 2510 mutex_unlock(&cam->busy_lock);
2511 return -EAGAIN; 2511 return -EAGAIN;
2512 } 2512 }
2513 start += PAGE_SIZE; 2513 start += PAGE_SIZE;
@@ -2519,7 +2519,7 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
2519 } 2519 }
2520 2520
2521 cam->mmapped = true; 2521 cam->mmapped = true;
2522 up(&cam->busy_lock); 2522 mutex_unlock(&cam->busy_lock);
2523 return 0; 2523 return 0;
2524} 2524}
2525 2525
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index 08f8be345fa8..481e178ef56d 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -255,7 +255,7 @@ static int cpia2_open(struct inode *inode, struct file *file)
255 return -ENODEV; 255 return -ENODEV;
256 } 256 }
257 257
258 if(down_interruptible(&cam->busy_lock)) 258 if(mutex_lock_interruptible(&cam->busy_lock))
259 return -ERESTARTSYS; 259 return -ERESTARTSYS;
260 260
261 if(!cam->present) { 261 if(!cam->present) {
@@ -299,7 +299,7 @@ skip_init:
299 cpia2_dbg_dump_registers(cam); 299 cpia2_dbg_dump_registers(cam);
300 300
301err_return: 301err_return:
302 up(&cam->busy_lock); 302 mutex_unlock(&cam->busy_lock);
303 return retval; 303 return retval;
304} 304}
305 305
@@ -314,7 +314,7 @@ static int cpia2_close(struct inode *inode, struct file *file)
314 struct camera_data *cam = video_get_drvdata(dev); 314 struct camera_data *cam = video_get_drvdata(dev);
315 struct cpia2_fh *fh = file->private_data; 315 struct cpia2_fh *fh = file->private_data;
316 316
317 down(&cam->busy_lock); 317 mutex_lock(&cam->busy_lock);
318 318
319 if (cam->present && 319 if (cam->present &&
320 (cam->open_count == 1 320 (cam->open_count == 1
@@ -347,7 +347,7 @@ static int cpia2_close(struct inode *inode, struct file *file)
347 } 347 }
348 } 348 }
349 349
350 up(&cam->busy_lock); 350 mutex_unlock(&cam->busy_lock);
351 351
352 return 0; 352 return 0;
353} 353}
@@ -523,11 +523,11 @@ static int sync(struct camera_data *cam, int frame_nr)
523 return 0; 523 return 0;
524 } 524 }
525 525
526 up(&cam->busy_lock); 526 mutex_unlock(&cam->busy_lock);
527 wait_event_interruptible(cam->wq_stream, 527 wait_event_interruptible(cam->wq_stream,
528 !cam->streaming || 528 !cam->streaming ||
529 frame->status == FRAME_READY); 529 frame->status == FRAME_READY);
530 down(&cam->busy_lock); 530 mutex_lock(&cam->busy_lock);
531 if (signal_pending(current)) 531 if (signal_pending(current))
532 return -ERESTARTSYS; 532 return -ERESTARTSYS;
533 if(!cam->present) 533 if(!cam->present)
@@ -1544,11 +1544,11 @@ static int ioctl_dqbuf(void *arg,struct camera_data *cam, struct file *file)
1544 if(frame < 0) { 1544 if(frame < 0) {
1545 /* Wait for a frame to become available */ 1545 /* Wait for a frame to become available */
1546 struct framebuf *cb=cam->curbuff; 1546 struct framebuf *cb=cam->curbuff;
1547 up(&cam->busy_lock); 1547 mutex_unlock(&cam->busy_lock);
1548 wait_event_interruptible(cam->wq_stream, 1548 wait_event_interruptible(cam->wq_stream,
1549 !cam->present || 1549 !cam->present ||
1550 (cb=cam->curbuff)->status == FRAME_READY); 1550 (cb=cam->curbuff)->status == FRAME_READY);
1551 down(&cam->busy_lock); 1551 mutex_lock(&cam->busy_lock);
1552 if (signal_pending(current)) 1552 if (signal_pending(current))
1553 return -ERESTARTSYS; 1553 return -ERESTARTSYS;
1554 if(!cam->present) 1554 if(!cam->present)
@@ -1591,11 +1591,11 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1591 return -ENOTTY; 1591 return -ENOTTY;
1592 1592
1593 /* make this _really_ smp-safe */ 1593 /* make this _really_ smp-safe */
1594 if (down_interruptible(&cam->busy_lock)) 1594 if (mutex_lock_interruptible(&cam->busy_lock))
1595 return -ERESTARTSYS; 1595 return -ERESTARTSYS;
1596 1596
1597 if (!cam->present) { 1597 if (!cam->present) {
1598 up(&cam->busy_lock); 1598 mutex_unlock(&cam->busy_lock);
1599 return -ENODEV; 1599 return -ENODEV;
1600 } 1600 }
1601 1601
@@ -1608,7 +1608,7 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1608 struct cpia2_fh *fh = file->private_data; 1608 struct cpia2_fh *fh = file->private_data;
1609 retval = v4l2_prio_check(&cam->prio, &fh->prio); 1609 retval = v4l2_prio_check(&cam->prio, &fh->prio);
1610 if(retval) { 1610 if(retval) {
1611 up(&cam->busy_lock); 1611 mutex_unlock(&cam->busy_lock);
1612 return retval; 1612 return retval;
1613 } 1613 }
1614 break; 1614 break;
@@ -1618,7 +1618,7 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1618 { 1618 {
1619 struct cpia2_fh *fh = file->private_data; 1619 struct cpia2_fh *fh = file->private_data;
1620 if(fh->prio != V4L2_PRIORITY_RECORD) { 1620 if(fh->prio != V4L2_PRIORITY_RECORD) {
1621 up(&cam->busy_lock); 1621 mutex_unlock(&cam->busy_lock);
1622 return -EBUSY; 1622 return -EBUSY;
1623 } 1623 }
1624 break; 1624 break;
@@ -1847,7 +1847,7 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1847 break; 1847 break;
1848 } 1848 }
1849 1849
1850 up(&cam->busy_lock); 1850 mutex_unlock(&cam->busy_lock);
1851 return retval; 1851 return retval;
1852} 1852}
1853 1853
@@ -1924,14 +1924,15 @@ static void reset_camera_struct_v4l(struct camera_data *cam)
1924 * The v4l video device structure initialized for this device 1924 * The v4l video device structure initialized for this device
1925 ***/ 1925 ***/
1926static struct file_operations fops_template = { 1926static struct file_operations fops_template = {
1927 .owner= THIS_MODULE, 1927 .owner = THIS_MODULE,
1928 .open= cpia2_open, 1928 .open = cpia2_open,
1929 .release= cpia2_close, 1929 .release = cpia2_close,
1930 .read= cpia2_v4l_read, 1930 .read = cpia2_v4l_read,
1931 .poll= cpia2_v4l_poll, 1931 .poll = cpia2_v4l_poll,
1932 .ioctl= cpia2_ioctl, 1932 .ioctl = cpia2_ioctl,
1933 .llseek= no_llseek, 1933 .llseek = no_llseek,
1934 .mmap= cpia2_mmap, 1934 .compat_ioctl = v4l_compat_ioctl32,
1935 .mmap = cpia2_mmap,
1935}; 1936};
1936 1937
1937static struct video_device cpia2_template = { 1938static struct video_device cpia2_template = {