From patchwork Thu Feb 28 16:29:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 654 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 28A33610B6 for ; Thu, 28 Feb 2019 17:29:25 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B58CA67 for ; Thu, 28 Feb 2019 17:29:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1551371364; bh=6EeDSKKsb49gVuJmphPuRuJ8UiJkOHnfVhKXfaGXb2k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uq5AUYYEdecQK+KiuQho0ljJbNkeYpksSDYGA8hAbutGWkP2vLofsCWzt2CHx4fTW I5eEhCuMsPDvV366pzGUdDWZ82PBvJxHmDWfMQVBKuOFBglUkFYzipxXaWTksQxQgx ZaPSCsi96zIY8wvo8nq3r7gZUOlxYXuNJp1jsm48= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Feb 2019 18:29:04 +0200 Message-Id: <20190228162913.6508-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190228162913.6508-1-laurent.pinchart@ideasonboard.com> References: <20190228162913.6508-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 01/10] libcamera: pipeline: Fix double release of media devices X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2019 16:29:25 -0000 Media devices are acquired in the match() function of pipeline handlers, and explicitly released if no match is found. The pipeline handler is then deleted, which causes a second release of the media device in the destructor. Fix this by removing the explicit release in the match() function. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Acked-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 28 +++++++++++----------------- src/libcamera/pipeline/uvcvideo.cpp | 1 - src/libcamera/pipeline/vimc.cpp | 5 +---- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 9694d0ce51ab..cf5c28577393 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -278,19 +278,20 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator) imgu_dm.add("ipu3-imgu 1 viewfinder"); imgu_dm.add("ipu3-imgu 1 3a stat"); + /* + * It is safe to acquire both media devices at this point as + * DeviceEnumerator::search() skips the busy ones for us. + */ cio2_ = enumerator->search(cio2_dm); if (!cio2_) return false; + cio2_->acquire(); + imgu_ = enumerator->search(imgu_dm); if (!imgu_) return false; - /* - * It is safe to acquire both media devices at this point as - * DeviceEnumerator::search() skips the busy ones for us. - */ - cio2_->acquire(); imgu_->acquire(); /* @@ -301,25 +302,18 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator) * not need to be changed after. */ if (cio2_->open()) - goto error_release_mdev; + return false; - if (cio2_->disableLinks()) - goto error_close_cio2; + if (cio2_->disableLinks()) { + cio2_->close(); + return false; + } registerCameras(); cio2_->close(); return true; - -error_close_cio2: - cio2_->close(); - -error_release_mdev: - cio2_->release(); - imgu_->release(); - - return false; } /* diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index b7b8ff109109..dd20bb085a29 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -167,7 +167,6 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) if (!video_) LOG(UVC, Error) << "Could not find a default video device"; - media_->release(); return false; } diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 812777cffbb3..640fca5cb0e7 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -165,11 +165,8 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) media_->acquire(); video_ = new V4L2Device(media_->getEntityByName("Raw Capture 1")); - - if (video_->open()) { - media_->release(); + if (video_->open()) return false; - } std::vector streams{ &stream_ }; std::shared_ptr camera = Camera::create(this, "VIMC Sensor B",