Show a patch.

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

{
    "id": 12538,
    "url": "https://patchwork.libcamera.org/api/patches/12538/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/12538/",
    "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": "<20210610075027.523672-6-hiroh@chromium.org>",
    "date": "2021-06-10T07:50:22",
    "name": "[libcamera-devel,v2,05/10] libcamera: MediaDevice: Manage fd by ScopedFD",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "d9de66df2b758088e541437390c780acc9440977",
    "submitter": {
        "id": 63,
        "url": "https://patchwork.libcamera.org/api/people/63/?format=api",
        "name": "Hirokazu Honda",
        "email": "hiroh@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/12538/mbox/",
    "series": [
        {
            "id": 2115,
            "url": "https://patchwork.libcamera.org/api/series/2115/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2115",
            "date": "2021-06-10T07:50:17",
            "name": "Introduce ScopedFD",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2115/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/12538/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/12538/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 C0A66BD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Jun 2021 07:50:44 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 84F5F6893B;\n\tThu, 10 Jun 2021 09:50:44 +0200 (CEST)",
            "from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com\n\t[IPv6:2607:f8b0:4864:20::62f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 137D66892C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Jun 2021 09:50:43 +0200 (CEST)",
            "by mail-pl1-x62f.google.com with SMTP id 69so544549plc.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Jun 2021 00:50:42 -0700 (PDT)",
            "from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:98e0:b356:1c8a:25d4])\n\tby smtp.gmail.com with ESMTPSA id\n\td66sm1565161pfa.32.2021.06.10.00.50.40\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 10 Jun 2021 00:50:41 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"Hifbk8Sg\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=j5NZZ4iXvafGwsvGWf4VPksAYgE7O1U8gS5PYWmf/To=;\n\tb=Hifbk8Sg5H13aBfwgVGJbOazl0dO0Q+V8lnXnmbUzVv8w3cuM6lXmzx9aG38gQtp8O\n\tK4ykIUVdtEs80ZzgEzv58lsNrO0rbRWcDrU0MwxK9a1vOK2/I6IEkzoUdtd2ap/rctaN\n\tHIq+T0UmO7eJP/FIEvvXxCZxO8zdMmMRx974Q=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=j5NZZ4iXvafGwsvGWf4VPksAYgE7O1U8gS5PYWmf/To=;\n\tb=mPQ+ddOfPxV+Oh2nUiaUd96EyYmppW0fu8BngPugWxAYVR4kQZYGzve48CalzDPawi\n\tu6Wfmv937cru2thputc/VgfXsoXQBidLwNBvDONhg2SS028c6l++KU8tMh/0NJ9eRY95\n\t/NdnHJROvgwcCQHzIqAvWBDTiOliTAvicZnWVX2l2EUEOkLmQY6knB73H8k6pKGgMcOp\n\tNXpySGSIpkxmHRRyMd94wzq3Y97onbikW3/MdG0EHrk77oce/RkCTI2xK8vRkQXPDcdf\n\tbG5vznXxwmLceQ3iK3X/aRATpHkPSxhQD+zMP91Waj8ot3EzA3eorr4Rg5eQPuMQmD7v\n\tcCFA==",
        "X-Gm-Message-State": "AOAM533iUKOSpauMBJtEzPA6IL9cl/1hb7njgr9mLb1ncNOlVba+HGNy\n\tfSGUpL+kT7P9AlNHDcYNEX3FzUgiBxaBIQ==",
        "X-Google-Smtp-Source": "ABdhPJz34NJJrhdNYei7z2tfdr5lM82BckRdYpZwC0sSnAXhOeSRY7HnIn7BlPZVpr9JAtUnyRKKBQ==",
        "X-Received": "by 2002:a17:902:8c91:b029:ef:aa9a:af35 with SMTP id\n\tt17-20020a1709028c91b02900efaa9aaf35mr3549104plo.24.1623311441423; \n\tThu, 10 Jun 2021 00:50:41 -0700 (PDT)",
        "From": "Hirokazu Honda <hiroh@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 10 Jun 2021 16:50:22 +0900",
        "Message-Id": "<20210610075027.523672-6-hiroh@chromium.org>",
        "X-Mailer": "git-send-email 2.32.0.rc1.229.g3e70b5a671-goog",
        "In-Reply-To": "<20210610075027.523672-1-hiroh@chromium.org>",
        "References": "<20210610075027.523672-1-hiroh@chromium.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 05/10] libcamera: MediaDevice: Manage\n\tfd by ScopedFD",
        "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": "Manages a file descriptor owned by MediaDevice for a media device\nnode by ScopedFD.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n include/libcamera/internal/media_device.h |  3 +-\n src/libcamera/media_device.cpp            | 39 ++++++++++-------------\n 2 files changed, 18 insertions(+), 24 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h\nindex c3292508..7722df06 100644\n--- a/include/libcamera/internal/media_device.h\n+++ b/include/libcamera/internal/media_device.h\n@@ -14,6 +14,7 @@\n \n #include <linux/media.h>\n \n+#include <libcamera/scoped_fd.h>\n #include <libcamera/signal.h>\n \n #include \"libcamera/internal/log.h\"\n@@ -82,7 +83,7 @@ private:\n \tunsigned int version_;\n \tunsigned int hwRevision_;\n \n-\tint fd_;\n+\tScopedFD 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 9ec84e56..1050bf6d 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,18 @@ 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_ = ScopedFD(::open(deviceNode_.c_str(), O_RDWR));\n+\tif (!fd_.isValid()) {\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\t\t<< deviceNode_ << \": \" << strerror(errno);\n+\t\treturn -errno;\n \t}\n-\tfd_ = ret;\n \n \treturn 0;\n }\n@@ -514,11 +511,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@@ -763,7 +756,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@@ -806,7 +799,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",
        "v2",
        "05/10"
    ]
}