Patch Detail
Show a patch.
GET /api/1.1/patches/14830/?format=api
{ "id": 14830, "url": "https://patchwork.libcamera.org/api/1.1/patches/14830/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14830/", "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": "<20211128235752.10836-16-laurent.pinchart@ideasonboard.com>", "date": "2021-11-28T23:57:50", "name": "[libcamera-devel,v3,15/17] 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/14830/mbox/", "series": [ { "id": 2768, "url": "https://patchwork.libcamera.org/api/1.1/series/2768/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2768", "date": "2021-11-28T23:57:35", "name": "libcamera: Introduce UniqueFD", "version": 3, "mbox": "https://patchwork.libcamera.org/series/2768/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14830/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14830/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 A93CAC3251\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 28 Nov 2021 23:58:40 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5B2EF605A4;\n\tMon, 29 Nov 2021 00:58:40 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EDBE7605B8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Nov 2021 00:58:27 +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 75665730;\n\tMon, 29 Nov 2021 00:58:27 +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=\"OsQxKElj\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638143907;\n\tbh=b+y7AsF0MkaD6dEeLwtDX93/y3Khi4cycGRl3WPGJhU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=OsQxKEljP4FdwcSqjgxd9/Xxxw+gJm8gsQd31YVkw16d9sLcIDrPinsplOqqncH/X\n\tAVIM/MgcdXrbtiZ8mBQh45sOXtas9vnJ1djnpKgQDnS1ms/VulHeb1782dw+RY+hoD\n\ttlniMlPE9iimtmUIMDqK3JdGFwEypbpYgrYhqJ/8=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 29 Nov 2021 01:57:50 +0200", "Message-Id": "<20211128235752.10836-16-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20211128235752.10836-1-laurent.pinchart@ideasonboard.com>", "References": "<20211128235752.10836-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 15/17] 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>\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 7526edf774a2..ffa51a0c65ca 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1361,10 +1361,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", "v3", "15/17" ] }