{"id":20760,"url":"https://patchwork.libcamera.org/api/patches/20760/?format=json","web_url":"https://patchwork.libcamera.org/patch/20760/","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":"<20240804153106.22167-3-laurent.pinchart@ideasonboard.com>","date":"2024-08-04T15:31:06","name":"[v3,2/2] pipeline: rkisp1: Use ScopeExitActions to simplify error handling in start","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"953356117cf0b55b24d1a605e805e75416d69862","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20760/mbox/","series":[{"id":4482,"url":"https://patchwork.libcamera.org/api/series/4482/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4482","date":"2024-08-04T15:31:04","name":"libcamera: Simplify error handling with ScopeExitActions class","version":3,"mbox":"https://patchwork.libcamera.org/series/4482/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20760/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20760/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A8C68C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  4 Aug 2024 15:31:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5F4AA63381;\n\tSun,  4 Aug 2024 17:31:36 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 048DA63383\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  4 Aug 2024 17:31:31 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D0D531BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  4 Aug 2024 17:30:40 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"lw1FdZ9J\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722785441;\n\tbh=wIACAUXXXLbrXeOiDyZ7kanLNWrKtlHp0IjmV9DANuc=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=lw1FdZ9JGC3r3t2WF6tPPkaLTdf9oZ/c8Vjcw88RMuZLsPoOXy8YsFxxdBwNdH/l2\n\tLGEdIfkNV7ly7MRfr6/c7x7QVm4Oak6ykRMM2knRptaIbu6I20tnZsH/HTsAnMAHZk\n\tC7EJ58f38j2CXOZetguzIF+4AoI1w+fYHmBYqDc4=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v3 2/2] pipeline: rkisp1: Use ScopeExitActions to simplify\n\terror handling in start","Date":"Sun,  4 Aug 2024 18:31:06 +0300","Message-ID":"<20240804153106.22167-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.44.2","In-Reply-To":"<20240804153106.22167-1-laurent.pinchart@ideasonboard.com>","References":"<20240804153106.22167-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Error handling in the PipelineHandlerRkISP1::start() function is\ncumbersome. Simplify it using the utils::ScopeExitActions class.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 31 +++++++++---------------\n 1 file changed, 11 insertions(+), 20 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex eec5bf949bed..f7ca7025f95b 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -915,71 +915,62 @@ int PipelineHandlerRkISP1::freeBuffers(Camera *camera)\n int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] const ControlList *controls)\n {\n \tRkISP1CameraData *data = cameraData(camera);\n+\tutils::ScopeExitActions actions;\n \tint ret;\n \n \t/* Allocate buffers for internal pipeline usage. */\n \tret = allocateBuffers(camera);\n \tif (ret)\n \t\treturn ret;\n+\tactions += [&]() { freeBuffers(camera); };\n \n \tret = data->ipa_->start();\n \tif (ret) {\n-\t\tfreeBuffers(camera);\n \t\tLOG(RkISP1, Error)\n \t\t\t<< \"Failed to start IPA \" << camera->id();\n \t\treturn ret;\n \t}\n+\tactions += [&]() { data->ipa_->stop(); };\n \n \tdata->frame_ = 0;\n \n \tif (!isRaw_) {\n \t\tret = param_->streamOn();\n \t\tif (ret) {\n-\t\t\tdata->ipa_->stop();\n-\t\t\tfreeBuffers(camera);\n \t\t\tLOG(RkISP1, Error)\n \t\t\t\t<< \"Failed to start parameters \" << camera->id();\n \t\t\treturn ret;\n \t\t}\n+\t\tactions += [&]() { param_->streamOff(); };\n \n \t\tret = stat_->streamOn();\n \t\tif (ret) {\n-\t\t\tparam_->streamOff();\n-\t\t\tdata->ipa_->stop();\n-\t\t\tfreeBuffers(camera);\n \t\t\tLOG(RkISP1, Error)\n \t\t\t\t<< \"Failed to start statistics \" << camera->id();\n \t\t\treturn ret;\n \t\t}\n+\t\tactions += [&]() { stat_->streamOff(); };\n \t}\n \n \tif (data->mainPath_->isEnabled()) {\n \t\tret = mainPath_.start();\n-\t\tif (ret) {\n-\t\t\tparam_->streamOff();\n-\t\t\tstat_->streamOff();\n-\t\t\tdata->ipa_->stop();\n-\t\t\tfreeBuffers(camera);\n+\t\tif (ret)\n \t\t\treturn ret;\n-\t\t}\n+\t\tactions += [&]() { mainPath_.stop(); };\n \t}\n \n \tif (hasSelfPath_ && data->selfPath_->isEnabled()) {\n \t\tret = selfPath_.start();\n-\t\tif (ret) {\n-\t\t\tmainPath_.stop();\n-\t\t\tparam_->streamOff();\n-\t\t\tstat_->streamOff();\n-\t\t\tdata->ipa_->stop();\n-\t\t\tfreeBuffers(camera);\n+\t\tif (ret)\n \t\t\treturn ret;\n-\t\t}\n \t}\n \n \tisp_->setFrameStartEnabled(true);\n \n \tactiveCamera_ = camera;\n-\treturn ret;\n+\n+\tactions.release();\n+\treturn 0;\n }\n \n void PipelineHandlerRkISP1::stopDevice(Camera *camera)\n","prefixes":["v3","2/2"]}