Show a patch.

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

{
    "id": 3439,
    "url": "https://patchwork.libcamera.org/api/patches/3439/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3439/",
    "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": "<20200413133047.11913-6-laurent.pinchart@ideasonboard.com>",
    "date": "2020-04-13T13:30:41",
    "name": "[libcamera-devel,v2,05/11] libcamera: ipa_module: Simplify error handling in loadIPAModuleInfo()",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "d4755a3a338f039f26559c33e98084c8507ee4af",
    "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/3439/mbox/",
    "series": [
        {
            "id": 804,
            "url": "https://patchwork.libcamera.org/api/series/804/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=804",
            "date": "2020-04-13T13:30:37",
            "name": "Sign IPA modules instead of checking their advertised license",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/804/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3439/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3439/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 66C4D62DFB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Apr 2020 15:31:06 +0200 (CEST)",
            "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0292A24B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Apr 2020 15:31:05 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"XcWeMnF1\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1586784666;\n\tbh=2V91YychmFFeYx9gcuCQcxpOTJvJzn3HRPNbrX8BeNs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=XcWeMnF1asAlhgJlhN/rLkY0N1Rn3B04lqv6BD/hGKwOq4K7tLgXDZwu9BRQ+hywU\n\tFYGBm/kLvs6qdPQDcYoAX1SxRzzs6xaNzrU/LOh4gIZIMLK15nIcJUTW/hmtOJH9jw\n\tUUVmL2cSrzwqf7KjPSADzBT3/4nrVyIJWY6keQsQ=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 13 Apr 2020 16:30:41 +0300",
        "Message-Id": "<20200413133047.11913-6-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.24.1",
        "In-Reply-To": "<20200413133047.11913-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20200413133047.11913-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 05/11] libcamera: ipa_module: Simplify\n\terror handling in loadIPAModuleInfo()",
        "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>",
        "X-List-Received-Date": "Mon, 13 Apr 2020 13:31:08 -0000"
    },
    "content": "Use the File helper class to handle cleanup of the mapped file to\nsimplify error handling in loadIPAModuleInfo().\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/ipa_module.cpp | 58 +++++++++++++-----------------------\n 1 file changed, 21 insertions(+), 37 deletions(-)",
    "diff": "diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\nindex a01d0757ff8f..d1c411e14ba9 100644\n--- a/src/libcamera/ipa_module.cpp\n+++ b/src/libcamera/ipa_module.cpp\n@@ -21,6 +21,7 @@\n #include <tuple>\n #include <unistd.h>\n \n+#include \"file.h\"\n #include \"log.h\"\n #include \"pipeline_handler.h\"\n #include \"utils.h\"\n@@ -283,55 +284,38 @@ IPAModule::~IPAModule()\n \n int IPAModule::loadIPAModuleInfo()\n {\n-\tint fd = open(libPath_.c_str(), O_RDONLY);\n-\tif (fd < 0) {\n-\t\tint ret = -errno;\n+\tFile file{ libPath_ };\n+\tif (!file.open(File::ReadOnly)) {\n \t\tLOG(IPAModule, Error) << \"Failed to open IPA library: \"\n-\t\t\t\t      << strerror(-ret);\n-\t\treturn ret;\n+\t\t\t\t      << strerror(-file.error());\n+\t\treturn file.error();\n \t}\n \n-\tvoid *data = nullptr;\n-\tsize_t dataSize;\n-\tvoid *map;\n-\tsize_t soSize;\n-\tstruct stat st;\n-\tint ret = fstat(fd, &st);\n-\tif (ret < 0)\n-\t\tgoto close;\n-\tsoSize = st.st_size;\n-\tmap = mmap(NULL, soSize, PROT_READ, MAP_PRIVATE, fd, 0);\n-\tif (map == MAP_FAILED) {\n-\t\tret = -errno;\n-\t\tgoto close;\n+\tSpan<uint8_t> data = file.map(0, -1, File::MapPrivate);\n+\tint ret = elfVerifyIdent(data.data(), data.size());\n+\tif (ret) {\n+\t\tLOG(IPAModule, Error) << \"IPA module is not an ELF file\";\n+\t\treturn ret;\n \t}\n \n-\tret = elfVerifyIdent(map, soSize);\n-\tif (ret)\n-\t\tgoto unmap;\n+\tvoid *info = nullptr;\n+\tsize_t infoSize;\n \n-\tstd::tie(data, dataSize) = elfLoadSymbol(map, soSize, \"ipaModuleInfo\");\n-\n-\tif (data && dataSize == sizeof(info_))\n-\t\tmemcpy(&info_, data, dataSize);\n+\tstd::tie(info, infoSize) = elfLoadSymbol(data.data(), data.size(),\n+\t\t\t\t\t\t \"ipaModuleInfo\");\n+\tif (!info || infoSize != sizeof(info_)) {\n+\t\tLOG(IPAModule, Error) << \"IPA module has no valid info\";\n+\t\treturn -EINVAL;\n+\t}\n \n-\tif (!data)\n-\t\tgoto unmap;\n+\tmemcpy(&info_, info, infoSize);\n \n \tif (info_.moduleAPIVersion != IPA_MODULE_API_VERSION) {\n \t\tLOG(IPAModule, Error) << \"IPA module API version mismatch\";\n-\t\tret = -EINVAL;\n+\t\treturn -EINVAL;\n \t}\n \n-unmap:\n-\tmunmap(map, soSize);\n-close:\n-\tif (ret || !data)\n-\t\tLOG(IPAModule, Error)\n-\t\t\t<< \"Error loading IPA module info for \" << libPath_;\n-\n-\tclose(fd);\n-\treturn ret;\n+\treturn 0;\n }\n \n /**\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "05/11"
    ]
}