diff options
author | Lamarque Vieira Souza <lamarque@gmail.com> | 2009-07-22 15:54:51 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-09-12 11:18:07 -0400 |
commit | 76594c5315d843fb1d3bffe7a8e2559086755f72 (patch) | |
tree | 1f4cac05702d8c76b48a61a94ae55543b7c150f5 /drivers/media/video/zr364xx.c | |
parent | 8c5f32ac2f8c1b92149b08bba673ccecb7578e57 (diff) |
V4L/DVB (12326): zr364xx: error message when buffer is too small and code cleanup
. added code to print an error message when buffer is too small to hold frame
data, that is better than just a hard crash. Tested using MAX_FRAME_SIZE =
50000, lots of error messages appeared in /var/log/messages but no crash.
. removed line "f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;" in
zr364xx_vidioc_try_fmt_vid_cap, it should not be there.
. changes to improve performance (or at least not hurt it): removed some
unneeded debug messages; added macro FULL_DEBUG to enable debug messages in
performance critical places, this macro is disabled by default; removed "if
(frm->lpvbits == NULL)..." in zr364xx_read_video_callback because after
analisying the source code I concluded it will always results to false, so it
is not needed.
. some small code reorganization.
Signed-off-by: Lamarque V. Souza <lamarque@gmail.com>
Signed-off-by: Antoine Jacquet <royale@zerezo.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/zr364xx.c')
-rw-r--r-- | drivers/media/video/zr364xx.c | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c index 009f8733cb16..9aae011d92ab 100644 --- a/drivers/media/video/zr364xx.c +++ b/drivers/media/video/zr364xx.c | |||
@@ -66,6 +66,13 @@ | |||
66 | } \ | 66 | } \ |
67 | } while (0) | 67 | } while (0) |
68 | 68 | ||
69 | /*#define FULL_DEBUG 1*/ | ||
70 | #ifdef FULL_DEBUG | ||
71 | #define _DBG DBG | ||
72 | #else | ||
73 | #define _DBG(fmt, args...) | ||
74 | #endif | ||
75 | |||
69 | /* Init methods, need to find nicer names for these | 76 | /* Init methods, need to find nicer names for these |
70 | * the exact names of the chipsets would be the best if someone finds it */ | 77 | * the exact names of the chipsets would be the best if someone finds it */ |
71 | #define METHOD0 0 | 78 | #define METHOD0 0 |
@@ -375,7 +382,7 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count, | |||
375 | 382 | ||
376 | static void free_buffer(struct videobuf_queue *vq, struct zr364xx_buffer *buf) | 383 | static void free_buffer(struct videobuf_queue *vq, struct zr364xx_buffer *buf) |
377 | { | 384 | { |
378 | DBG("%s\n", __func__); | 385 | _DBG("%s\n", __func__); |
379 | 386 | ||
380 | if (in_interrupt()) | 387 | if (in_interrupt()) |
381 | BUG(); | 388 | BUG(); |
@@ -428,7 +435,7 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) | |||
428 | vb); | 435 | vb); |
429 | struct zr364xx_camera *cam = vq->priv_data; | 436 | struct zr364xx_camera *cam = vq->priv_data; |
430 | 437 | ||
431 | DBG("%s\n", __func__); | 438 | _DBG("%s\n", __func__); |
432 | 439 | ||
433 | buf->vb.state = VIDEOBUF_QUEUED; | 440 | buf->vb.state = VIDEOBUF_QUEUED; |
434 | list_add_tail(&buf->vb.queue, &cam->vidq.active); | 441 | list_add_tail(&buf->vb.queue, &cam->vidq.active); |
@@ -440,7 +447,7 @@ static void buffer_release(struct videobuf_queue *vq, | |||
440 | struct zr364xx_buffer *buf = container_of(vb, struct zr364xx_buffer, | 447 | struct zr364xx_buffer *buf = container_of(vb, struct zr364xx_buffer, |
441 | vb); | 448 | vb); |
442 | 449 | ||
443 | DBG("%s\n", __func__); | 450 | _DBG("%s\n", __func__); |
444 | free_buffer(vq, buf); | 451 | free_buffer(vq, buf); |
445 | } | 452 | } |
446 | 453 | ||
@@ -462,7 +469,7 @@ static ssize_t zr364xx_read(struct file *file, char __user *buf, size_t count, | |||
462 | { | 469 | { |
463 | struct zr364xx_camera *cam = video_drvdata(file); | 470 | struct zr364xx_camera *cam = video_drvdata(file); |
464 | 471 | ||
465 | DBG("%s\n", __func__); | 472 | _DBG("%s\n", __func__); |
466 | 473 | ||
467 | if (!buf) | 474 | if (!buf) |
468 | return -EINVAL; | 475 | return -EINVAL; |
@@ -582,7 +589,7 @@ static int zr364xx_read_video_callback(struct zr364xx_camera *cam, | |||
582 | int i = 0; | 589 | int i = 0; |
583 | unsigned char *ptr = NULL; | 590 | unsigned char *ptr = NULL; |
584 | 591 | ||
585 | /*DBG("buffer to user\n");*/ | 592 | _DBG("buffer to user\n"); |
586 | idx = cam->cur_frame; | 593 | idx = cam->cur_frame; |
587 | frm = &cam->buffer.frame[idx]; | 594 | frm = &cam->buffer.frame[idx]; |
588 | 595 | ||
@@ -600,12 +607,6 @@ static int zr364xx_read_video_callback(struct zr364xx_camera *cam, | |||
600 | return -EINVAL; | 607 | return -EINVAL; |
601 | } | 608 | } |
602 | 609 | ||
603 | if (frm->lpvbits == NULL) { | ||
604 | DBG("%s: frame buffer == NULL.%p %p %d\n", __func__, | ||
605 | frm, cam, idx); | ||
606 | return -ENOMEM; | ||
607 | } | ||
608 | |||
609 | psrc = (u8 *)pipe_info->transfer_buffer; | 610 | psrc = (u8 *)pipe_info->transfer_buffer; |
610 | ptr = pdest = frm->lpvbits; | 611 | ptr = pdest = frm->lpvbits; |
611 | 612 | ||
@@ -613,7 +614,7 @@ static int zr364xx_read_video_callback(struct zr364xx_camera *cam, | |||
613 | frm->ulState = ZR364XX_READ_FRAME; | 614 | frm->ulState = ZR364XX_READ_FRAME; |
614 | frm->cur_size = 0; | 615 | frm->cur_size = 0; |
615 | 616 | ||
616 | DBG("jpeg header, "); | 617 | _DBG("jpeg header, "); |
617 | memcpy(ptr, header1, sizeof(header1)); | 618 | memcpy(ptr, header1, sizeof(header1)); |
618 | ptr += sizeof(header1); | 619 | ptr += sizeof(header1); |
619 | header3 = 0; | 620 | header3 = 0; |
@@ -631,21 +632,28 @@ static int zr364xx_read_video_callback(struct zr364xx_camera *cam, | |||
631 | memcpy(ptr, psrc + 128, | 632 | memcpy(ptr, psrc + 128, |
632 | purb->actual_length - 128); | 633 | purb->actual_length - 128); |
633 | ptr += purb->actual_length - 128; | 634 | ptr += purb->actual_length - 128; |
634 | DBG("header : %d %d %d %d %d %d %d %d %d\n", | 635 | _DBG("header : %d %d %d %d %d %d %d %d %d\n", |
635 | psrc[0], psrc[1], psrc[2], | 636 | psrc[0], psrc[1], psrc[2], |
636 | psrc[3], psrc[4], psrc[5], | 637 | psrc[3], psrc[4], psrc[5], |
637 | psrc[6], psrc[7], psrc[8]); | 638 | psrc[6], psrc[7], psrc[8]); |
638 | frm->cur_size = ptr - pdest; | 639 | frm->cur_size = ptr - pdest; |
639 | } else { | 640 | } else { |
640 | pdest += frm->cur_size; | 641 | if (frm->cur_size + purb->actual_length > MAX_FRAME_SIZE) { |
641 | memcpy(pdest, psrc, purb->actual_length); | 642 | dev_info(&cam->udev->dev, |
642 | frm->cur_size += purb->actual_length; | 643 | "%s: buffer (%d bytes) too small to hold " |
644 | "frame data. Discarding frame data.\n", | ||
645 | __func__, MAX_FRAME_SIZE); | ||
646 | } else { | ||
647 | pdest += frm->cur_size; | ||
648 | memcpy(pdest, psrc, purb->actual_length); | ||
649 | frm->cur_size += purb->actual_length; | ||
650 | } | ||
643 | } | 651 | } |
644 | /*DBG("cur_size %lu urb size %d\n", frm->cur_size, | 652 | /*_DBG("cur_size %lu urb size %d\n", frm->cur_size, |
645 | purb->actual_length);*/ | 653 | purb->actual_length);*/ |
646 | 654 | ||
647 | if (purb->actual_length < pipe_info->transfer_size) { | 655 | if (purb->actual_length < pipe_info->transfer_size) { |
648 | DBG("****************Buffer[%d]full*************\n", idx); | 656 | _DBG("****************Buffer[%d]full*************\n", idx); |
649 | cam->last_frame = cam->cur_frame; | 657 | cam->last_frame = cam->cur_frame; |
650 | cam->cur_frame++; | 658 | cam->cur_frame++; |
651 | /* end of system frame ring buffer, start at zero */ | 659 | /* end of system frame ring buffer, start at zero */ |
@@ -680,7 +688,7 @@ static int zr364xx_read_video_callback(struct zr364xx_camera *cam, | |||
680 | if (cam->skip) | 688 | if (cam->skip) |
681 | cam->skip--; | 689 | cam->skip--; |
682 | else { | 690 | else { |
683 | DBG("jpeg(%lu): %d %d %d %d %d %d %d %d\n", | 691 | _DBG("jpeg(%lu): %d %d %d %d %d %d %d %d\n", |
684 | frm->cur_size, | 692 | frm->cur_size, |
685 | pdest[0], pdest[1], pdest[2], pdest[3], | 693 | pdest[0], pdest[1], pdest[2], pdest[3], |
686 | pdest[4], pdest[5], pdest[6], pdest[7]); | 694 | pdest[4], pdest[5], pdest[6], pdest[7]); |
@@ -707,7 +715,7 @@ static int res_get(struct zr364xx_camera *cam) | |||
707 | } | 715 | } |
708 | /* it's free, grab it */ | 716 | /* it's free, grab it */ |
709 | cam->resources = 1; | 717 | cam->resources = 1; |
710 | DBG("res: get\n"); | 718 | _DBG("res: get\n"); |
711 | mutex_unlock(&cam->lock); | 719 | mutex_unlock(&cam->lock); |
712 | return 1; | 720 | return 1; |
713 | } | 721 | } |
@@ -722,7 +730,7 @@ static void res_free(struct zr364xx_camera *cam) | |||
722 | mutex_lock(&cam->lock); | 730 | mutex_lock(&cam->lock); |
723 | cam->resources = 0; | 731 | cam->resources = 0; |
724 | mutex_unlock(&cam->lock); | 732 | mutex_unlock(&cam->lock); |
725 | DBG("res: put\n"); | 733 | _DBG("res: put\n"); |
726 | } | 734 | } |
727 | 735 | ||
728 | static int zr364xx_vidioc_querycap(struct file *file, void *priv, | 736 | static int zr364xx_vidioc_querycap(struct file *file, void *priv, |
@@ -881,7 +889,6 @@ static int zr364xx_vidioc_try_fmt_vid_cap(struct file *file, void *priv, | |||
881 | } | 889 | } |
882 | 890 | ||
883 | f->fmt.pix.field = V4L2_FIELD_NONE; | 891 | f->fmt.pix.field = V4L2_FIELD_NONE; |
884 | f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | ||
885 | f->fmt.pix.bytesperline = f->fmt.pix.width * 2; | 892 | f->fmt.pix.bytesperline = f->fmt.pix.width * 2; |
886 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; | 893 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
887 | f->fmt.pix.colorspace = 0; | 894 | f->fmt.pix.colorspace = 0; |
@@ -1017,7 +1024,7 @@ static int zr364xx_vidioc_qbuf(struct file *file, | |||
1017 | { | 1024 | { |
1018 | int rc; | 1025 | int rc; |
1019 | struct zr364xx_camera *cam = video_drvdata(file); | 1026 | struct zr364xx_camera *cam = video_drvdata(file); |
1020 | DBG("%s\n", __func__); | 1027 | _DBG("%s\n", __func__); |
1021 | rc = videobuf_qbuf(&cam->vb_vidq, p); | 1028 | rc = videobuf_qbuf(&cam->vb_vidq, p); |
1022 | return rc; | 1029 | return rc; |
1023 | } | 1030 | } |
@@ -1028,7 +1035,7 @@ static int zr364xx_vidioc_dqbuf(struct file *file, | |||
1028 | { | 1035 | { |
1029 | int rc; | 1036 | int rc; |
1030 | struct zr364xx_camera *cam = video_drvdata(file); | 1037 | struct zr364xx_camera *cam = video_drvdata(file); |
1031 | DBG("%s\n", __func__); | 1038 | _DBG("%s\n", __func__); |
1032 | rc = videobuf_dqbuf(&cam->vb_vidq, p, file->f_flags & O_NONBLOCK); | 1039 | rc = videobuf_dqbuf(&cam->vb_vidq, p, file->f_flags & O_NONBLOCK); |
1033 | return rc; | 1040 | return rc; |
1034 | } | 1041 | } |
@@ -1040,7 +1047,7 @@ static void read_pipe_completion(struct urb *purb) | |||
1040 | int pipe; | 1047 | int pipe; |
1041 | 1048 | ||
1042 | pipe_info = purb->context; | 1049 | pipe_info = purb->context; |
1043 | /*DBG("%s %p, status %d\n", __func__, purb, purb->status);*/ | 1050 | _DBG("%s %p, status %d\n", __func__, purb, purb->status); |
1044 | if (pipe_info == NULL) { | 1051 | if (pipe_info == NULL) { |
1045 | printk(KERN_ERR KBUILD_MODNAME ": no context!\n"); | 1052 | printk(KERN_ERR KBUILD_MODNAME ": no context!\n"); |
1046 | return; | 1053 | return; |
@@ -1151,7 +1158,6 @@ static void zr364xx_stop_readpipe(struct zr364xx_camera *cam) | |||
1151 | pipe_info->stream_urb = NULL; | 1158 | pipe_info->stream_urb = NULL; |
1152 | } | 1159 | } |
1153 | } | 1160 | } |
1154 | DBG("stop read pipe\n"); | ||
1155 | return; | 1161 | return; |
1156 | } | 1162 | } |
1157 | 1163 | ||
@@ -1214,7 +1220,6 @@ static int zr364xx_vidioc_streamon(struct file *file, void *priv, | |||
1214 | } else { | 1220 | } else { |
1215 | res_free(cam); | 1221 | res_free(cam); |
1216 | } | 1222 | } |
1217 | DBG("%s: %d\n", __func__, res); | ||
1218 | return res; | 1223 | return res; |
1219 | } | 1224 | } |
1220 | 1225 | ||
@@ -1326,8 +1331,6 @@ static void zr364xx_destroy(struct zr364xx_camera *cam) | |||
1326 | /* release transfer buffer */ | 1331 | /* release transfer buffer */ |
1327 | kfree(cam->pipe->transfer_buffer); | 1332 | kfree(cam->pipe->transfer_buffer); |
1328 | cam->pipe->transfer_buffer = NULL; | 1333 | cam->pipe->transfer_buffer = NULL; |
1329 | |||
1330 | DBG("%s\n", __func__); | ||
1331 | mutex_unlock(&cam->open_lock); | 1334 | mutex_unlock(&cam->open_lock); |
1332 | kfree(cam); | 1335 | kfree(cam); |
1333 | cam = NULL; | 1336 | cam = NULL; |
@@ -1408,7 +1411,7 @@ static unsigned int zr364xx_poll(struct file *file, | |||
1408 | { | 1411 | { |
1409 | struct zr364xx_camera *cam = video_drvdata(file); | 1412 | struct zr364xx_camera *cam = video_drvdata(file); |
1410 | struct videobuf_queue *q = &cam->vb_vidq; | 1413 | struct videobuf_queue *q = &cam->vb_vidq; |
1411 | DBG("%s\n", __func__); | 1414 | _DBG("%s\n", __func__); |
1412 | 1415 | ||
1413 | if (cam->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | 1416 | if (cam->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
1414 | return POLLERR; | 1417 | return POLLERR; |