MLK-20888: m2m: add checking for userspace input parameters
authorGuoniu.Zhou <guoniu.zhou@nxp.com>
Mon, 11 Feb 2019 10:05:54 +0000 (18:05 +0800)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
Checking parameters from userspace befor applying for different format

Signed-off-by: Guoniu.Zhou <guoniu.zhou@nxp.com>
(cherry picked from commit 47ff54238f138be015756a45afb0af58b52e5a02)
(cherry picked from commit 5a52bef34e084943ac5ca8c4c27ca4e0c97a4263)

drivers/media/platform/imx8/mxc-isi-m2m.c

index 43ba7f2..76a8a79 100644 (file)
@@ -685,13 +685,29 @@ static int mxc_isi_m2m_s_fmt_vid_cap(struct file *file, void *priv,
        }
 
        if (i >= ARRAY_SIZE(mxc_isi_out_formats)) {
-               dev_dbg(&mxc_isi->pdev->dev, "%s, format is not support!\n", __func__);
+               dev_err(&mxc_isi->pdev->dev, "%s, format is not support!\n", __func__);
                return -EINVAL;
        }
 
        /* update out put frame size and formate */
-       if (pix->height <= 0 || pix->width <= 0)
+       if (pix->height <= 0 || pix->width <= 0) {
+               dev_err(&mxc_isi->pdev->dev,
+                       "Invalid width or height(w=%d, h=%d)\n",
+                       pix->width, pix->height);
+               return -EINVAL;
+       }
+
+       if ((pix->pixelformat == V4L2_PIX_FMT_NV12) && ((pix->width / 4) % 2)) {
+               dev_err(&mxc_isi->pdev->dev,
+                       "Invalid width or height(w=%d, h=%d) for NV12\n",
+                       pix->width, pix->height);
                return -EINVAL;
+       } else if ((pix->pixelformat != V4L2_PIX_FMT_XBGR32) && (pix->width % 2)) {
+               dev_err(&mxc_isi->pdev->dev,
+                       "Invalid width or height(w=%d, h=%d) for %.4s\n",
+                       pix->width, pix->height, (char *)&pix->pixelformat);
+               return -EINVAL;
+       }
 
        frame->fmt = fmt;
        frame->height = pix->height;