From patchwork Mon Oct 28 02:22:20 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: 2256 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AA6256139C for ; Mon, 28 Oct 2019 03:22:48 +0100 (CET) X-Halon-ID: d34a2ef7-f929-11e9-903a-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from localhost.localdomain (unknown [93.2.121.143]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id d34a2ef7-f929-11e9-903a-005056917f90; Mon, 28 Oct 2019 03:22:44 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 03:22:20 +0100 Message-Id: <20191028022224.795355-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028022224.795355-1-niklas.soderlund@ragnatech.se> References: <20191028022224.795355-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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: Mon, 28 Oct 2019 02:22:49 -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: 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 208ab54199b141c3..a2a9eab2bcc0d7e8 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -819,9 +819,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; } /** @@ -832,24 +839,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] = {}; @@ -936,23 +934,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;