From patchwork Tue Oct 20 19:51:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10147 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 97C38BDB13 for ; Tue, 20 Oct 2020 19:52:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 08F0E61D8E; Tue, 20 Oct 2020 21:52:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cYPKFmVl"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4390D603B0 for ; Tue, 20 Oct 2020 21:52:46 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BC05CDB1 for ; Tue, 20 Oct 2020 21:52:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1603223565; bh=gkoKl95ISo3XpmowdoMUzBOT9qNMEz4pOs2HQeL3QSc=; h=From:To:Subject:Date:From; b=cYPKFmVljyO6Q/mTuFL3Uj1XwhV+Hh4L1MftvwM14EeihEMqqFlQQi7bNIueofd+c QDYzNIgRdDHk3HPGb8Moyj7g82WajB5TtI7Por7rHWVDAFEKb3m+mQLvSIOYOJ/e1H tsfDQ5rsyFkZ8M5sjFxtYIUSSGA6T35HrhLN9ffE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 20 Oct 2020 22:51:55 +0300 Message-Id: <20201020195155.15537-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: pipeline: Fail match() when no camera is registered 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The rkisp1 and simple pipeline handlers can fail to register any camera, if initialization of all the detected cameras fail. In that case, they still return success from their match function. As no camera gets registered, the pipeline handler is immediately destroyed, releasing the acquired media devices, and the camera manager immediately tries to match the same pipeline handler with the same media device, causing an endless loop. Fix it by returning false from the match function if no camera gets registered. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 9 ++++++--- src/libcamera/pipeline/simple/simple.cpp | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 2352ab3b234a..c74a2e9bd548 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -1107,10 +1107,13 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator) if (!pad) return false; - for (MediaLink *link : pad->links()) - createCamera(link->source()->entity()); + bool registered = false; + for (MediaLink *link : pad->links()) { + if (!createCamera(link->source()->entity())) + registered = true; + } - return true; + return registered; } /* ----------------------------------------------------------------------------- diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 8c00c0ffc121..8868a43beeb4 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -821,6 +821,8 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) } /* Initialize each pipeline and register a corresponding camera. */ + bool registered = false; + for (std::unique_ptr &data : pipelines) { int ret = data->init(); if (ret < 0) @@ -830,9 +832,10 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) Camera::create(this, data->sensor_->id(), data->streams()); registerCamera(std::move(camera), std::move(data)); + registered = true; } - return true; + return registered; } V4L2VideoDevice *SimplePipelineHandler::video(const MediaEntity *entity)