Patch Detail
Show a patch.
GET /api/1.1/patches/11896/?format=api
{ "id": 11896, "url": "https://patchwork.libcamera.org/api/1.1/patches/11896/?format=api", "web_url": "https://patchwork.libcamera.org/patch/11896/", "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": "<20210413061925.3054927-1-hiroh@chromium.org>", "date": "2021-04-13T06:19:23", "name": "[libcamera-devel,1/3] libcamera: V4L2Device: Use std::vector for v4l2_ext_control in getControls()", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "378e835640f9d31b6bb69c265fc56e53803b81e3", "submitter": { "id": 63, "url": "https://patchwork.libcamera.org/api/1.1/people/63/?format=api", "name": "Hirokazu Honda", "email": "hiroh@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/11896/mbox/", "series": [ { "id": 1915, "url": "https://patchwork.libcamera.org/api/1.1/series/1915/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1915", "date": "2021-04-13T06:19:23", "name": "[libcamera-devel,1/3] libcamera: V4L2Device: Use std::vector for v4l2_ext_control in getControls()", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1915/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/11896/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/11896/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 A5E1FBD224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 13 Apr 2021 06:19:36 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1AEFF687F3;\n\tTue, 13 Apr 2021 08:19:36 +0200 (CEST)", "from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com\n\t[IPv6:2607:f8b0:4864:20::1035])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DF5A0605AE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 08:19:33 +0200 (CEST)", "by mail-pj1-x1035.google.com with SMTP id i4so7924957pjk.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Apr 2021 23:19:33 -0700 (PDT)", "from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:84f5:7981:dfbe:8f02])\n\tby smtp.gmail.com with ESMTPSA id\n\tn4sm11666063pfu.45.2021.04.12.23.19.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 12 Apr 2021 23:19:31 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"jNgQRpoF\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; h=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=Q1hC5n4D2ruo8tDDXvz3jBM31g3+DuH4sNeW+LjMqkY=;\n\tb=jNgQRpoF7FWgfOf+HbNqMdgzfcdpO1kElBtMSEWqrtQz9aGZ0WbXCIFS8cxENQI5IA\n\tmPBJpSPYfCoq6bRhMjZGmmkkT8NTdpVW44kifvLKJMXDCWoMwvs5JhVKbH5pTk2Dv0Sz\n\tfMGtOLxKPhbDJSv5WMsDvIMzp23+B8ayBJ0Js=", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=Q1hC5n4D2ruo8tDDXvz3jBM31g3+DuH4sNeW+LjMqkY=;\n\tb=HdVmr1LfKCmA+HQDszV+xrGZFZUhRABXtZWsZreEB1N/Fj72GZBxDuRqsHNQqqF59N\n\tRUzctILscwengB+/RwMN5hup6oItyS43uDfL22ylacic+WqhNThiRE2frqYBktkS14pv\n\tqknn1dhYug1dtFf2/+melem4KyPdrfB9f99v40EY7Ba1yQO7CWQL7LANBc8EhiLDKGqO\n\toX9ruNRUeruxCKr+otqQwokfJBAcP+6c+AXJhaJsY0W2g4at8aFN15R0mP/G2M8y3/Qp\n\tnyE7C1SutpNdUn3EOb04JI4Me4RDHF+Y+pvSlneouLtl/5Lx4aOOppmNmlvR+zK9h5ad\n\tT8bQ==", "X-Gm-Message-State": "AOAM530DMXwZ72+M4Da+PsZNZhB/C+lbc/CFDmk0TM+QryHwHpXCf/QT\n\t3fadoNTmwiervgZ1hmjl4YJLdbhPS3obTw==", "X-Google-Smtp-Source": "ABdhPJwzumDc5JDpYF58fPRm4dfKdLuyTRLnX4RqbxhH4FAqFevZlTOjai3qyjTEVe72/HFw+6jWyw==", "X-Received": "by 2002:a17:90b:300c:: with SMTP id\n\thg12mr3027914pjb.165.1618294771934; \n\tMon, 12 Apr 2021 23:19:31 -0700 (PDT)", "From": "Hirokazu Honda <hiroh@chromium.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 13 Apr 2021 15:19:23 +0900", "Message-Id": "<20210413061925.3054927-1-hiroh@chromium.org>", "X-Mailer": "git-send-email 2.31.1.295.g9ea45b61b8-goog", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH 1/3] libcamera: V4L2Device: Use\n\tstd::vector for v4l2_ext_control in getControls()", "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 original code uses Variable-Length-Array, which is not\nofficially supported in C++. This replaces the array with\nstd::vector.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/libcamera/v4l2_device.cpp | 44 +++++++++++++++++------------------\n 1 file changed, 21 insertions(+), 23 deletions(-)", "diff": "diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex decd19ef..78c289c2 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -173,8 +173,7 @@ void V4L2Device::close()\n */\n ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n {\n-\tunsigned int count = ids.size();\n-\tif (count == 0)\n+\tif (ids.empty())\n \t\treturn {};\n \n \tControlList ctrls{ controls_ };\n@@ -196,21 +195,26 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\tctrls.set(id, {});\n \t}\n \n-\tstruct v4l2_ext_control v4l2Ctrls[count];\n-\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n-\n-\tunsigned int i = 0;\n+\tstd::vector<v4l2_ext_control> v4l2Ctrls;\n+\tv4l2Ctrls.reserve(ctrls.size());\n \tfor (auto &ctrl : ctrls) {\n \t\tunsigned int id = ctrl.first;\n \t\tconst struct v4l2_query_ext_ctrl &info = controlInfo_[id];\n+\t\tv4l2_ext_control v4l2Ctrl;\n+\t\tmemset(&v4l2Ctrl, 0, sizeof(v4l2Ctrl));\n \n \t\tif (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) {\n-\t\t\tControlType type;\n-\n \t\t\tswitch (info.type) {\n-\t\t\tcase V4L2_CTRL_TYPE_U8:\n+\t\t\tcase V4L2_CTRL_TYPE_U8: {\n+\t\t\t\tControlType type;\n \t\t\t\ttype = ControlTypeByte;\n+\t\t\t\tControlValue &value = ctrl.second;\n+\t\t\t\tvalue.reserve(type, true, info.elems);\n+\t\t\t\tSpan<uint8_t> data = value.data();\n+\t\t\t\tv4l2Ctrl.p_u8 = data.data();\n+\t\t\t\tv4l2Ctrl.size = data.size();\n \t\t\t\tbreak;\n+\t\t\t}\n \n \t\t\tdefault:\n \t\t\t\tLOG(V4L2, Error)\n@@ -218,30 +222,23 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\t\t\t\t<< info.type;\n \t\t\t\treturn {};\n \t\t\t}\n-\n-\t\t\tControlValue &value = ctrl.second;\n-\t\t\tvalue.reserve(type, true, info.elems);\n-\t\t\tSpan<uint8_t> data = value.data();\n-\n-\t\t\tv4l2Ctrls[i].p_u8 = data.data();\n-\t\t\tv4l2Ctrls[i].size = data.size();\n \t\t}\n \n-\t\tv4l2Ctrls[i].id = id;\n-\t\ti++;\n+\t\tv4l2Ctrl.id = id;\n+\t\tv4l2Ctrls.push_back(std::move(v4l2Ctrl));\n \t}\n \n \tstruct v4l2_ext_controls v4l2ExtCtrls = {};\n \tv4l2ExtCtrls.which = V4L2_CTRL_WHICH_CUR_VAL;\n-\tv4l2ExtCtrls.controls = v4l2Ctrls;\n-\tv4l2ExtCtrls.count = count;\n+\tv4l2ExtCtrls.controls = v4l2Ctrls.data();\n+\tv4l2ExtCtrls.count = v4l2Ctrls.size();\n \n \tint ret = ioctl(VIDIOC_G_EXT_CTRLS, &v4l2ExtCtrls);\n \tif (ret) {\n \t\tunsigned int errorIdx = v4l2ExtCtrls.error_idx;\n \n \t\t/* Generic validation error. */\n-\t\tif (errorIdx == 0 || errorIdx >= count) {\n+\t\tif (errorIdx == 0 || errorIdx >= v4l2Ctrls.size()) {\n \t\t\tLOG(V4L2, Error) << \"Unable to read controls: \"\n \t\t\t\t\t << strerror(-ret);\n \t\t\treturn {};\n@@ -250,10 +247,11 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\t/* A specific control failed. */\n \t\tLOG(V4L2, Error) << \"Unable to read control \" << errorIdx\n \t\t\t\t << \": \" << strerror(-ret);\n-\t\tcount = errorIdx - 1;\n+\n+\t\tv4l2Ctrls.resize(errorIdx);\n \t}\n \n-\tupdateControls(&ctrls, v4l2Ctrls, count);\n+\tupdateControls(&ctrls, v4l2Ctrls.data(), v4l2Ctrls.size());\n \n \treturn ctrls;\n }\n", "prefixes": [ "libcamera-devel", "1/3" ] }