Patch Detail
Show a patch.
GET /api/1.1/patches/14872/?format=api
{ "id": 14872, "url": "https://patchwork.libcamera.org/api/1.1/patches/14872/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14872/", "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-18-laurent.pinchart@ideasonboard.com>", "date": "2021-11-30T03:38:15", "name": "[libcamera-devel,v4,17/22] libcamera: pipeline: raspberrypi: DmaHeaps: Use UniqueFD for a file descriptor", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "0fb7e6d20d3973876b284d2e0645eb3bfa0c52b0", "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/14872/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/14872/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14872/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 F07E2C3250\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 03:39:13 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A907F60720;\n\tTue, 30 Nov 2021 04:39:13 +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 8B69F605B6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 04:38:56 +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 1A7368F0;\n\tTue, 30 Nov 2021 04:38:56 +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=\"XtFNoVUW\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638243536;\n\tbh=3BX2MS1kaMxk0kaqPaIUH/ZPZT0B3qL5SJ2IEKDbyws=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=XtFNoVUWGZ3DmllPfsFeM+XBBBmyky4izkI+p6R4+yuNUu5wdpES/BMxbQS2lsv21\n\thZxYhkhIvNJwNC8qnbK5pf3xS8fVf7YbI0X/tvtx6L6pmymM/shjH86OanmBGJz8U9\n\tOWkzVWX94uXPk10jevMLs6GhpD3Us2Ls2YGpI0GI=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 30 Nov 2021 05:38:15 +0200", "Message-Id": "<20211130033820.18235-18-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 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>\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 | 6 ++--\n 3 files changed, 21 insertions(+), 23 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..d4f248a799e5 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1382,10 +1382,12 @@ 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\tif (!lsTable_.isValid())\n+\t\tUniqueFD fd = dmaHeap_.alloc(\"ls_grid\", ipa::RPi::MaxLsGridSize);\n+\t\tif (!fd.isValid())\n \t\t\treturn -ENOMEM;\n \n+\t\tlsTable_ = FileDescriptor(std::move(fd));\n+\n \t\t/* Allow the IPA to mmap the LS table via the file descriptor. */\n \t\t/*\n \t\t * \\todo Investigate if mapping the lens shading table buffer\n", "prefixes": [ "libcamera-devel", "v4", "17/22" ] }