From patchwork Tue Dec 28 21:59:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15230 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 88FA4C3259 for ; Tue, 28 Dec 2021 22:00:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1D21060917; Tue, 28 Dec 2021 23:00:04 +0100 (CET) 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="hIteENsB"; 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 4339560868 for ; Tue, 28 Dec 2021 22:59:59 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DC95C3E7 for ; Tue, 28 Dec 2021 22:59:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640728799; bh=MjWKeZN9GqCHXj+cYSixOLC838Yfriuc6ECgBJSnzzg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hIteENsBsjVSXaGBGNlwQ/btk8JUmsPDMnCsIgrJsfdOA50wgf4XIiXls1F+idgHk BrLvHR25FRBAu9zx+ZXNbd9/445c9onF0QP6+LYxRIx25TxcIkTz2xREO8qrWQ8HOB 7XXfqjiQAbq8paPuw/zfYoqkEvs6umGwXTOSJXsg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Dec 2021 23:59:50 +0200 Message-Id: <20211228215951.32396-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> References: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 4/5] v4l2: v4l2_compat_manager: Store V4L2CameraFile in mmaps_ 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 mmaps_ map stores a pointer to the V4L2CameraProxy to avoid increasing the reference count on the V4L2CameraFile shared pointer needlessly. While this provides a small optimization, it prevents accessing the V4L2CameraFile from the munmap() function which doesn't take an fd as argument. To prepare for improved debugging that will require access to V4L2CameraFile in munmap(), store the V4L2CameraFile pointer in mmaps_. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/v4l2/v4l2_compat_manager.cpp | 10 +++------- src/v4l2/v4l2_compat_manager.h | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index 585046e97e4b..ded568beb60e 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -198,11 +198,7 @@ void *V4L2CompatManager::mmap(void *addr, size_t length, int prot, int flags, if (map == MAP_FAILED) return map; - /* - * Map to V4L2CameraProxy directly to prevent adding more references - * to V4L2CameraFile. - */ - mmaps_[map] = file->proxy(); + mmaps_[map] = file; return map; } @@ -212,9 +208,9 @@ int V4L2CompatManager::munmap(void *addr, size_t length) if (device == mmaps_.end()) return fops_.munmap(addr, length); - V4L2CameraProxy *proxy = device->second; + V4L2CameraFile *file = device->second.get(); - int ret = proxy->munmap(addr, length); + int ret = file->proxy()->munmap(addr, length); if (ret < 0) return ret; diff --git a/src/v4l2/v4l2_compat_manager.h b/src/v4l2/v4l2_compat_manager.h index f52069f7b62d..64af9a8c008f 100644 --- a/src/v4l2/v4l2_compat_manager.h +++ b/src/v4l2/v4l2_compat_manager.h @@ -65,5 +65,5 @@ private: std::vector> proxies_; std::map> files_; - std::map mmaps_; + std::map> mmaps_; };