Show a patch.

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

{
    "id": 14884,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/14884/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/14884/",
    "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": "<20211130102800.1890-1-laurent.pinchart@ideasonboard.com>",
    "date": "2021-11-30T10:28:00",
    "name": "[libcamera-devel,v4.1,17/22] libcamera: pipeline: raspberrypi: DmaHeaps: Use UniqueFD for a file descriptor",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "77034068bba7bc8243a6b9233e0c7bf51dfcf5a6",
    "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/14884/mbox/",
    "series": [
        {
            "id": 2781,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2781/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2781",
            "date": "2021-11-30T10:27:16",
            "name": null,
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2781/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/14884/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/14884/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 3A57DBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 10:28:31 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E0DFF605B7;\n\tTue, 30 Nov 2021 11:28:30 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B0E9860230\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 11:28:28 +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 35A8C2A5;\n\tTue, 30 Nov 2021 11:28:28 +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=\"CR5ufbP8\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638268108;\n\tbh=TJr9NP2Hv2sWMikq7JSU+FWFnD6guP2OPe4BulB5KvA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=CR5ufbP8KEfo7qtC0YoGidf5vhG3w5rZXgnLXRDvEWmej3yAIhd9ayXi+ZQkMJSZv\n\tm7ywhW6/+GOo11p4KGAAeUi1ZZ4DLFxFCOoOXITJIKdDNphDQ8BEnkk/D3IiNN7loK\n\tLhIX3oPh98tT2LpBLU8gWcSyTUeK75qdNnA5GxLc=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 30 Nov 2021 12:28:00 +0200",
        "Message-Id": "<20211130102800.1890-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20211130033820.18235-18-laurent.pinchart@ideasonboard.com>",
        "References": "<20211130033820.18235-18-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4.1 17/22] libcamera: pipeline:\n\traspberrypi: DmaHeaps: Use UniqueFD 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 DmaHeaps for a dma handle by\nUniqueFD. Furthermore, DmaHeaps::alloc() creates a new file\ndescriptor and the returned file descriptor is owned by a caller.\nThis also clarifies it by changing the returned value to 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 v4:\n\n- Drop unneeded local variable in configureIPA()\n\nChanges since v2:\n\n- Use default destructor\n- Return {}\n---\n .../pipeline/raspberrypi/dma_heaps.cpp        | 28 ++++++++-----------\n .../pipeline/raspberrypi/dma_heaps.h          | 10 ++++---\n .../pipeline/raspberrypi/raspberrypi.cpp      |  2 +-\n 3 files changed, 18 insertions(+), 22 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\nindex 573ea11de607..69831dabbe75 100644\n--- a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n@@ -35,7 +35,6 @@ LOG_DECLARE_CATEGORY(RPI)\n namespace RPi {\n \n DmaHeap::DmaHeap()\n-\t: dmaHeapHandle_(-1)\n {\n \tfor (const char *name : heapNames) {\n \t\tint ret = ::open(name, O_RDWR, 0);\n@@ -46,49 +45,44 @@ DmaHeap::DmaHeap()\n \t\t\tcontinue;\n \t\t}\n \n-\t\tdmaHeapHandle_ = ret;\n+\t\tdmaHeapHandle_ = UniqueFD(ret);\n \t\tbreak;\n \t}\n \n-\tif (dmaHeapHandle_ < 0)\n+\tif (!dmaHeapHandle_.isValid())\n \t\tLOG(RPI, Error) << \"Could not open any dmaHeap device\";\n }\n \n-DmaHeap::~DmaHeap()\n-{\n-\tif (dmaHeapHandle_ > -1)\n-\t\t::close(dmaHeapHandle_);\n-}\n+DmaHeap::~DmaHeap() = default;\n \n-FileDescriptor DmaHeap::alloc(const char *name, std::size_t size)\n+UniqueFD DmaHeap::alloc(const char *name, std::size_t size)\n {\n \tint ret;\n \n \tif (!name)\n-\t\treturn FileDescriptor();\n+\t\treturn {};\n \n \tstruct dma_heap_allocation_data alloc = {};\n \n \talloc.len = size;\n \talloc.fd_flags = O_CLOEXEC | O_RDWR;\n \n-\tret = ::ioctl(dmaHeapHandle_, DMA_HEAP_IOCTL_ALLOC, &alloc);\n-\n+\tret = ::ioctl(dmaHeapHandle_.get(), DMA_HEAP_IOCTL_ALLOC, &alloc);\n \tif (ret < 0) {\n \t\tLOG(RPI, Error) << \"dmaHeap allocation failure for \"\n \t\t\t\t<< name;\n-\t\treturn FileDescriptor();\n+\t\treturn {};\n \t}\n \n-\tret = ::ioctl(alloc.fd, DMA_BUF_SET_NAME, name);\n+\tUniqueFD allocFd(alloc.fd);\n+\tret = ::ioctl(allocFd.get(), DMA_BUF_SET_NAME, name);\n \tif (ret < 0) {\n \t\tLOG(RPI, Error) << \"dmaHeap naming failure for \"\n \t\t\t\t<< name;\n-\t\t::close(alloc.fd);\n-\t\treturn FileDescriptor();\n+\t\treturn {};\n \t}\n \n-\treturn FileDescriptor(std::move(alloc.fd));\n+\treturn allocFd;\n }\n \n } /* namespace RPi */\ndiff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.h b/src/libcamera/pipeline/raspberrypi/dma_heaps.h\nindex 57beaeb2e48a..d38f41eae1a2 100644\n--- a/src/libcamera/pipeline/raspberrypi/dma_heaps.h\n+++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.h\n@@ -7,7 +7,9 @@\n \n #pragma once\n \n-#include <libcamera/base/file_descriptor.h>\n+#include <stddef.h>\n+\n+#include <libcamera/base/unique_fd.h>\n \n namespace libcamera {\n \n@@ -18,11 +20,11 @@ class DmaHeap\n public:\n \tDmaHeap();\n \t~DmaHeap();\n-\tbool isValid() const { return dmaHeapHandle_ > -1; }\n-\tFileDescriptor alloc(const char *name, std::size_t size);\n+\tbool isValid() const { return dmaHeapHandle_.isValid(); }\n+\tUniqueFD alloc(const char *name, std::size_t size);\n \n private:\n-\tint dmaHeapHandle_;\n+\tUniqueFD dmaHeapHandle_;\n };\n \n } /* namespace RPi */\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex d82cb30f0e77..e2af1fb80200 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1382,7 +1382,7 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n \n \t/* Allocate the lens shading table via dmaHeap and pass to the IPA. */\n \tif (!lsTable_.isValid()) {\n-\t\tlsTable_ = dmaHeap_.alloc(\"ls_grid\", ipa::RPi::MaxLsGridSize);\n+\t\tlsTable_ = FileDescriptor(dmaHeap_.alloc(\"ls_grid\", ipa::RPi::MaxLsGridSize));\n \t\tif (!lsTable_.isValid())\n \t\t\treturn -ENOMEM;\n \n",
    "prefixes": [
        "libcamera-devel",
        "v4.1",
        "17/22"
    ]
}