From patchwork Thu Apr 18 10:47:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1035 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 424F960DC0 for ; Thu, 18 Apr 2019 12:46:32 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id C48381C0004; Thu, 18 Apr 2019 10:46:31 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 18 Apr 2019 12:47:04 +0200 Message-Id: <20190418104715.22622-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418104715.22622-1-jacopo@jmondi.org> References: <20190418104715.22622-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 03/14] libcamera: camera: Don't call freeBuffer() on allocateBuffer() error X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Apr 2019 10:46:32 -0000 Do not assume the freeBuffer() function can handle allocateBuffer() method failures, as error handling and clean up should be performed by allocateBuffer() method itself. Perform clean-up on allocations failures in the IPU3 pipeline handler, now that freeBuffers() is not called anymore. Signed-off-by: Jacopo Mondi --- src/libcamera/camera.cpp | 1 - src/libcamera/pipeline/ipu3/ipu3.cpp | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 21caa24b90b5..2d0a80664214 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -650,7 +650,6 @@ int Camera::allocateBuffers() int ret = pipe_->allocateBuffers(this, activeStreams_); if (ret) { LOG(Camera, Error) << "Failed to allocate buffers"; - freeBuffers(); return ret; } diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index f96e8763bce9..6e093fc22259 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -314,6 +314,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, Stream *stream = *streams.begin(); CIO2Device *cio2 = &data->cio2_; ImgUDevice *imgu = data->imgu_; + unsigned int bufferCount; int ret; /* Share buffers between CIO2 output and ImgU input. */ @@ -323,31 +324,39 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, ret = imgu->importBuffers(pool); if (ret) - return ret; + goto error_free_cio2; /* Export ImgU output buffers to the stream's pool. */ ret = imgu->exportBuffers(&imgu->output_, &stream->bufferPool()); if (ret) - return ret; + goto error_free_imgu; /* * Reserve memory in viewfinder and stat output devices. Use the * same number of buffers as the ones requested for the output * stream. */ - unsigned int bufferCount = stream->bufferPool().count(); + bufferCount = stream->bufferPool().count(); imgu->viewfinder_.pool->createBuffers(bufferCount); ret = imgu->exportBuffers(&imgu->viewfinder_, imgu->viewfinder_.pool); if (ret) - return ret; + goto error_free_imgu; imgu->stat_.pool->createBuffers(bufferCount); ret = imgu->exportBuffers(&imgu->stat_, imgu->stat_.pool); if (ret) - return ret; + goto error_free_imgu; return 0; + +error_free_imgu: + imgu->freeBuffers(); + +error_free_cio2: + cio2->freeBuffers(); + + return ret; } int PipelineHandlerIPU3::freeBuffers(Camera *camera,