Show a patch.

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

{
    "id": 13691,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13691/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13691/",
    "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": "<20210906225636.14683-25-laurent.pinchart@ideasonboard.com>",
    "date": "2021-09-06T22:56:31",
    "name": "[libcamera-devel,v3,25/30] cam: drm: Avoid importing the same dmabuf multiple times",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "7e9a28068d3651aaf804b659f527fc86e15d7c16",
    "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/13691/mbox/",
    "series": [
        {
            "id": 2482,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2482/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2482",
            "date": "2021-09-06T22:54:20",
            "name": "libcamera: Handle fallout of FrameBuffer offset support",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/2482/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13691/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13691/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 75252BE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Sep 2021 22:57:49 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3401C6917E;\n\tTue,  7 Sep 2021 00:57:49 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E9F6A69167\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 00:57:08 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 87204891;\n\tTue,  7 Sep 2021 00:57:08 +0200 (CEST)"
        ],
        "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=\"PrNYx+b9\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630969028;\n\tbh=KGEkV/+jB/Kl24eWKUk1fHAkY97gdEaD0mhGkRoNyns=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=PrNYx+b94uUkhwggRNpMu9xf4GB7ZRgpzSdw/V2WQBtI9BLUzR7VYkmG1Z4Uet6AT\n\txNuQ24AmVGnVJ2QdtgWSYaWpiFp8Au0DYkVB7L3Hh8g0vjRW1DVtHBhBB0iOG9K7n5\n\tIEd3H1qVmkTbXlLo5xE+vZxOAaREV+K5DjK2GfWs=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue,  7 Sep 2021 01:56:31 +0300",
        "Message-Id": "<20210906225636.14683-25-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 25/30] cam: drm: Avoid importing the\n\tsame dmabuf multiple times",
        "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": "When creating a DRM frame buffer, the dmabufs for the planes are\nimported as GEM objects. For multi-planar formats, all planes may use\nthe same dmabuf, which results in multiple imports. This doesn't cause\nany issue at import time, as DRM detects this situation and returns the\nsame GEM object. However, when destroying the frame buffer, the same GEM\nobject ends up being closed multiple times, which generates an error.\n\nFix this by avoiding multiple imports of the same dmabuf for the same\nframe buffer. While the issue may theoretically occur with identical\ndmabufs for different frame buffers, this is quite unlikely and is thus\nnot addressed.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n---\n src/cam/drm.cpp | 29 +++++++++++++++++------------\n src/cam/drm.h   |  2 +-\n 2 files changed, 18 insertions(+), 13 deletions(-)",
    "diff": "diff --git a/src/cam/drm.cpp b/src/cam/drm.cpp\nindex d5a75d039fd8..f25300913a7f 100644\n--- a/src/cam/drm.cpp\n+++ b/src/cam/drm.cpp\n@@ -283,9 +283,9 @@ FrameBuffer::FrameBuffer(Device *dev)\n \n FrameBuffer::~FrameBuffer()\n {\n-\tfor (FrameBuffer::Plane &plane : planes_) {\n+\tfor (const auto &plane : planes_) {\n \t\tstruct drm_gem_close gem_close = {\n-\t\t\t.handle = plane.handle,\n+\t\t\t.handle = plane.second.handle,\n \t\t\t.pad = 0,\n \t\t};\n \t\tint ret;\n@@ -605,22 +605,27 @@ std::unique_ptr<FrameBuffer> Device::createFrameBuffer(\n \tint ret;\n \n \tconst std::vector<libcamera::FrameBuffer::Plane> &planes = buffer.planes();\n-\tfb->planes_.reserve(planes.size());\n \n \tunsigned int i = 0;\n \tfor (const libcamera::FrameBuffer::Plane &plane : planes) {\n+\t\tint fd = plane.fd.fd();\n \t\tuint32_t handle;\n \n-\t\tret = drmPrimeFDToHandle(fd_, plane.fd.fd(), &handle);\n-\t\tif (ret < 0) {\n-\t\t\tret = -errno;\n-\t\t\tstd::cerr\n-\t\t\t\t<< \"Unable to import framebuffer dmabuf: \"\n-\t\t\t\t<< strerror(-ret) << std::endl;\n-\t\t\treturn nullptr;\n-\t\t}\n+\t\tauto iter = fb->planes_.find(fd);\n+\t\tif (iter == fb->planes_.end()) {\n+\t\t\tret = drmPrimeFDToHandle(fd_, plane.fd.fd(), &handle);\n+\t\t\tif (ret < 0) {\n+\t\t\t\tret = -errno;\n+\t\t\t\tstd::cerr\n+\t\t\t\t\t<< \"Unable to import framebuffer dmabuf: \"\n+\t\t\t\t\t<< strerror(-ret) << std::endl;\n+\t\t\t\treturn nullptr;\n+\t\t\t}\n \n-\t\tfb->planes_.push_back({ handle });\n+\t\t\tfb->planes_[fd] = { handle };\n+\t\t} else {\n+\t\t\thandle = iter->second.handle;\n+\t\t}\n \n \t\thandles[i] = handle;\n \t\toffsets[i] = plane.offset;\ndiff --git a/src/cam/drm.h b/src/cam/drm.h\nindex 00f7e798b771..0b88f9a33912 100644\n--- a/src/cam/drm.h\n+++ b/src/cam/drm.h\n@@ -242,7 +242,7 @@ private:\n \n \tFrameBuffer(Device *dev);\n \n-\tstd::vector<Plane> planes_;\n+\tstd::map<int, Plane> planes_;\n };\n \n class AtomicRequest\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "25/30"
    ]
}