Merge remote-tracking branch 'stable/linux-4.19.y' into rpi-4.19.y
[platform/kernel/linux-rpi.git] / drivers / media / v4l2-core / v4l2-ioctl.c
index 54afc9c..4f422ed 100644 (file)
@@ -286,6 +286,7 @@ static void v4l_print_format(const void *arg, bool write_only)
        const struct v4l2_window *win;
        const struct v4l2_sdr_format *sdr;
        const struct v4l2_meta_format *meta;
+       u32 planes;
        unsigned i;
 
        pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
@@ -316,7 +317,8 @@ static void v4l_print_format(const void *arg, bool write_only)
                        prt_names(mp->field, v4l2_field_names),
                        mp->colorspace, mp->num_planes, mp->flags,
                        mp->ycbcr_enc, mp->quantization, mp->xfer_func);
-               for (i = 0; i < mp->num_planes; i++)
+               planes = min_t(u32, mp->num_planes, VIDEO_MAX_PLANES);
+               for (i = 0; i < planes; i++)
                        printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i,
                                        mp->plane_fmt[i].bytesperline,
                                        mp->plane_fmt[i].sizeimage);
@@ -1413,10 +1415,26 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
        return ret;
 }
 
+static void v4l_pix_format_touch(struct v4l2_pix_format *p)
+{
+       /*
+        * The v4l2_pix_format structure contains fields that make no sense for
+        * touch. Set them to default values in this case.
+        */
+
+       p->field = V4L2_FIELD_NONE;
+       p->colorspace = V4L2_COLORSPACE_RAW;
+       p->flags = 0;
+       p->ycbcr_enc = 0;
+       p->quantization = 0;
+       p->xfer_func = 0;
+}
+
 static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
                                struct file *file, void *fh, void *arg)
 {
        struct v4l2_format *p = arg;
+       struct video_device *vfd = video_devdata(file);
        int ret = check_fmt(file, p->type);
 
        if (ret)
@@ -1454,6 +1472,8 @@ static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
                ret = ops->vidioc_g_fmt_vid_cap(file, fh, arg);
                /* just in case the driver zeroed it again */
                p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
+               if (vfd->vfl_type == VFL_TYPE_TOUCH)
+                       v4l_pix_format_touch(&p->fmt.pix);
                return ret;
        case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
                return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg);
@@ -1489,21 +1509,6 @@ static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
        return -EINVAL;
 }
 
-static void v4l_pix_format_touch(struct v4l2_pix_format *p)
-{
-       /*
-        * The v4l2_pix_format structure contains fields that make no sense for
-        * touch. Set them to default values in this case.
-        */
-
-       p->field = V4L2_FIELD_NONE;
-       p->colorspace = V4L2_COLORSPACE_RAW;
-       p->flags = 0;
-       p->ycbcr_enc = 0;
-       p->quantization = 0;
-       p->xfer_func = 0;
-}
-
 static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
                                struct file *file, void *fh, void *arg)
 {
@@ -1877,7 +1882,7 @@ static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops,
        if (ret)
                return ret;
 
-       CLEAR_AFTER_FIELD(p, memory);
+       CLEAR_AFTER_FIELD(p, capabilities);
 
        return ops->vidioc_reqbufs(file, fh, p);
 }
@@ -1918,7 +1923,7 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
        if (ret)
                return ret;
 
-       CLEAR_AFTER_FIELD(create, format);
+       CLEAR_AFTER_FIELD(create, capabilities);
 
        v4l_sanitize_format(&create->format);