{"id":1035,"url":"https://patchwork.libcamera.org/api/patches/1035/?format=json","web_url":"https://patchwork.libcamera.org/patch/1035/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190418104715.22622-4-jacopo@jmondi.org>","date":"2019-04-18T10:47:04","name":"[libcamera-devel,v5,03/14] libcamera: camera: Don't call freeBuffer() on allocateBuffer() error","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"76b6b64ff9e9a827a5f52e0b68313a8552315b04","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1035/mbox/","series":[{"id":255,"url":"https://patchwork.libcamera.org/api/series/255/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=255","date":"2019-04-18T10:47:01","name":"libcamera: ipu3: Multiple streams support","version":5,"mbox":"https://patchwork.libcamera.org/series/255/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1035/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1035/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net\n\t[217.70.183.197])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 424F960DC0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Apr 2019 12:46:32 +0200 (CEST)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay5-d.mail.gandi.net (Postfix) with ESMTPSA id C48381C0004;\n\tThu, 18 Apr 2019 10:46:31 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 03/14] libcamera: camera: Don't call\n\tfreeBuffer() on allocateBuffer() error","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Thu, 18 Apr 2019 10:46:32 -0000"},"content":"Do not assume the freeBuffer() function can handle allocateBuffer()\nmethod failures, as error handling and clean up should be performed\nby allocateBuffer() method itself.\n\nPerform clean-up on allocations failures in the IPU3 pipeline handler,\nnow that freeBuffers() is not called anymore.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/camera.cpp             |  1 -\n src/libcamera/pipeline/ipu3/ipu3.cpp | 19 ++++++++++++++-----\n 2 files changed, 14 insertions(+), 6 deletions(-)","diff":"diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 21caa24b90b5..2d0a80664214 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -650,7 +650,6 @@ int Camera::allocateBuffers()\n \tint ret = pipe_->allocateBuffers(this, activeStreams_);\n \tif (ret) {\n \t\tLOG(Camera, Error) << \"Failed to allocate buffers\";\n-\t\tfreeBuffers();\n \t\treturn ret;\n \t}\n \ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex f96e8763bce9..6e093fc22259 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -314,6 +314,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n \tStream *stream = *streams.begin();\n \tCIO2Device *cio2 = &data->cio2_;\n \tImgUDevice *imgu = data->imgu_;\n+\tunsigned int bufferCount;\n \tint ret;\n \n \t/* Share buffers between CIO2 output and ImgU input. */\n@@ -323,31 +324,39 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n \n \tret = imgu->importBuffers(pool);\n \tif (ret)\n-\t\treturn ret;\n+\t\tgoto error_free_cio2;\n \n \t/* Export ImgU output buffers to the stream's pool. */\n \tret = imgu->exportBuffers(&imgu->output_, &stream->bufferPool());\n \tif (ret)\n-\t\treturn ret;\n+\t\tgoto error_free_imgu;\n \n \t/*\n \t * Reserve memory in viewfinder and stat output devices. Use the\n \t * same number of buffers as the ones requested for the output\n \t * stream.\n \t */\n-\tunsigned int bufferCount = stream->bufferPool().count();\n+\tbufferCount = stream->bufferPool().count();\n \n \timgu->viewfinder_.pool->createBuffers(bufferCount);\n \tret = imgu->exportBuffers(&imgu->viewfinder_, imgu->viewfinder_.pool);\n \tif (ret)\n-\t\treturn ret;\n+\t\tgoto error_free_imgu;\n \n \timgu->stat_.pool->createBuffers(bufferCount);\n \tret = imgu->exportBuffers(&imgu->stat_, imgu->stat_.pool);\n \tif (ret)\n-\t\treturn ret;\n+\t\tgoto error_free_imgu;\n \n \treturn 0;\n+\n+error_free_imgu:\n+\timgu->freeBuffers();\n+\n+error_free_cio2:\n+\tcio2->freeBuffers();\n+\n+\treturn ret;\n }\n \n int PipelineHandlerIPU3::freeBuffers(Camera *camera,\n","prefixes":["libcamera-devel","v5","03/14"]}