Patch Detail
Show a patch.
GET /api/patches/14153/?format=api
{ "id": 14153, "url": "https://patchwork.libcamera.org/api/patches/14153/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14153/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<mailman.593.1634254720.837.libcamera-devel@lists.libcamera.org>", "date": "2021-10-14T23:38:33", "name": "[libcamera-devel] libcamera: v4l2_videodevice: close dmabuf fd", "commit_ref": null, "pull_url": null, "state": "rejected", "archived": false, "hash": "ac40400b81b5e0a2a5a9bf14054bc39e580aa4bb", "submitter": { "id": 100, "url": "https://patchwork.libcamera.org/api/people/100/?format=api", "name": "Karthik Poduval", "email": "kpoduval@gmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14153/mbox/", "series": [ { "id": 2629, "url": "https://patchwork.libcamera.org/api/series/2629/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2629", "date": "2021-10-14T23:38:33", "name": "[libcamera-devel] libcamera: v4l2_videodevice: close dmabuf fd", "version": 1, "mbox": "https://patchwork.libcamera.org/series/2629/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14153/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14153/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\r\n\t[92.243.16.209])\r\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 54EF6C324C\r\n\tfor <parsemail@patchwork.libcamera.org>;\r\n\tThu, 14 Oct 2021 23:38:41 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\r\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1D7BF68F52;\r\n\tFri, 15 Oct 2021 01:38:41 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\r\n\ts=mail; t=1634254721;\r\n\tbh=fViZEgX7k+Ia9bZq1nKJIpRCpwAriVsJjeVAglMH+Xw=;\r\n\th=To:Date:List-Id:List-Post:From:List-Subscribe:List-Unsubscribe:\r\n\tList-Archive:Reply-To:List-Help:Subject:From;\r\n\tb=Q3fN7WxSokHRdk8AfgfXXqNiUMs4ykGB/Nl/45rZbsTKMWB9xXOY7PyF/a804NXr3\r\n\tVwZAKclFukcl8cfb9ko8uBaqA75ZNn/N3dFImv23TDNaNEi/oEodyjTFEvsMjShyLc\r\n\t89hVfiG4WYlNBuPAxBYqU0cV6EJJ0fYqkTGYcYKeQKVMsNlmBS2KfsbSQaZZhJMJ2Q\r\n\tQfFY70ypGQFEtYE2SXdmuW2zaeaNK3pljPZpXW7fE7UKKjywkdvR8qGUlnMtwQJX3J\r\n\tpxf8YPo7phoqZ5ktuxfLGCXJ3QZlYrdtKP3LryCWluWdvF2uiEdYJqrVxfgp7pbLeh\r\n\txJjQYVK74g8eQ==", "To": "<libcamera-devel@lists.libcamera.org>", "Date": "Thu, 14 Oct 2021 23:38:33 +0000", "MIME-Version": "1.0", "Message-ID": "<mailman.593.1634254720.837.libcamera-devel@lists.libcamera.org>", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "From": "Karthik Poduval via libcamera-devel\r\n\t<libcamera-devel@lists.libcamera.org>", "Precedence": "list", "X-Mailman-Version": "2.1.29", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\r\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\r\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "Reply-To": "Karthik Poduval <kpoduval@lab126.com>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "Subject": "[libcamera-devel] [PATCH] libcamera: v4l2_videodevice: close dmabuf\r\n\tfd", "Content-Type": "message/rfc822", "Content-Disposition": "inline", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The dmabuf fd that comes from V4L2_EXPBUF is passed to FileDescriptor\nwhich makes a dup of the fd and stores it. However the original fd\nisn't closed and this causes the vb2's buf reference count to remain at\n3 (one for kernel, one for V4L2_EXPBUF and one for the dup fd by File\nDescriptor). When requestbufs is called with zero count, it unable to\nfree the buffer as the refcount is still 2. After FileDecriptor dup the\nfd the original fd must be closed so that the buf refcount is maintained\nproperly by vb2.\n\nSigned-off-by: Karthik Poduval <kpoduval@lab126.com>\n---\n src/libcamera/v4l2_videodevice.cpp | 10 +++++++++-\n 1 file changed, 9 insertions(+), 1 deletion(-)", "diff": "diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\r\nindex ba5f88cd..8c85da22 100644\r\n--- a/src/libcamera/v4l2_videodevice.cpp\r\n+++ b/src/libcamera/v4l2_videodevice.cpp\r\n@@ -1384,6 +1384,7 @@ FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index,\r\n {\r\n \tstruct v4l2_exportbuffer expbuf = {};\r\n \tint ret;\r\n+\tFileDescriptor fd;\r\n \r\n \texpbuf.type = bufferType_;\r\n \texpbuf.index = index;\r\n@@ -1397,7 +1398,14 @@ FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index,\r\n \t\treturn FileDescriptor();\r\n \t}\r\n \r\n-\treturn FileDescriptor(std::move(expbuf.fd));\r\n+\tfd = FileDescriptor(std::move(expbuf.fd));\r\n+\t/*\r\n+\t * since FileDesciptor makes a dup of the fd, original fd must be\r\n+\t * closed or else driver considers it as an orphaned buffer (due to\r\n+\t * additional buffer refcount) thus causing a frame buffer leak\r\n+\t */\r\n+\t::close(expbuf.fd);\r\n+\treturn fd;\r\n }\r\n \r\n /**", "prefixes": [ "libcamera-devel" ] }