[{"id":33178,"web_url":"https://patchwork.libcamera.org/comment/33178/","msgid":"<20250126212529.GA1059@pendragon.ideasonboard.com>","date":"2025-01-26T21:25:29","subject":"Re: [RFC PATCH v2 06/13] libcamera: simple: Protect against null\n\tmaxPipeConfig","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Fri, Jan 24, 2025 at 10:57:57PM +0100, Milan Zamazal wrote:\n> SimpleCameraData::pipeConfig_ is set to the determined maxPipeConfig if\n> no better configuration is found.  In the current code, maxPipeConfig\n> should be always set.  But it may be easy to miss that requirement and\n> end up with null maxPipeConfig on contingent code changes.\n> \n> Let's add a check for nullptr to prevent segmentation fault surprises.\n> It doesn't harm.\n\nBut that should never happen. I'm fine hardening the code, but not with\nan error check like this. If you think the code is too bug-prone, it\nshould be refactored to make it less bug-prone.\n\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  src/libcamera/pipeline/simple/simple.cpp | 7 ++++++-\n>  1 file changed, 6 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index e6bbff5d..300ebbc0 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -1078,8 +1078,13 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n>  \t}\n>  \n>  \t/* If no configuration was large enough, select the largest one. */\n> -\tif (!pipeConfig_)\n> +\tif (!pipeConfig_) {\n> +\t\tif (!maxPipeConfig) {\n> +\t\t\tLOG(SimplePipeline, Error) << \"No valid configuration found\";\n> +\t\t\treturn Invalid;\n> +\t\t}\n>  \t\tpipeConfig_ = maxPipeConfig;\n> +\t}\n>  \n>  \tLOG(SimplePipeline, Debug)\n>  \t\t<< \"Picked \"","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 2EFA9BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 26 Jan 2025 21:25:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 250EE6855D;\n\tSun, 26 Jan 2025 22:25:42 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 543C768506\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 26 Jan 2025 22:25:40 +0100 (CET)","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 30558BC0;\n\tSun, 26 Jan 2025 22:24:34 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"b7NWAK1N\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1737926674;\n\tbh=NlHLqcgErk2psYse8SHPt+5qKFsNGLihqz49jFuG9lQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=b7NWAK1N0Q8jQUWIZ9fX80GHoumDIxbxs7wurvygASos55OocV9f++/hZtGojy2kI\n\tNEBwFU4FX9Z9CJ1nSKvpeJt9JppHQSJpwvrAwOGxik5To5I8LRywcRC01LJdT//Agw\n\tcultZdHm0N+esNZXMHUs3W/4HcW6NJP6zuVHJB5s=","Date":"Sun, 26 Jan 2025 23:25:29 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 06/13] libcamera: simple: Protect against null\n\tmaxPipeConfig","Message-ID":"<20250126212529.GA1059@pendragon.ideasonboard.com>","References":"<20250124215806.158024-1-mzamazal@redhat.com>\n\t<20250124215806.158024-7-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250124215806.158024-7-mzamazal@redhat.com>","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>"}}]