Show a patch.

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

{
    "id": 17016,
    "url": "https://patchwork.libcamera.org/api/patches/17016/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17016/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20220807180100.396-3-laurent.pinchart@ideasonboard.com>",
    "date": "2022-08-07T18:00:59",
    "name": "[libcamera-devel,2/3] cam: kms_sink: Make lifetime management of DRM request safer",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "ed682c21ac7d2533a3870d2415165697e471bec8",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17016/mbox/",
    "series": [
        {
            "id": 3384,
            "url": "https://patchwork.libcamera.org/api/series/3384/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3384",
            "date": "2022-08-07T18:00:57",
            "name": "cam: Support KMS scaling",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3384/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17016/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17016/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 BF2D4C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  7 Aug 2022 18:01:15 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 17F7D63332;\n\tSun,  7 Aug 2022 20:01:15 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CFC16332E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  7 Aug 2022 20:01:13 +0200 (CEST)",
            "from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A01C69DA;\n\tSun,  7 Aug 2022 20:01:12 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659895275;\n\tbh=wYfz9+aPgxCtDCWKhZd5OrCfMyu7hutN/qxqf3+DEpU=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=VRjVUOlcIjhi4k5rM4HcSlp/uKuHVMpUzYrPrzAwjPSglhKsGSFL46OrTZ4ZAhFah\n\tO79wytaCbWSG1I3xCKeTBj59GeeHm/n6DrV0oa1FKo2VXq0CX1CAtCkuetpNK3Rp09\n\tddwC5siT5J+3l+WAolCstO11zh8c9enlVgrVq2y3TZwWBWM8k4Q1TcoYJVVXSLkGRA\n\tsQ1wApLE5sl+WgYpAEkTtyUD6fXfuuximGDvCultqWyuHdebzT8eeF+/pH6HG/b1E8\n\tBir7OrE5RslbCnIZyeCOxzZVGzAJ4eGFbhOLwoonD26EP7fosAAmARxmPY1p4ma8xX\n\t/Zlrb2PqZsEEA==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659895272;\n\tbh=wYfz9+aPgxCtDCWKhZd5OrCfMyu7hutN/qxqf3+DEpU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=eVY9UIaRCeDRCabs6v5/kwwtGFVygPHDVjzEWAfP9EYzdUhd/8Ju7U/nI8C39Xntz\n\tJSjP95721ly7A0xmv2Jxs4piEfys+pNcKaMHTqL1SZBzNbF4E7CRff+hGV0jBLexm4\n\toD3CTGtW1QlfCcGYnKGohVenV6eqkS1LPlk13uEE="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"eVY9UIaR\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sun,  7 Aug 2022 21:00:59 +0300",
        "Message-Id": "<20220807180100.396-3-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20220807180100.396-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20220807180100.396-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 2/3] cam: kms_sink: Make lifetime\n\tmanagement of DRM request safer",
        "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>",
        "From": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The drmRequest is KMSSink::processRequest() is created as a naked\npointer, passed to the constructor of the KMSSink::Request object that\nstores it in a std::unique_ptr<>, and used later in the function. The\ncurrent implementation is safe, but could be prone to both memory leaks\nand use-after-free bugs if modified. Improve it by replacing the naked\npointer with a std::unique_ptr<>.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/cam/kms_sink.cpp | 7 ++++---\n src/cam/kms_sink.h   | 5 +++--\n 2 files changed, 7 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/src/cam/kms_sink.cpp b/src/cam/kms_sink.cpp\nindex 37a3bd50a2bf..16435ede6b6a 100644\n--- a/src/cam/kms_sink.cpp\n+++ b/src/cam/kms_sink.cpp\n@@ -301,7 +301,8 @@ bool KMSSink::processRequest(libcamera::Request *camRequest)\n \tDRM::FrameBuffer *drmBuffer = iter->second.get();\n \n \tunsigned int flags = DRM::AtomicRequest::FlagAsync;\n-\tDRM::AtomicRequest *drmRequest = new DRM::AtomicRequest(&dev_);\n+\tstd::unique_ptr<DRM::AtomicRequest> drmRequest =\n+\t\tstd::make_unique<DRM::AtomicRequest>(&dev_);\n \tdrmRequest->addProperty(plane_, \"FB_ID\", drmBuffer->id());\n \n \tif (!active_ && !queued_) {\n@@ -324,12 +325,12 @@ bool KMSSink::processRequest(libcamera::Request *camRequest)\n \t\tflags |= DRM::AtomicRequest::FlagAllowModeset;\n \t}\n \n-\tpending_ = std::make_unique<Request>(drmRequest, camRequest);\n+\tpending_ = std::make_unique<Request>(std::move(drmRequest), camRequest);\n \n \tstd::lock_guard<std::mutex> lock(lock_);\n \n \tif (!queued_) {\n-\t\tint ret = drmRequest->commit(flags);\n+\t\tint ret = pending_->drmRequest_->commit(flags);\n \t\tif (ret < 0) {\n \t\t\tstd::cerr\n \t\t\t\t<< \"Failed to commit atomic request: \"\ndiff --git a/src/cam/kms_sink.h b/src/cam/kms_sink.h\nindex 4a0a872cb653..8f5f08667cea 100644\n--- a/src/cam/kms_sink.h\n+++ b/src/cam/kms_sink.h\n@@ -38,8 +38,9 @@ private:\n \tclass Request\n \t{\n \tpublic:\n-\t\tRequest(DRM::AtomicRequest *drmRequest, libcamera::Request *camRequest)\n-\t\t\t: drmRequest_(drmRequest), camRequest_(camRequest)\n+\t\tRequest(std::unique_ptr<DRM::AtomicRequest> drmRequest,\n+\t\t\tlibcamera::Request *camRequest)\n+\t\t\t: drmRequest_(std::move(drmRequest)), camRequest_(camRequest)\n \t\t{\n \t\t}\n \n",
    "prefixes": [
        "libcamera-devel",
        "2/3"
    ]
}