[{"id":5042,"web_url":"https://patchwork.libcamera.org/comment/5042/","msgid":"<20200605101621.GG5852@pendragon.ideasonboard.com>","date":"2020-06-05T10:16:21","subject":"Re: [libcamera-devel] [PATCH v2 5/7] v4l2: v4l2_camera_proxy: Don't\n\treturn -EINVAL for zero sizeimage in REQBUFS","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Fri, Jun 05, 2020 at 06:01:04PM +0900, Paul Elder wrote:\n> If VIDIOC_REQBUFS returns -EINVAL, it signals to the application that\n> the requested buffer or memory type is not supported. If we return\n> -EINVAL due to a zero sizeimage, then the application will think that we\n> don't support a memory type that we actually do. We cannot error on a\n> zero sizeimage, because reqbufs could be called merely to probe what IO\n> methods we support; qv4l2, for example, called reqbufs once with userptr\n> and once more with mmap, both times with count=1.\n> \n> On the other hand, sizeimage will be zero for formats whose size we\n> don't know how to calculate, such as MJPEG. If we try to stream such\n> formats anyway, we will get a floating point exception and crash. Issue\n> a warning for now, and don't return -EINVAL, so that we can continue\n> operation.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> Changes in v2: expand changelog\n> ---\n>  src/v4l2/v4l2_camera_proxy.cpp | 12 +++++++++++-\n>  1 file changed, 11 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index a0c6deea..cbe9e026 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -352,8 +352,18 @@ int V4L2CameraProxy::vidioc_reqbufs(struct v4l2_requestbuffers *arg)\n>  \t\treturn -EINVAL;\n>  \n>  \tsizeimage_ = calculateSizeImage(streamConfig_);\n> +\t/*\n> +\t * If we return -EINVAL here then the application will think that we\n> +\t * don't support streaming mmap. Since we don't support readwrite and\n> +\t * userptr either, the application will get confused and think that\n> +\t * we don't support anything.\n> +\t * On the other hand, if a format has a zero sizeimage (eg. MJPEG),\n> +\t * we'll get a floating point exception when we try to stream it.\n> +\t */\n>  \tif (sizeimage_ == 0)\n> -\t\treturn -EINVAL;\n> +\t\tLOG(V4L2Compat, Warning)\n> +\t\t\t<< \"sizeimage of at least one format is zero. \"\n> +\t\t\t<< \"Streaming this format will cause a floating point exception.\";\n>  \n>  \tsetFmtFromConfig(streamConfig_);\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B1B9D603C9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 12:16:39 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 35C2F27C;\n\tFri,  5 Jun 2020 12:16:39 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Kyqai/lC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1591352199;\n\tbh=3QM/JrROWF9N44D7tT3ayC6lyZZCnI2qP2cnZci6O1w=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Kyqai/lCfyEWMssirkDuDu+IauG+7ca/M6FfOd5p/izfNm48jkf+M0pMjR8038OwW\n\tg+a+cLRnh0wyn1VweT5e+Cv0CN7jnhQEheMltlC3VjM3JBrtWNefZAjmj4L/oV4wGo\n\tL8skkJD+JuuyXJNL9Ug6HlcImFuOxYNz+nkmWDM0=","Date":"Fri, 5 Jun 2020 13:16:21 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200605101621.GG5852@pendragon.ideasonboard.com>","References":"<20200605090106.15424-1-paul.elder@ideasonboard.com>\n\t<20200605090106.15424-6-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200605090106.15424-6-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 5/7] v4l2: v4l2_camera_proxy: Don't\n\treturn -EINVAL for zero sizeimage in REQBUFS","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 05 Jun 2020 10:16:39 -0000"}}]