From patchwork Wed Oct 21 00:24:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10148 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 72BE0BDB1F for ; Wed, 21 Oct 2020 00:25:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CD49F61DB2; Wed, 21 Oct 2020 02:25:09 +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="mGaq8zkZ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2164160350 for ; Wed, 21 Oct 2020 02:25:08 +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 9A895555 for ; Wed, 21 Oct 2020 02:25:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1603239907; bh=gkoKl95ISo3XpmowdoMUzBOT9qNMEz4pOs2HQeL3QSc=; h=From:To:Subject:Date:From; b=mGaq8zkZQM59Tu47NkTC6/qVVtGTFCIdmQqGN0UpQdx2x3RGfhU5S4cYaxLyMU19A YfmZYMAM99daZ0tuDFd4QNF1H7PshFrLWH3V/+AVaIjqDcZVmNdRQXtlTNqIOexEdn WUeXdm/6XyBf36vMdI90v/J9J7UXJXT0bB1s3x10= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 21 Oct 2020 03:24:16 +0300 Message-Id: <20201021002418.21764-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: Jacopo Mondi Tested-by: Andrey Konovalov --- 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)