media: common: saa7146: fix compliance problems with field handling
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Thu, 2 Mar 2023 11:27:04 +0000 (11:27 +0000)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Sat, 15 Apr 2023 07:53:53 +0000 (08:53 +0100)
The initial field value of the format is ANY, which isn't allowed.
Change to INTERLACED.

VIDIOC_TRY_FMT will overwrite vv->last_field, which is an
unwanted side-effect, so drop this.

And finally vidioc_s_fmt_vid_cap didn't initialize vv->last_field
correctly.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/common/saa7146/saa7146_fops.c
drivers/media/common/saa7146/saa7146_video.c

index 1adfffc987b6f4c61687b94780846a3d6de92f85..79214459387aba65b8d76524d17db92362d0895d 100644 (file)
@@ -298,7 +298,7 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
        fmt->width = 384;
        fmt->height = 288;
        fmt->pixelformat = V4L2_PIX_FMT_BGR24;
-       fmt->field = V4L2_FIELD_ANY;
+       fmt->field = V4L2_FIELD_INTERLACED;
        fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
        fmt->bytesperline = 3 * fmt->width;
        fmt->sizeimage = fmt->bytesperline * fmt->height;
index 5d580b5e61febb969947154703b8e91a56430be8..8306860e9e8aabac39683e0d7a5c85968a9ef314 100644 (file)
@@ -381,20 +381,13 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma
        }
        switch (field) {
        case V4L2_FIELD_ALTERNATE:
-               vv->last_field = V4L2_FIELD_TOP;
-               maxh = maxh / 2;
-               break;
        case V4L2_FIELD_TOP:
        case V4L2_FIELD_BOTTOM:
-               vv->last_field = V4L2_FIELD_INTERLACED;
                maxh = maxh / 2;
                break;
-       case V4L2_FIELD_INTERLACED:
-               vv->last_field = V4L2_FIELD_INTERLACED;
-               break;
        default:
-               DEB_D("no known field mode '%d'\n", field);
-               return -EINVAL;
+               field = V4L2_FIELD_INTERLACED;
+               break;
        }
 
        f->fmt.pix.field = field;
@@ -434,6 +427,14 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format
        err = vidioc_try_fmt_vid_cap(file, fh, f);
        if (0 != err)
                return err;
+       switch (f->fmt.pix.field) {
+       case V4L2_FIELD_ALTERNATE:
+               vv->last_field = V4L2_FIELD_TOP;
+               break;
+       default:
+               vv->last_field = V4L2_FIELD_INTERLACED;
+               break;
+       }
        vv->video_fmt = f->fmt.pix;
        DEB_EE("set to pixelformat '%4.4s'\n",
               (char *)&vv->video_fmt.pixelformat);