{"id":2337,"url":"https://patchwork.libcamera.org/api/1.1/patches/2337/?format=json","web_url":"https://patchwork.libcamera.org/patch/2337/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20191120015506.362440-7-niklas.soderlund@ragnatech.se>","date":"2019-11-20T01:55:02","name":"[libcamera-devel,v2,06/10] libcamera: v4l2_videodevice: Simplify error checking for requestBuffers()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"0e1417de49c996b406d5599338c6b7b076132661","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2337/mbox/","series":[{"id":572,"url":"https://patchwork.libcamera.org/api/1.1/series/572/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=572","date":"2019-11-20T01:54:56","name":"libcamera: Fixes found while working on new","version":2,"mbox":"https://patchwork.libcamera.org/series/572/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2337/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2337/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D7623613A0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Nov 2019 02:55:32 +0100 (CET)","from bismarck.berto.se (p54ac5865.dip0.t-ipconnect.de\n\t[84.172.88.101]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid d56d4a16-0b38-11ea-a00b-005056917a89;\n\tWed, 20 Nov 2019 02:55:31 +0100 (CET)"],"X-Halon-ID":"d56d4a16-0b38-11ea-a00b-005056917a89","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 20 Nov 2019 02:55:02 +0100","Message-Id":"<20191120015506.362440-7-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.24.0","In-Reply-To":"<20191120015506.362440-1-niklas.soderlund@ragnatech.se>","References":"<20191120015506.362440-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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":"Wed, 20 Nov 2019 01:55:33 -0000"},"content":"There is no point in explicitly checking the same error in the only call\nsites for the internal function, centralize the check and simplify the\ncode.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/v4l2_videodevice.cpp | 31 ++++++++++--------------------\n 1 file changed, 10 insertions(+), 21 deletions(-)","diff":"diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 3f2dc2799796f516..992130751286994c 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -821,9 +821,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@@ -834,24 +841,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@@ -938,23 +936,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 \n","prefixes":["libcamera-devel","v2","06/10"]}