[{"id":3051,"web_url":"https://patchwork.libcamera.org/comment/3051/","msgid":"<20191118112733.GH4724@pendragon.ideasonboard.com>","date":"2019-11-18T11:27:33","subject":"Re: [libcamera-devel] [PATCH 06/10] libcamera: v4l2_videodevice:\n\tSimplify error checking for requestBuffers()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Mon, Oct 28, 2019 at 03:22:20AM +0100, Niklas Söderlund wrote:\n> There is no point in explicitly checking the same error in the only call\n> sites for the internal function, centralize the check and simplify the\n> code.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 31 ++++++++++--------------------\n>  1 file changed, 10 insertions(+), 21 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 208ab54199b141c3..a2a9eab2bcc0d7e8 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -819,9 +819,16 @@ int V4L2VideoDevice::requestBuffers(unsigned int count)\n>  \t\treturn ret;\n>  \t}\n>  \n> +\tif (rb.count < count) {\n> +\t\tLOG(V4L2, Error)\n> +\t\t\t<< \"Not enough buffers provided by V4L2VideoDevice\";\n> +\t\trequestBuffers(0);\n> +\t\treturn -ENOMEM;\n> +\t}\n> +\n>  \tLOG(V4L2, Debug) << rb.count << \" buffers requested.\";\n>  \n> -\treturn rb.count;\n> +\treturn 0;\n>  }\n>  \n>  /**\n> @@ -832,24 +839,15 @@ int V4L2VideoDevice::requestBuffers(unsigned int count)\n>   */\n>  int V4L2VideoDevice::exportBuffers(BufferPool *pool)\n>  {\n> -\tunsigned int allocatedBuffers;\n>  \tunsigned int i;\n>  \tint ret;\n>  \n>  \tmemoryType_ = V4L2_MEMORY_MMAP;\n>  \n>  \tret = requestBuffers(pool->count());\n> -\tif (ret < 0)\n> +\tif (ret)\n>  \t\treturn ret;\n>  \n> -\tallocatedBuffers = ret;\n> -\tif (allocatedBuffers < pool->count()) {\n> -\t\tLOG(V4L2, Error)\n> -\t\t\t<< \"Not enough buffers provided by V4L2VideoDevice\";\n> -\t\trequestBuffers(0);\n> -\t\treturn -ENOMEM;\n> -\t}\n> -\n>  \t/* Map the buffers. */\n>  \tfor (i = 0; i < pool->count(); ++i) {\n>  \t\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n> @@ -936,23 +934,14 @@ int V4L2VideoDevice::createPlane(BufferMemory *buffer, unsigned int index,\n>   */\n>  int V4L2VideoDevice::importBuffers(BufferPool *pool)\n>  {\n> -\tunsigned int allocatedBuffers;\n>  \tint ret;\n>  \n>  \tmemoryType_ = V4L2_MEMORY_DMABUF;\n>  \n>  \tret = requestBuffers(pool->count());\n> -\tif (ret < 0)\n> +\tif (ret)\n>  \t\treturn ret;\n>  \n> -\tallocatedBuffers = ret;\n> -\tif (allocatedBuffers < pool->count()) {\n> -\t\tLOG(V4L2, Error)\n> -\t\t\t<< \"Not enough buffers provided by V4L2VideoDevice\";\n> -\t\trequestBuffers(0);\n> -\t\treturn -ENOMEM;\n> -\t}\n> -\n>  \tLOG(V4L2, Debug) << \"provided pool of \" << pool->count() << \" buffers\";\n>  \tbufferPool_ = pool;\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 871E860F1C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2019 12:27:38 +0100 (CET)","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 E8A79563;\n\tMon, 18 Nov 2019 12:27:37 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1574076458;\n\tbh=TL3yYGkcTk4PQOa8MyPFwqw4lfcg7MBey+C1o00mlk8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Q62JD8HUxCEbd5pVO/OGACe4bUf8YSsWsr0EkAcUTPblf5yXPVn/P326/L6aRtp4P\n\tZ+buUJ8u64kWEJimk8Yyq7SvCbe1trXw1d7zEHdLL3HcjLeYal7BpNr048ELcRAAzo\n\tH20rNHengdvP0/GQ/UEqACgtJO9uk8z1bPbTTkJY=","Date":"Mon, 18 Nov 2019 13:27:33 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191118112733.GH4724@pendragon.ideasonboard.com>","References":"<20191028022224.795355-1-niklas.soderlund@ragnatech.se>\n\t<20191028022224.795355-7-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20191028022224.795355-7-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 06/10] libcamera: v4l2_videodevice:\n\tSimplify error checking for requestBuffers()","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":"Mon, 18 Nov 2019 11:27:38 -0000"}}]