Patch Detail
Show a patch.
GET /api/patches/14868/?format=api
{ "id": 14868, "url": "https://patchwork.libcamera.org/api/patches/14868/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14868/", "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-14-laurent.pinchart@ideasonboard.com>", "date": "2021-11-30T03:38:11", "name": "[libcamera-devel,v4,13/22] libcamera: media_device: Manage fd by UniqueFD", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "ae550fb2db8437a874a1ee98bb2f59a3ff0f4404", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14868/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/14868/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14868/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 7455CC324F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 03:39:11 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2082B605CA;\n\tTue, 30 Nov 2021 04:39:11 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9540E605CB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 04:38:54 +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 2B1C78F0;\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=\"QebHCXQL\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638243534;\n\tbh=oNBjFN0xuIBQza74WRtXsPByAO9ei0dL+JgjmbSvjbw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=QebHCXQLIUj9ZerJs4EGXeTp9XUaE61LK8vFcGibW8x/Btcx6VhRcPjA9LYPXiCro\n\tS+zSNheXAMJDJyvaW3VoQdNrFYYFSIXCzlKZdai6Ye2loXB7AjVJQCwtSBULWQzBR3\n\tS+QobJqDxetO6cIkC+4QLH4ByZgHjRQDvcMVHAxo=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 30 Nov 2021 05:38:11 +0200", "Message-Id": "<20211130033820.18235-14-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 13/22] libcamera: media_device: Manage\n\tfd by UniqueFD", "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 MediaDevice for a media device\nnode by 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/media_device.h | 3 +-\n src/libcamera/media_device.cpp | 36 ++++++++++-------------\n 2 files changed, 17 insertions(+), 22 deletions(-)", "diff": "diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h\nindex d636e34a8573..af0b25b731eb 100644\n--- a/include/libcamera/internal/media_device.h\n+++ b/include/libcamera/internal/media_device.h\n@@ -16,6 +16,7 @@\n \n #include <libcamera/base/log.h>\n #include <libcamera/base/signal.h>\n+#include <libcamera/base/unique_fd.h>\n \n #include \"libcamera/internal/media_object.h\"\n \n@@ -82,7 +83,7 @@ private:\n \tunsigned int version_;\n \tunsigned int hwRevision_;\n \n-\tint fd_;\n+\tUniqueFD fd_;\n \tbool valid_;\n \tbool acquired_;\n \tbool lockOwner_;\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex aa93da75c593..4df0a27fe193 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -63,15 +63,14 @@ LOG_DEFINE_CATEGORY(MediaDevice)\n * populate() before the media graph can be queried.\n */\n MediaDevice::MediaDevice(const std::string &deviceNode)\n-\t: deviceNode_(deviceNode), fd_(-1), valid_(false), acquired_(false),\n+\t: deviceNode_(deviceNode), valid_(false), acquired_(false),\n \t lockOwner_(false)\n {\n }\n \n MediaDevice::~MediaDevice()\n {\n-\tif (fd_ != -1)\n-\t\t::close(fd_);\n+\tfd_.reset();\n \tclear();\n }\n \n@@ -143,14 +142,14 @@ void MediaDevice::release()\n */\n bool MediaDevice::lock()\n {\n-\tif (fd_ == -1)\n+\tif (!fd_.isValid())\n \t\treturn false;\n \n \t/* Do not allow nested locking in the same libcamera instance. */\n \tif (lockOwner_)\n \t\treturn false;\n \n-\tif (lockf(fd_, F_TLOCK, 0))\n+\tif (lockf(fd_.get(), F_TLOCK, 0))\n \t\treturn false;\n \n \tlockOwner_ = true;\n@@ -169,7 +168,7 @@ bool MediaDevice::lock()\n */\n void MediaDevice::unlock()\n {\n-\tif (fd_ == -1)\n+\tif (!fd_.isValid())\n \t\treturn;\n \n \tif (!lockOwner_)\n@@ -177,7 +176,7 @@ void MediaDevice::unlock()\n \n \tlockOwner_ = false;\n \n-\tlockf(fd_, F_ULOCK, 0);\n+\tlockf(fd_.get(), F_ULOCK, 0);\n }\n \n /**\n@@ -220,7 +219,7 @@ int MediaDevice::populate()\n \t\treturn ret;\n \n \tstruct media_device_info info = {};\n-\tret = ioctl(fd_, MEDIA_IOC_DEVICE_INFO, &info);\n+\tret = ioctl(fd_.get(), MEDIA_IOC_DEVICE_INFO, &info);\n \tif (ret) {\n \t\tret = -errno;\n \t\tLOG(MediaDevice, Error)\n@@ -243,7 +242,7 @@ int MediaDevice::populate()\n \t\ttopology.ptr_links = reinterpret_cast<uintptr_t>(links);\n \t\ttopology.ptr_pads = reinterpret_cast<uintptr_t>(pads);\n \n-\t\tret = ioctl(fd_, MEDIA_IOC_G_TOPOLOGY, &topology);\n+\t\tret = ioctl(fd_.get(), MEDIA_IOC_G_TOPOLOGY, &topology);\n \t\tif (ret < 0) {\n \t\t\tret = -errno;\n \t\t\tLOG(MediaDevice, Error)\n@@ -481,20 +480,19 @@ int MediaDevice::disableLinks()\n */\n int MediaDevice::open()\n {\n-\tif (fd_ != -1) {\n+\tif (fd_.isValid()) {\n \t\tLOG(MediaDevice, Error) << \"MediaDevice already open\";\n \t\treturn -EBUSY;\n \t}\n \n-\tint ret = ::open(deviceNode_.c_str(), O_RDWR);\n-\tif (ret < 0) {\n-\t\tret = -errno;\n+\tfd_ = UniqueFD(::open(deviceNode_.c_str(), O_RDWR));\n+\tif (!fd_.isValid()) {\n+\t\tint ret = -errno;\n \t\tLOG(MediaDevice, Error)\n \t\t\t<< \"Failed to open media device at \"\n \t\t\t<< deviceNode_ << \": \" << strerror(-ret);\n \t\treturn ret;\n \t}\n-\tfd_ = ret;\n \n \treturn 0;\n }\n@@ -514,11 +512,7 @@ int MediaDevice::open()\n */\n void MediaDevice::close()\n {\n-\tif (fd_ == -1)\n-\t\treturn;\n-\n-\t::close(fd_);\n-\tfd_ = -1;\n+\tfd_.reset();\n }\n \n /**\n@@ -756,7 +750,7 @@ void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity)\n \tstruct media_entity_desc desc = {};\n \tdesc.id = entity->id;\n \n-\tint ret = ioctl(fd_, MEDIA_IOC_ENUM_ENTITIES, &desc);\n+\tint ret = ioctl(fd_.get(), MEDIA_IOC_ENUM_ENTITIES, &desc);\n \tif (ret < 0) {\n \t\tret = -errno;\n \t\tLOG(MediaDevice, Debug)\n@@ -799,7 +793,7 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)\n \n \tlinkDesc.flags = flags;\n \n-\tint ret = ioctl(fd_, MEDIA_IOC_SETUP_LINK, &linkDesc);\n+\tint ret = ioctl(fd_.get(), MEDIA_IOC_SETUP_LINK, &linkDesc);\n \tif (ret) {\n \t\tret = -errno;\n \t\tLOG(MediaDevice, Error)\n", "prefixes": [ "libcamera-devel", "v4", "13/22" ] }