diff options
author | Guennadi Liakhovetski <g.liakhovetski@gmx.de> | 2008-12-18 09:51:55 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-12-30 06:40:21 -0500 |
commit | 64f5905ee74906643e22657bd20e2f11443053f0 (patch) | |
tree | 17aaf01284c3297d835f3167098be9333df9b188 /drivers/media/video/soc_camera.c | |
parent | 9414de39e8e07d90bdb6524be501fae0e013d37b (diff) |
V4L/DVB (10080): soc-camera: readability improvements, more strict operations checks
Simplify multiple drivers by replacing f->fmt.pix.* with a single pointer
dereference, merge some needlessly broken lines, verify host and camera
operations pointers on registration.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/soc_camera.c')
-rw-r--r-- | drivers/media/video/soc_camera.c | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c index 176017501055..d5613cdd93a6 100644 --- a/drivers/media/video/soc_camera.c +++ b/drivers/media/video/soc_camera.c | |||
@@ -98,8 +98,7 @@ static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv, | |||
98 | { | 98 | { |
99 | struct soc_camera_file *icf = file->private_data; | 99 | struct soc_camera_file *icf = file->private_data; |
100 | struct soc_camera_device *icd = icf->icd; | 100 | struct soc_camera_device *icd = icf->icd; |
101 | struct soc_camera_host *ici = | 101 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
102 | to_soc_camera_host(icd->dev.parent); | ||
103 | enum v4l2_field field; | 102 | enum v4l2_field field; |
104 | int ret; | 103 | int ret; |
105 | 104 | ||
@@ -163,8 +162,7 @@ static int soc_camera_reqbufs(struct file *file, void *priv, | |||
163 | int ret; | 162 | int ret; |
164 | struct soc_camera_file *icf = file->private_data; | 163 | struct soc_camera_file *icf = file->private_data; |
165 | struct soc_camera_device *icd = icf->icd; | 164 | struct soc_camera_device *icd = icf->icd; |
166 | struct soc_camera_host *ici = | 165 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
167 | to_soc_camera_host(icd->dev.parent); | ||
168 | 166 | ||
169 | WARN_ON(priv != file->private_data); | 167 | WARN_ON(priv != file->private_data); |
170 | 168 | ||
@@ -388,8 +386,7 @@ static unsigned int soc_camera_poll(struct file *file, poll_table *pt) | |||
388 | { | 386 | { |
389 | struct soc_camera_file *icf = file->private_data; | 387 | struct soc_camera_file *icf = file->private_data; |
390 | struct soc_camera_device *icd = icf->icd; | 388 | struct soc_camera_device *icd = icf->icd; |
391 | struct soc_camera_host *ici = | 389 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
392 | to_soc_camera_host(icd->dev.parent); | ||
393 | 390 | ||
394 | if (list_empty(&icf->vb_vidq.stream)) { | 391 | if (list_empty(&icf->vb_vidq.stream)) { |
395 | dev_err(&icd->dev, "Trying to poll with no queued buffers!\n"); | 392 | dev_err(&icd->dev, "Trying to poll with no queued buffers!\n"); |
@@ -415,9 +412,9 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv, | |||
415 | { | 412 | { |
416 | struct soc_camera_file *icf = file->private_data; | 413 | struct soc_camera_file *icf = file->private_data; |
417 | struct soc_camera_device *icd = icf->icd; | 414 | struct soc_camera_device *icd = icf->icd; |
418 | struct soc_camera_host *ici = | 415 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
419 | to_soc_camera_host(icd->dev.parent); | 416 | struct v4l2_pix_format *pix = &f->fmt.pix; |
420 | __u32 pixfmt = f->fmt.pix.pixelformat; | 417 | __u32 pixfmt = pix->pixelformat; |
421 | int ret; | 418 | int ret; |
422 | struct v4l2_rect rect; | 419 | struct v4l2_rect rect; |
423 | 420 | ||
@@ -429,9 +426,9 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv, | |||
429 | 426 | ||
430 | rect.left = icd->x_current; | 427 | rect.left = icd->x_current; |
431 | rect.top = icd->y_current; | 428 | rect.top = icd->y_current; |
432 | rect.width = f->fmt.pix.width; | 429 | rect.width = pix->width; |
433 | rect.height = f->fmt.pix.height; | 430 | rect.height = pix->height; |
434 | ret = ici->ops->set_fmt(icd, f->fmt.pix.pixelformat, &rect); | 431 | ret = ici->ops->set_fmt(icd, pix->pixelformat, &rect); |
435 | if (ret < 0) { | 432 | if (ret < 0) { |
436 | return ret; | 433 | return ret; |
437 | } else if (!icd->current_fmt || | 434 | } else if (!icd->current_fmt || |
@@ -443,7 +440,7 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv, | |||
443 | 440 | ||
444 | icd->width = rect.width; | 441 | icd->width = rect.width; |
445 | icd->height = rect.height; | 442 | icd->height = rect.height; |
446 | icf->vb_vidq.field = f->fmt.pix.field; | 443 | icf->vb_vidq.field = pix->field; |
447 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | 444 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
448 | dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n", | 445 | dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n", |
449 | f->type); | 446 | f->type); |
@@ -479,16 +476,17 @@ static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv, | |||
479 | { | 476 | { |
480 | struct soc_camera_file *icf = file->private_data; | 477 | struct soc_camera_file *icf = file->private_data; |
481 | struct soc_camera_device *icd = icf->icd; | 478 | struct soc_camera_device *icd = icf->icd; |
479 | struct v4l2_pix_format *pix = &f->fmt.pix; | ||
482 | 480 | ||
483 | WARN_ON(priv != file->private_data); | 481 | WARN_ON(priv != file->private_data); |
484 | 482 | ||
485 | f->fmt.pix.width = icd->width; | 483 | pix->width = icd->width; |
486 | f->fmt.pix.height = icd->height; | 484 | pix->height = icd->height; |
487 | f->fmt.pix.field = icf->vb_vidq.field; | 485 | pix->field = icf->vb_vidq.field; |
488 | f->fmt.pix.pixelformat = icd->current_fmt->fourcc; | 486 | pix->pixelformat = icd->current_fmt->fourcc; |
489 | f->fmt.pix.bytesperline = f->fmt.pix.width * | 487 | pix->bytesperline = pix->width * |
490 | DIV_ROUND_UP(icd->current_fmt->depth, 8); | 488 | DIV_ROUND_UP(icd->current_fmt->depth, 8); |
491 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; | 489 | pix->sizeimage = pix->height * pix->bytesperline; |
492 | dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n", | 490 | dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n", |
493 | icd->current_fmt->fourcc); | 491 | icd->current_fmt->fourcc); |
494 | return 0; | 492 | return 0; |
@@ -499,8 +497,7 @@ static int soc_camera_querycap(struct file *file, void *priv, | |||
499 | { | 497 | { |
500 | struct soc_camera_file *icf = file->private_data; | 498 | struct soc_camera_file *icf = file->private_data; |
501 | struct soc_camera_device *icd = icf->icd; | 499 | struct soc_camera_device *icd = icf->icd; |
502 | struct soc_camera_host *ici = | 500 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
503 | to_soc_camera_host(icd->dev.parent); | ||
504 | 501 | ||
505 | WARN_ON(priv != file->private_data); | 502 | WARN_ON(priv != file->private_data); |
506 | 503 | ||
@@ -651,8 +648,7 @@ static int soc_camera_s_crop(struct file *file, void *fh, | |||
651 | { | 648 | { |
652 | struct soc_camera_file *icf = file->private_data; | 649 | struct soc_camera_file *icf = file->private_data; |
653 | struct soc_camera_device *icd = icf->icd; | 650 | struct soc_camera_device *icd = icf->icd; |
654 | struct soc_camera_host *ici = | 651 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
655 | to_soc_camera_host(icd->dev.parent); | ||
656 | int ret; | 652 | int ret; |
657 | 653 | ||
658 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | 654 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
@@ -776,13 +772,9 @@ static int scan_add_device(struct soc_camera_device *icd) | |||
776 | static int soc_camera_probe(struct device *dev) | 772 | static int soc_camera_probe(struct device *dev) |
777 | { | 773 | { |
778 | struct soc_camera_device *icd = to_soc_camera_dev(dev); | 774 | struct soc_camera_device *icd = to_soc_camera_dev(dev); |
779 | struct soc_camera_host *ici = | 775 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
780 | to_soc_camera_host(icd->dev.parent); | ||
781 | int ret; | 776 | int ret; |
782 | 777 | ||
783 | if (!icd->ops->probe) | ||
784 | return -ENODEV; | ||
785 | |||
786 | /* We only call ->add() here to activate and probe the camera. | 778 | /* We only call ->add() here to activate and probe the camera. |
787 | * We shall ->remove() and deactivate it immediately afterwards. */ | 779 | * We shall ->remove() and deactivate it immediately afterwards. */ |
788 | ret = ici->ops->add(icd); | 780 | ret = ici->ops->add(icd); |
@@ -863,7 +855,16 @@ int soc_camera_host_register(struct soc_camera_host *ici) | |||
863 | int ret; | 855 | int ret; |
864 | struct soc_camera_host *ix; | 856 | struct soc_camera_host *ix; |
865 | 857 | ||
866 | if (!ici->ops->init_videobuf || !ici->ops->add || !ici->ops->remove) | 858 | if (!ici || !ici->ops || |
859 | !ici->ops->try_fmt || | ||
860 | !ici->ops->set_fmt || | ||
861 | !ici->ops->set_bus_param || | ||
862 | !ici->ops->querycap || | ||
863 | !ici->ops->init_videobuf || | ||
864 | !ici->ops->reqbufs || | ||
865 | !ici->ops->add || | ||
866 | !ici->ops->remove || | ||
867 | !ici->ops->poll) | ||
867 | return -EINVAL; | 868 | return -EINVAL; |
868 | 869 | ||
869 | /* Number might be equal to the platform device ID */ | 870 | /* Number might be equal to the platform device ID */ |
@@ -931,7 +932,16 @@ int soc_camera_device_register(struct soc_camera_device *icd) | |||
931 | struct soc_camera_device *ix; | 932 | struct soc_camera_device *ix; |
932 | int num = -1, i; | 933 | int num = -1, i; |
933 | 934 | ||
934 | if (!icd) | 935 | if (!icd || !icd->ops || |
936 | !icd->ops->probe || | ||
937 | !icd->ops->init || | ||
938 | !icd->ops->release || | ||
939 | !icd->ops->start_capture || | ||
940 | !icd->ops->stop_capture || | ||
941 | !icd->ops->set_fmt || | ||
942 | !icd->ops->try_fmt || | ||
943 | !icd->ops->query_bus_param || | ||
944 | !icd->ops->set_bus_param) | ||
935 | return -EINVAL; | 945 | return -EINVAL; |
936 | 946 | ||
937 | for (i = 0; i < 256 && num < 0; i++) { | 947 | for (i = 0; i < 256 && num < 0; i++) { |
@@ -953,7 +963,9 @@ int soc_camera_device_register(struct soc_camera_device *icd) | |||
953 | icd->dev.bus = &soc_camera_bus_type; | 963 | icd->dev.bus = &soc_camera_bus_type; |
954 | dev_set_name(&icd->dev, "%u-%u", icd->iface, icd->devnum); | 964 | dev_set_name(&icd->dev, "%u-%u", icd->iface, icd->devnum); |
955 | 965 | ||
956 | icd->dev.release = dummy_release; | 966 | icd->dev.release = dummy_release; |
967 | icd->use_count = 0; | ||
968 | icd->host_priv = NULL; | ||
957 | 969 | ||
958 | return scan_add_device(icd); | 970 | return scan_add_device(icd); |
959 | } | 971 | } |