Patch Detail
Show a patch.
GET /api/patches/14870/?format=api
{ "id": 14870, "url": "https://patchwork.libcamera.org/api/patches/14870/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14870/", "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": "<20211130033820.18235-17-laurent.pinchart@ideasonboard.com>", "date": "2021-11-30T03:38:14", "name": "[libcamera-devel,v4,16/22] libcamera: v4l2_videodevice: Pass SharedFD to open()", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "5970720741f3d1b4fc62f290bf7221ea18402ff3", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": { "id": 14, "url": "https://patchwork.libcamera.org/api/users/14/?format=api", "username": "pinchartl", "first_name": "Laurent", "last_name": "Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "mbox": "https://patchwork.libcamera.org/patch/14870/mbox/", "series": [ { "id": 2776, "url": "https://patchwork.libcamera.org/api/series/2776/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2776", "date": "2021-11-30T03:37:58", "name": "libcamera: Introduce UniqueFD", "version": 4, "mbox": "https://patchwork.libcamera.org/series/2776/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14870/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14870/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\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id BC66EC3251\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 03:39:12 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6397D605C2;\n\tTue, 30 Nov 2021 04:39:12 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 21AB5605BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 04:38:56 +0100 (CET)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B05C211FB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 04:38:55 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"bHsiojhX\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638243535;\n\tbh=SeyzkNKxBvNqGt6W5rdjec51yqCbeLJdUCINRKHg0p4=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=bHsiojhXi2dqgNmbHtzO1WAatEXC7o48XxScwkT80UP1piDQoQFc/o9So9BiN0gXY\n\tCkVh7kJl/3WVHmHngkHKOpph8IUrvvkqLKAT0HoK4GKh/0NsczJ8bDJnY8CexnyUj0\n\tylyD3pFotNpzWG1HmtL6jQ9kgr7/OltEap9USmfY=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 30 Nov 2021 05:38:14 +0200", "Message-Id": "<20211130033820.18235-17-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20211130033820.18235-1-laurent.pinchart@ideasonboard.com>", "References": "<20211130033820.18235-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 16/22] libcamera: v4l2_videodevice:\n\tPass SharedFD to open()", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The V4L2VideoDevice::open() function that takes an open file handle\nduplicates it internally, and leaves the original handle untouched. This\nis documented but not enforced through language constructs. Fix it by\npassing a SharedFD to the function.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/v4l2_videodevice.h | 2 +-\n src/libcamera/v4l2_videodevice.cpp | 22 ++++++++-----------\n 2 files changed, 10 insertions(+), 14 deletions(-)", "diff": "diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 80b665771782..9f556f99587c 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -184,7 +184,7 @@ public:\n \t~V4L2VideoDevice();\n \n \tint open();\n-\tint open(int handle, enum v4l2_buf_type type);\n+\tint open(FileDescriptor handle, enum v4l2_buf_type type);\n \tvoid close();\n \n \tconst char *driverName() const { return caps_.driver(); }\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 3966483a365f..5f1cc6e2f47f 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -612,16 +612,14 @@ int V4L2VideoDevice::open()\n * its type from the capabilities. This can be used to force a given device type\n * for memory-to-memory devices.\n *\n- * The file descriptor \\a handle is duplicated, and the caller is responsible\n- * for closing the \\a handle when it has no further use for it. The close()\n- * function will close the duplicated file descriptor, leaving \\a handle\n- * untouched.\n+ * The file descriptor \\a handle is duplicated, no reference to the original\n+ * handle is kept.\n *\n * \\return 0 on success or a negative error code otherwise\n */\n-int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type)\n+int V4L2VideoDevice::open(FileDescriptor handle, enum v4l2_buf_type type)\n {\n-\tUniqueFD newFd(dup(handle));\n+\tUniqueFD newFd = handle.dup();\n \tif (!newFd.isValid()) {\n \t\tLOG(V4L2, Error) << \"Failed to duplicate file handle: \"\n \t\t\t\t << strerror(errno);\n@@ -1900,12 +1898,10 @@ int V4L2M2MDevice::open()\n \n \t/*\n \t * The output and capture V4L2VideoDevice instances use the same file\n-\t * handle for the same device node. The local file handle can be closed\n-\t * as the V4L2VideoDevice::open() retains a handle by duplicating the\n-\t * fd passed in.\n+\t * handle for the same device node.\n \t */\n-\tUniqueFD fd(syscall(SYS_openat, AT_FDCWD, deviceNode_.c_str(),\n-\t\t\t O_RDWR | O_NONBLOCK));\n+\tFileDescriptor fd(syscall(SYS_openat, AT_FDCWD, deviceNode_.c_str(),\n+\t\t\t\t O_RDWR | O_NONBLOCK));\n \tif (!fd.isValid()) {\n \t\tret = -errno;\n \t\tLOG(V4L2, Error) << \"Failed to open V4L2 M2M device: \"\n@@ -1913,11 +1909,11 @@ int V4L2M2MDevice::open()\n \t\treturn ret;\n \t}\n \n-\tret = output_->open(fd.get(), V4L2_BUF_TYPE_VIDEO_OUTPUT);\n+\tret = output_->open(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT);\n \tif (ret)\n \t\tgoto err;\n \n-\tret = capture_->open(fd.get(), V4L2_BUF_TYPE_VIDEO_CAPTURE);\n+\tret = capture_->open(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE);\n \tif (ret)\n \t\tgoto err;\n \n", "prefixes": [ "libcamera-devel", "v4", "16/22" ] }