Patch Detail
Show a patch.
GET /api/patches/12540/?format=api
{ "id": 12540, "url": "https://patchwork.libcamera.org/api/patches/12540/?format=api", "web_url": "https://patchwork.libcamera.org/patch/12540/", "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-8-hiroh@chromium.org>", "date": "2021-06-10T07:50:24", "name": "[libcamera-devel,v2,07/10] libcamera: V4L2VideoDevice: Use fd for a file descriptor", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "da79b340b1c517c2d2bf979bce67a8aca6e9e030", "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/12540/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/12540/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/12540/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 CF3B9BD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Jun 2021 07:50:47 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 868A46893F;\n\tThu, 10 Jun 2021 09:50:47 +0200 (CEST)", "from mail-pl1-x631.google.com (mail-pl1-x631.google.com\n\t[IPv6:2607:f8b0:4864:20::631])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D13468937\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Jun 2021 09:50:46 +0200 (CEST)", "by mail-pl1-x631.google.com with SMTP id h1so552685plt.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Jun 2021 00:50:45 -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.43\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 10 Jun 2021 00:50:43 -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=\"jGjthLhx\"; 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=oQtmMIORVn3nv2jgxMAC+YN9+BInlyeVUONDYOxbT4c=;\n\tb=jGjthLhxxXG+cHZYuL00/PWiCJUvk/WHRTybUVMR4PQ3QWdicZQNGdcVNsJBAmdfB0\n\tKLjIXTXLKRzTpfMstQW9hTayhtc0B3+47FErRpXdpeT8vuKH75uiPUzogo0gNDc535lM\n\t+cvoh4tejwz2/PnoQYMtmQo2EPiNWzpY+oWf0=", "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=oQtmMIORVn3nv2jgxMAC+YN9+BInlyeVUONDYOxbT4c=;\n\tb=dxdFLHN/41o9DnPYSqgc7n+nq9DrQbERthUCiJVaSQYRiAGWDq5PoM6z4vgP1FD+0r\n\tJ9tnJ08UJ/+nyWSDYI+6+PdX+wSq9NNPDs3awXlgfw2FeERu71ICpgkDpNkYby6c2hf4\n\trhxiWQkJ4m7RQN+I9QXswWQ0MOtqfZUhvKb34eQ6ftl2UzWzfdnl0is/EPU8wpXB0sTJ\n\tjIizIzXLX+6k3CSqMVKsfdXgtqwyFICEF9Uyxbl7mFbNQjBV+xC5Z1FGlISuJABGlFzp\n\tipaBqtUtTqGFj13Zy0o/TrWZSg1w/YoFlOrKn0rqTjReqFPSlfzaUxNOAftq75FPDJrD\n\tCJmA==", "X-Gm-Message-State": "AOAM53342/5uYw4S+8xUGijk9dmRlHFBev1jedXtQJrMYdl/9s3fg4VT\n\tse3i1KWInyzMEdV4zmq5hWUAp+UJHFZ5Ng==", "X-Google-Smtp-Source": "ABdhPJw89MROU9tHGz+IdgyYP97mkw4gvLX+pQVvGI5hOAqUUUUHi7skxKWAD6U7SDzHUrN6Y479uA==", "X-Received": "by 2002:a17:90a:f48c:: with SMTP id\n\tbx12mr2055707pjb.200.1623311444338; \n\tThu, 10 Jun 2021 00:50:44 -0700 (PDT)", "From": "Hirokazu Honda <hiroh@chromium.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 10 Jun 2021 16:50:24 +0900", "Message-Id": "<20210610075027.523672-8-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 07/10] libcamera: V4L2VideoDevice: Use\n\tfd 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": "Manages file descriptors owned by V4L2VideoDevice by ScopedFD.\nThis also changes the return type of exportDmabufFd to ScopedFD\nfrom FileDescriptor in order to represent a caller owns the\nreturned file file descriptor.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n include/libcamera/internal/v4l2_videodevice.h | 4 +--\n src/libcamera/v4l2_videodevice.cpp | 33 ++++++++-----------\n 2 files changed, 15 insertions(+), 22 deletions(-)", "diff": "diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 7938343b..925a8e82 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -30,9 +30,9 @@\n namespace libcamera {\n \n class EventNotifier;\n-class FileDescriptor;\n class MediaDevice;\n class MediaEntity;\n+class ScopedFD;\n \n struct V4L2Capability final : v4l2_capability {\n \tconst char *driver() const\n@@ -235,7 +235,7 @@ private:\n \tint createBuffers(unsigned int count,\n \t\t\t std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n \tstd::unique_ptr<FrameBuffer> createBuffer(unsigned int index);\n-\tFileDescriptor exportDmabufFd(unsigned int index, unsigned int plane);\n+\tScopedFD exportDmabufFd(unsigned int index, unsigned int plane);\n \n \tvoid bufferAvailable(EventNotifier *notifier);\n \tFrameBuffer *dequeueBuffer();\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex ce6ad8b5..1dfb011c 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1274,12 +1274,12 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n \n \tstd::vector<FrameBuffer::Plane> planes;\n \tfor (unsigned int nplane = 0; nplane < numPlanes; nplane++) {\n-\t\tFileDescriptor fd = exportDmabufFd(buf.index, nplane);\n+\t\tScopedFD fd = exportDmabufFd(buf.index, nplane);\n \t\tif (!fd.isValid())\n \t\t\treturn nullptr;\n \n \t\tFrameBuffer::Plane plane;\n-\t\tplane.fd = std::move(fd);\n+\t\tplane.fd = FileDescriptor(fd.release());\n \t\tplane.length = multiPlanar ?\n \t\t\tbuf.m.planes[nplane].length : buf.length;\n \n@@ -1289,7 +1289,7 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n \treturn std::make_unique<FrameBuffer>(std::move(planes));\n }\n \n-FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index,\n+ScopedFD V4L2VideoDevice::exportDmabufFd(unsigned int index,\n \t\t\t\t\t unsigned int plane)\n {\n \tstruct v4l2_exportbuffer expbuf = {};\n@@ -1304,10 +1304,10 @@ FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index,\n \tif (ret < 0) {\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to export buffer: \" << strerror(-ret);\n-\t\treturn FileDescriptor();\n+\t\treturn ScopedFD();\n \t}\n \n-\treturn FileDescriptor(std::move(expbuf.fd));\n+\treturn ScopedFD(expbuf.fd);\n }\n \n /**\n@@ -1699,39 +1699,32 @@ V4L2M2MDevice::~V4L2M2MDevice()\n */\n int V4L2M2MDevice::open()\n {\n-\tint fd;\n-\tint ret;\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 */\n-\tfd = syscall(SYS_openat, AT_FDCWD, deviceNode_.c_str(),\n-\t\t O_RDWR | O_NONBLOCK);\n-\tif (fd < 0) {\n-\t\tret = -errno;\n-\t\tLOG(V4L2, Error)\n-\t\t\t<< \"Failed to open V4L2 M2M device: \" << strerror(-ret);\n-\t\treturn ret;\n+\tScopedFD fd(syscall(SYS_openat, AT_FDCWD, deviceNode_.c_str(),\n+\t\t\t O_RDWR | O_NONBLOCK));\n+\tif (!fd.isValid()) {\n+\t\tLOG(V4L2, Error) << \"Failed to open V4L2 M2M device: \"\n+\t\t\t\t << strerror(errno);\n+\t\treturn -errno;\n \t}\n \n-\tret = output_->open(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT);\n+\tint ret = output_->open(fd.get(), V4L2_BUF_TYPE_VIDEO_OUTPUT);\n \tif (ret)\n \t\tgoto err;\n \n-\tret = capture_->open(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE);\n+\tret = capture_->open(fd.get(), V4L2_BUF_TYPE_VIDEO_CAPTURE);\n \tif (ret)\n \t\tgoto err;\n \n-\t::close(fd);\n-\n \treturn 0;\n \n err:\n \tclose();\n-\t::close(fd);\n \n \treturn ret;\n }\n", "prefixes": [ "libcamera-devel", "v2", "07/10" ] }