From patchwork Mon Mar 4 23:25:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 701 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 667B6611A2 for ; Tue, 5 Mar 2019 00:25:37 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E4C34322; Tue, 5 Mar 2019 00:25:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1551741937; bh=UZhZ6VNetcFDXQvCB2eHdc2R0StuH2/jONUwm+yGUlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YaDxY1cHdggoxRbCCCgPbsBFitKnl5HWdlOn1Zo48yoiAO4ZZZjSb7QvkdHh663Ks GczEsZbcNLwt+4RxY3deDPy7UFFjWOL0A2Gi1nvXbB+TW1TkBNzl5huf23WHj3cBdA ix0Tx1AAk7VnGxKNE0l9QifJYXwOQKnOoeVlaupA= From: Kieran Bingham To: LibCamera Devel Date: Mon, 4 Mar 2019 23:25:29 +0000 Message-Id: <20190304232530.4427-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190304232530.4427-1-kieran.bingham@ideasonboard.com> References: <20190304232530.4427-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: v4l2_device: Close Plane dmabuf fd 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: Mon, 04 Mar 2019 23:25:38 -0000 When constructing a Plane, the exported buffer provides a dmabuf handle which is set to the Plane object. This action duplicates the handle for internal storage, and the original fd is not used and needs to be closed. Close the handle, ensuring that the resources can be correctly managed. Fixes: 771befc6dc0e ("libcamera: v4l2_device: Request buffers from the device") Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_device.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 0cd9f4b8e178..a88a5f5ff036 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -676,6 +676,7 @@ int V4L2Device::createPlane(Buffer *buffer, unsigned int planeIndex, buffer->planes().emplace_back(); Plane &plane = buffer->planes().back(); plane.setDmabuf(expbuf.fd, length); + ::close(expbuf.fd); return 0; } From patchwork Mon Mar 4 23:25:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 702 Return-Path: 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 9C8AB611A7 for ; Tue, 5 Mar 2019 00:25:37 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3AE7C334; Tue, 5 Mar 2019 00:25:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1551741937; bh=rhki0TsVozJQYFu9PwCs95SXzCf3WVunlLw3RJyj76U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fOgWR6jN7he2X7yS5aV3PhoRe1F24fZ4vuBvYYN7+Zz+iyLLjZzfkwJK3gTJAY5Wm BtPV1nCANP/VKDLoCIDJDRu7zrTgeCoqiLgmlq0IH8gCMmScZlv5QvAQRLcUHkE11w 7o8mtAYAOpnWscs/Ug8xV8XJZsEznWU+DMuX06hM= From: Kieran Bingham To: LibCamera Devel Date: Mon, 4 Mar 2019 23:25:30 +0000 Message-Id: <20190304232530.4427-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190304232530.4427-1-kieran.bingham@ideasonboard.com> References: <20190304232530.4427-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: camera: Unmap buffers before release 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: Mon, 04 Mar 2019 23:25:38 -0000 Before buffers can be released back to V4L2 all mappings must be unmapped. Ensure that buffers are released correctly by destroying the buffer pool contents before freeing the resources on the stream. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/camera.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 8e17085bfb50..875e1e46c89c 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -488,8 +488,13 @@ int Camera::freeBuffers() if (!stream->bufferPool().count()) continue; - pipe_->freeBuffers(this, stream); + /* + * Destroy Buffers will empty the pool, and unmap any existing + * memory mapping. This needs to be done before releasing + * buffers back to the V4L2Device through freeBuffers(). + */ stream->bufferPool().destroyBuffers(); + pipe_->freeBuffers(this, stream); } state_ = CameraConfigured;