aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorGuennadi Liakhovetski <g.liakhovetski@gmx.de>2008-12-18 09:51:55 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-12-30 06:40:21 -0500
commit64f5905ee74906643e22657bd20e2f11443053f0 (patch)
tree17aaf01284c3297d835f3167098be9333df9b188 /drivers/media
parent9414de39e8e07d90bdb6524be501fae0e013d37b (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')
-rw-r--r--drivers/media/video/mt9m001.c20
-rw-r--r--drivers/media/video/mt9m111.c10
-rw-r--r--drivers/media/video/mt9v022.c20
-rw-r--r--drivers/media/video/pxa_camera.c21
-rw-r--r--drivers/media/video/soc_camera.c74
-rw-r--r--drivers/media/video/soc_camera_platform.c5
6 files changed, 81 insertions, 69 deletions
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
index b58f0f85e30f..e81b3247f79e 100644
--- a/drivers/media/video/mt9m001.c
+++ b/drivers/media/video/mt9m001.c
@@ -327,15 +327,17 @@ static int mt9m001_set_fmt(struct soc_camera_device *icd,
327static int mt9m001_try_fmt(struct soc_camera_device *icd, 327static int mt9m001_try_fmt(struct soc_camera_device *icd,
328 struct v4l2_format *f) 328 struct v4l2_format *f)
329{ 329{
330 if (f->fmt.pix.height < 32 + icd->y_skip_top) 330 struct v4l2_pix_format *pix = &f->fmt.pix;
331 f->fmt.pix.height = 32 + icd->y_skip_top; 331
332 if (f->fmt.pix.height > 1024 + icd->y_skip_top) 332 if (pix->height < 32 + icd->y_skip_top)
333 f->fmt.pix.height = 1024 + icd->y_skip_top; 333 pix->height = 32 + icd->y_skip_top;
334 if (f->fmt.pix.width < 48) 334 if (pix->height > 1024 + icd->y_skip_top)
335 f->fmt.pix.width = 48; 335 pix->height = 1024 + icd->y_skip_top;
336 if (f->fmt.pix.width > 1280) 336 if (pix->width < 48)
337 f->fmt.pix.width = 1280; 337 pix->width = 48;
338 f->fmt.pix.width &= ~0x01; /* has to be even, unsure why was ~3 */ 338 if (pix->width > 1280)
339 pix->width = 1280;
340 pix->width &= ~0x01; /* has to be even, unsure why was ~3 */
339 341
340 return 0; 342 return 0;
341} 343}
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 3dfeea4e94b1..c89ea41fe259 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -503,10 +503,12 @@ static int mt9m111_set_fmt(struct soc_camera_device *icd,
503static int mt9m111_try_fmt(struct soc_camera_device *icd, 503static int mt9m111_try_fmt(struct soc_camera_device *icd,
504 struct v4l2_format *f) 504 struct v4l2_format *f)
505{ 505{
506 if (f->fmt.pix.height > MT9M111_MAX_HEIGHT) 506 struct v4l2_pix_format *pix = &f->fmt.pix;
507 f->fmt.pix.height = MT9M111_MAX_HEIGHT; 507
508 if (f->fmt.pix.width > MT9M111_MAX_WIDTH) 508 if (pix->height > MT9M111_MAX_HEIGHT)
509 f->fmt.pix.width = MT9M111_MAX_WIDTH; 509 pix->height = MT9M111_MAX_HEIGHT;
510 if (pix->width > MT9M111_MAX_WIDTH)
511 pix->width = MT9M111_MAX_WIDTH;
510 512
511 return 0; 513 return 0;
512} 514}
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index 3b3a6a027b1d..be20747b8138 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -406,15 +406,17 @@ static int mt9v022_set_fmt(struct soc_camera_device *icd,
406static int mt9v022_try_fmt(struct soc_camera_device *icd, 406static int mt9v022_try_fmt(struct soc_camera_device *icd,
407 struct v4l2_format *f) 407 struct v4l2_format *f)
408{ 408{
409 if (f->fmt.pix.height < 32 + icd->y_skip_top) 409 struct v4l2_pix_format *pix = &f->fmt.pix;
410 f->fmt.pix.height = 32 + icd->y_skip_top; 410
411 if (f->fmt.pix.height > 480 + icd->y_skip_top) 411 if (pix->height < 32 + icd->y_skip_top)
412 f->fmt.pix.height = 480 + icd->y_skip_top; 412 pix->height = 32 + icd->y_skip_top;
413 if (f->fmt.pix.width < 48) 413 if (pix->height > 480 + icd->y_skip_top)
414 f->fmt.pix.width = 48; 414 pix->height = 480 + icd->y_skip_top;
415 if (f->fmt.pix.width > 752) 415 if (pix->width < 48)
416 f->fmt.pix.width = 752; 416 pix->width = 48;
417 f->fmt.pix.width &= ~0x03; /* ? */ 417 if (pix->width > 752)
418 pix->width = 752;
419 pix->width &= ~0x03; /* ? */
418 420
419 return 0; 421 return 0;
420} 422}
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index 28ea13f7b2b0..f6919a0e2ac2 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -240,8 +240,7 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
240 unsigned int *size) 240 unsigned int *size)
241{ 241{
242 struct soc_camera_device *icd = vq->priv_data; 242 struct soc_camera_device *icd = vq->priv_data;
243 struct soc_camera_host *ici = 243 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
244 to_soc_camera_host(icd->dev.parent);
245 struct pxa_camera_dev *pcdev = ici->priv; 244 struct pxa_camera_dev *pcdev = ici->priv;
246 245
247 dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size); 246 dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size);
@@ -267,8 +266,7 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
267static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf) 266static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
268{ 267{
269 struct soc_camera_device *icd = vq->priv_data; 268 struct soc_camera_device *icd = vq->priv_data;
270 struct soc_camera_host *ici = 269 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
271 to_soc_camera_host(icd->dev.parent);
272 struct pxa_camera_dev *pcdev = ici->priv; 270 struct pxa_camera_dev *pcdev = ici->priv;
273 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); 271 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
274 int i; 272 int i;
@@ -344,8 +342,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
344 struct videobuf_buffer *vb, enum v4l2_field field) 342 struct videobuf_buffer *vb, enum v4l2_field field)
345{ 343{
346 struct soc_camera_device *icd = vq->priv_data; 344 struct soc_camera_device *icd = vq->priv_data;
347 struct soc_camera_host *ici = 345 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
348 to_soc_camera_host(icd->dev.parent);
349 struct pxa_camera_dev *pcdev = ici->priv; 346 struct pxa_camera_dev *pcdev = ici->priv;
350 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); 347 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
351 int ret; 348 int ret;
@@ -464,8 +461,7 @@ static void pxa_videobuf_queue(struct videobuf_queue *vq,
464 struct videobuf_buffer *vb) 461 struct videobuf_buffer *vb)
465{ 462{
466 struct soc_camera_device *icd = vq->priv_data; 463 struct soc_camera_device *icd = vq->priv_data;
467 struct soc_camera_host *ici = 464 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
468 to_soc_camera_host(icd->dev.parent);
469 struct pxa_camera_dev *pcdev = ici->priv; 465 struct pxa_camera_dev *pcdev = ici->priv;
470 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); 466 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
471 struct pxa_buffer *active; 467 struct pxa_buffer *active;
@@ -915,8 +911,7 @@ static int test_platform_param(struct pxa_camera_dev *pcdev,
915 911
916static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) 912static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
917{ 913{
918 struct soc_camera_host *ici = 914 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
919 to_soc_camera_host(icd->dev.parent);
920 struct pxa_camera_dev *pcdev = ici->priv; 915 struct pxa_camera_dev *pcdev = ici->priv;
921 unsigned long dw, bpp, bus_flags, camera_flags, common_flags; 916 unsigned long dw, bpp, bus_flags, camera_flags, common_flags;
922 u32 cicr0, cicr1, cicr2, cicr3, cicr4 = 0; 917 u32 cicr0, cicr1, cicr2, cicr3, cicr4 = 0;
@@ -1298,8 +1293,7 @@ static int pxa_camera_querycap(struct soc_camera_host *ici,
1298 1293
1299static int pxa_camera_suspend(struct soc_camera_device *icd, pm_message_t state) 1294static int pxa_camera_suspend(struct soc_camera_device *icd, pm_message_t state)
1300{ 1295{
1301 struct soc_camera_host *ici = 1296 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
1302 to_soc_camera_host(icd->dev.parent);
1303 struct pxa_camera_dev *pcdev = ici->priv; 1297 struct pxa_camera_dev *pcdev = ici->priv;
1304 int i = 0, ret = 0; 1298 int i = 0, ret = 0;
1305 1299
@@ -1317,8 +1311,7 @@ static int pxa_camera_suspend(struct soc_camera_device *icd, pm_message_t state)
1317 1311
1318static int pxa_camera_resume(struct soc_camera_device *icd) 1312static int pxa_camera_resume(struct soc_camera_device *icd)
1319{ 1313{
1320 struct soc_camera_host *ici = 1314 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
1321 to_soc_camera_host(icd->dev.parent);
1322 struct pxa_camera_dev *pcdev = ici->priv; 1315 struct pxa_camera_dev *pcdev = ici->priv;
1323 int i = 0, ret = 0; 1316 int i = 0, ret = 0;
1324 1317
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)
776static int soc_camera_probe(struct device *dev) 772static 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}
diff --git a/drivers/media/video/soc_camera_platform.c b/drivers/media/video/soc_camera_platform.c
index c23871e4c1e6..013ab06e3180 100644
--- a/drivers/media/video/soc_camera_platform.c
+++ b/drivers/media/video/soc_camera_platform.c
@@ -89,9 +89,10 @@ static int soc_camera_platform_try_fmt(struct soc_camera_device *icd,
89 struct v4l2_format *f) 89 struct v4l2_format *f)
90{ 90{
91 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd); 91 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
92 struct v4l2_pix_format *pix = &f->fmt.pix;
92 93
93 f->fmt.pix.width = p->format.width; 94 pix->width = p->format.width;
94 f->fmt.pix.height = p->format.height; 95 pix->height = p->format.height;
95 return 0; 96 return 0;
96} 97}
97 98