Show a patch.

GET /api/1.1/patches/14869/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 14869,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/14869/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/14869/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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-15-laurent.pinchart@ideasonboard.com>",
    "date": "2021-11-30T03:38:12",
    "name": "[libcamera-devel,v4,14/22] libcamera: v4l2_device: Use UniqueFD for a file descriptor",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "98c860b291944620b4d9f3ee8798060f263cbacc",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/14869/mbox/",
    "series": [
        {
            "id": 2776,
            "url": "https://patchwork.libcamera.org/api/1.1/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/14869/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/14869/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 19C7EBF415\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 BFA80605C7;\n\tTue, 30 Nov 2021 04:39:11 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 10673605CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 04:38:55 +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 976B611C5; \n\tTue, 30 Nov 2021 04:38:54 +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=\"Yl7r2BRB\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638243534;\n\tbh=H24AFrqDzwI42qQ6RLWntdF32rr49kklWsD1riSF05M=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Yl7r2BRBGid5JW/59iGgPnrvD8EEa/TnZWIagZAN9su2vDpmQZSCWHLN9MdCHUJzq\n\tmwQsf0OrDDLwGNIiPugKQ/aKKkonFdhmUxhxGIfv9HZPflnoSEfqNvesMHyvysTu2O\n\toSKx6ru61HnTRRb6AJMOLT2J03zO4Ey0ISh/BseU=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 30 Nov 2021 05:38:12 +0200",
        "Message-Id": "<20211130033820.18235-15-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 14/22] libcamera: v4l2_device: Use\n\tUniqueFD for a file descriptor",
        "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": "From: Hirokazu Honda <hiroh@chromium.org>\n\nManages a file descriptor owned by V4L2Device for a v4l2 device node\nby UniqueFD.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nChanges since v2:\n\n- Fix errno handling\n---\n include/libcamera/internal/v4l2_device.h |  9 +++++----\n src/libcamera/v4l2_device.cpp            | 23 ++++++++++-------------\n src/libcamera/v4l2_videodevice.cpp       | 16 ++++++----------\n 3 files changed, 21 insertions(+), 27 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex 7816a290141d..8886b750ae29 100644\n--- a/include/libcamera/internal/v4l2_device.h\n+++ b/include/libcamera/internal/v4l2_device.h\n@@ -16,6 +16,7 @@\n #include <libcamera/base/log.h>\n #include <libcamera/base/signal.h>\n #include <libcamera/base/span.h>\n+#include <libcamera/base/unique_fd.h>\n \n #include <libcamera/controls.h>\n \n@@ -27,7 +28,7 @@ class V4L2Device : protected Loggable\n {\n public:\n \tvoid close();\n-\tbool isOpen() const { return fd_ != -1; }\n+\tbool isOpen() const { return fd_.isValid(); }\n \n \tconst ControlInfoMap &controls() const { return controls_; }\n \n@@ -49,11 +50,11 @@ protected:\n \t~V4L2Device();\n \n \tint open(unsigned int flags);\n-\tint setFd(int fd);\n+\tint setFd(UniqueFD fd);\n \n \tint ioctl(unsigned long request, void *argp);\n \n-\tint fd() const { return fd_; }\n+\tint fd() const { return fd_.get(); }\n \n private:\n \tstatic ControlType v4l2CtrlType(uint32_t ctrlType);\n@@ -72,7 +73,7 @@ private:\n \tControlIdMap controlIdMap_;\n \tControlInfoMap controls_;\n \tstd::string deviceNode_;\n-\tint fd_;\n+\tUniqueFD fd_;\n \n \tEventNotifier *fdEventNotifier_;\n \tbool frameStartEnabled_;\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 9c783c9cbed1..39f360091f64 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -53,7 +53,7 @@ LOG_DEFINE_CATEGORY(V4L2)\n  * at open() time, and the \\a logTag to prefix log messages with.\n  */\n V4L2Device::V4L2Device(const std::string &deviceNode)\n-\t: deviceNode_(deviceNode), fd_(-1), fdEventNotifier_(nullptr),\n+\t: deviceNode_(deviceNode), fdEventNotifier_(nullptr),\n \t  frameStartEnabled_(false)\n {\n }\n@@ -81,15 +81,15 @@ int V4L2Device::open(unsigned int flags)\n \t\treturn -EBUSY;\n \t}\n \n-\tint ret = syscall(SYS_openat, AT_FDCWD, deviceNode_.c_str(), flags);\n-\tif (ret < 0) {\n-\t\tret = -errno;\n+\tUniqueFD fd(syscall(SYS_openat, AT_FDCWD, deviceNode_.c_str(), flags));\n+\tif (!fd.isValid()) {\n+\t\tint ret = -errno;\n \t\tLOG(V4L2, Error) << \"Failed to open V4L2 device: \"\n \t\t\t\t << strerror(-ret);\n \t\treturn ret;\n \t}\n \n-\tsetFd(ret);\n+\tsetFd(std::move(fd));\n \n \tlistControls();\n \n@@ -112,14 +112,14 @@ int V4L2Device::open(unsigned int flags)\n  *\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2Device::setFd(int fd)\n+int V4L2Device::setFd(UniqueFD fd)\n {\n \tif (isOpen())\n \t\treturn -EBUSY;\n \n-\tfd_ = fd;\n+\tfd_ = std::move(fd);\n \n-\tfdEventNotifier_ = new EventNotifier(fd_, EventNotifier::Exception);\n+\tfdEventNotifier_ = new EventNotifier(fd_.get(), EventNotifier::Exception);\n \tfdEventNotifier_->activated.connect(this, &V4L2Device::eventAvailable);\n \tfdEventNotifier_->setEnabled(false);\n \n@@ -138,10 +138,7 @@ void V4L2Device::close()\n \n \tdelete fdEventNotifier_;\n \n-\tif (::close(fd_) < 0)\n-\t\tLOG(V4L2, Error) << \"Failed to close V4L2 device: \"\n-\t\t\t\t << strerror(errno);\n-\tfd_ = -1;\n+\tfd_.reset();\n }\n \n /**\n@@ -440,7 +437,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n \t * Printing out an error message is usually better performed\n \t * in the caller, which can provide more context.\n \t */\n-\tif (::ioctl(fd_, request, argp) < 0)\n+\tif (::ioctl(fd_.get(), request, argp) < 0)\n \t\treturn -errno;\n \n \treturn 0;\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 0a85bcf6b3ff..c95626d33cc3 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -24,6 +24,7 @@\n #include <libcamera/base/event_notifier.h>\n #include <libcamera/base/file_descriptor.h>\n #include <libcamera/base/log.h>\n+#include <libcamera/base/unique_fd.h>\n #include <libcamera/base/utils.h>\n \n #include \"libcamera/internal/formats.h\"\n@@ -620,22 +621,17 @@ int V4L2VideoDevice::open()\n  */\n int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type)\n {\n-\tint ret;\n-\tint newFd;\n-\n-\tnewFd = dup(handle);\n-\tif (newFd < 0) {\n-\t\tret = -errno;\n+\tUniqueFD newFd(dup(handle));\n+\tif (!newFd.isValid()) {\n \t\tLOG(V4L2, Error) << \"Failed to duplicate file handle: \"\n-\t\t\t\t << strerror(-ret);\n-\t\treturn ret;\n+\t\t\t\t << strerror(errno);\n+\t\treturn -errno;\n \t}\n \n-\tret = V4L2Device::setFd(newFd);\n+\tint ret = V4L2Device::setFd(std::move(newFd));\n \tif (ret < 0) {\n \t\tLOG(V4L2, Error) << \"Failed to set file handle: \"\n \t\t\t\t << strerror(-ret);\n-\t\t::close(newFd);\n \t\treturn ret;\n \t}\n \n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "14/22"
    ]
}