From patchwork Wed Nov 20 01:55:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 2337 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D7623613A0 for ; Wed, 20 Nov 2019 02:55:32 +0100 (CET) X-Halon-ID: d56d4a16-0b38-11ea-a00b-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p54ac5865.dip0.t-ipconnect.de [84.172.88.101]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id d56d4a16-0b38-11ea-a00b-005056917a89; Wed, 20 Nov 2019 02:55:31 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= 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 Subject: [libcamera-devel] [PATCH v2 06/10] libcamera: v4l2_videodevice: Simplify error checking for requestBuffers() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Nov 2019 01:55:33 -0000 There is no point in explicitly checking the same error in the only call sites for the internal function, centralize the check and simplify the code. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_videodevice.cpp | 31 ++++++++++-------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 3f2dc2799796f516..992130751286994c 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -821,9 +821,16 @@ int V4L2VideoDevice::requestBuffers(unsigned int count) return ret; } + if (rb.count < count) { + LOG(V4L2, Error) + << "Not enough buffers provided by V4L2VideoDevice"; + requestBuffers(0); + return -ENOMEM; + } + LOG(V4L2, Debug) << rb.count << " buffers requested."; - return rb.count; + return 0; } /** @@ -834,24 +841,15 @@ int V4L2VideoDevice::requestBuffers(unsigned int count) */ int V4L2VideoDevice::exportBuffers(BufferPool *pool) { - unsigned int allocatedBuffers; unsigned int i; int ret; memoryType_ = V4L2_MEMORY_MMAP; ret = requestBuffers(pool->count()); - if (ret < 0) + if (ret) return ret; - allocatedBuffers = ret; - if (allocatedBuffers < pool->count()) { - LOG(V4L2, Error) - << "Not enough buffers provided by V4L2VideoDevice"; - requestBuffers(0); - return -ENOMEM; - } - /* Map the buffers. */ for (i = 0; i < pool->count(); ++i) { struct v4l2_plane planes[VIDEO_MAX_PLANES] = {}; @@ -938,23 +936,14 @@ int V4L2VideoDevice::createPlane(BufferMemory *buffer, unsigned int index, */ int V4L2VideoDevice::importBuffers(BufferPool *pool) { - unsigned int allocatedBuffers; int ret; memoryType_ = V4L2_MEMORY_DMABUF; ret = requestBuffers(pool->count()); - if (ret < 0) + if (ret) return ret; - allocatedBuffers = ret; - if (allocatedBuffers < pool->count()) { - LOG(V4L2, Error) - << "Not enough buffers provided by V4L2VideoDevice"; - requestBuffers(0); - return -ENOMEM; - } - LOG(V4L2, Debug) << "provided pool of " << pool->count() << " buffers"; bufferPool_ = pool;