{"id":9404,"url":"https://patchwork.libcamera.org/api/patches/9404/?format=json","web_url":"https://patchwork.libcamera.org/patch/9404/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200827082038.40758-2-jacopo@jmondi.org>","date":"2020-08-27T08:20:36","name":"[libcamera-devel,1/3] libcamera: raspberrypi: dma_heaps: Add open/close","commit_ref":null,"pull_url":null,"state":"superseded","archived":true,"hash":"a8ba27273709d25699f6bc4f08e240e18e093e54","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/9404/mbox/","series":[{"id":1245,"url":"https://patchwork.libcamera.org/api/series/1245/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1245","date":"2020-08-27T08:20:35","name":"libcamera: raspberrypi: Fail early when opening dma heaps","version":1,"mbox":"https://patchwork.libcamera.org/series/1245/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9404/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9404/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 55191BF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Aug 2020 08:17:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 359A8628F7;\n\tThu, 27 Aug 2020 10:17:00 +0200 (CEST)","from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2322D60379\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Aug 2020 10:16:59 +0200 (CEST)","from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 63C36240006;\n\tThu, 27 Aug 2020 08:16:58 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org,\n\tDave Stevenson <dave.stevenson@raspberrypi.com>,\n\tNaushir Patuck <naush@raspberrypi.com>","Date":"Thu, 27 Aug 2020 10:20:36 +0200","Message-Id":"<20200827082038.40758-2-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.28.0","In-Reply-To":"<20200827082038.40758-1-jacopo@jmondi.org>","References":"<20200827082038.40758-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 1/3] libcamera: raspberrypi: dma_heaps:\n\tAdd open/close","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The dma_heaps device is opened in the class constructor, making\nit impossible (or rather ugly) to catch errors before the allocator gets\nactually used.\n\nProvide an open() and a close() method to allow users to catch errors\nearlier.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n .../pipeline/raspberrypi/dma_heaps.cpp        | 22 ++++++++++++++++---\n .../pipeline/raspberrypi/dma_heaps.h          |  2 ++\n 2 files changed, 21 insertions(+), 3 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\nindex 6769c04640f1..739f05d3d4d8 100644\n--- a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n@@ -32,20 +32,36 @@ LOG_DECLARE_CATEGORY(RPI)\n namespace RPi {\n \n DmaHeap::DmaHeap()\n+\t: dmaHeapHandle_(-1)\n+{\n+}\n+\n+DmaHeap::~DmaHeap()\n+{\n+\tclose();\n+}\n+\n+int DmaHeap::open()\n {\n \tdmaHeapHandle_ = ::open(DMA_HEAP_CMA_NAME, O_RDWR, 0);\n \tif (dmaHeapHandle_ == -1) {\n \t\tdmaHeapHandle_ = ::open(DMA_HEAP_CMA_ALT_NAME, O_RDWR, 0);\n \t\tif (dmaHeapHandle_ == -1) {\n \t\t\tLOG(RPI, Error) << \"Could not open dmaHeap device\";\n+\t\t\treturn dmaHeapHandle_;\n \t\t}\n \t}\n+\n+\treturn 0;\n }\n \n-DmaHeap::~DmaHeap()\n+void DmaHeap::close()\n {\n-\tif (dmaHeapHandle_)\n-\t\t::close(dmaHeapHandle_);\n+\tif (dmaHeapHandle_ < 0)\n+\t\treturn;\n+\n+\t::close(dmaHeapHandle_);\n+\tdmaHeapHandle_ = -1;\n }\n \n FileDescriptor DmaHeap::alloc(const char *name, std::size_t size)\ndiff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.h b/src/libcamera/pipeline/raspberrypi/dma_heaps.h\nindex ae6be1135f17..3e17993097ef 100644\n--- a/src/libcamera/pipeline/raspberrypi/dma_heaps.h\n+++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.h\n@@ -18,6 +18,8 @@ class DmaHeap\n public:\n \tDmaHeap();\n \t~DmaHeap();\n+\tint open();\n+\tvoid close();\n \tFileDescriptor alloc(const char *name, std::size_t size);\n \n private:\n","prefixes":["libcamera-devel","1/3"]}