{"id":11897,"url":"https://patchwork.libcamera.org/api/patches/11897/?format=json","web_url":"https://patchwork.libcamera.org/patch/11897/","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":"<20210413061925.3054927-2-hiroh@chromium.org>","date":"2021-04-13T06:19:24","name":"[libcamera-devel,2/3] libcamera: V4L2Device: Use std::vector for v4l2_ext_control in setControls()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"67e27dd6d5317473d4f17a810fe693c60d14e60a","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11897/mbox/","series":[{"id":1915,"url":"https://patchwork.libcamera.org/api/series/1915/?format=json","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/11897/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11897/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 BFAB1BD224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 13 Apr 2021 06:19:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7985A68805;\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 F1A4F605AE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 08:19:34 +0200 (CEST)","by mail-pj1-x1035.google.com with SMTP id cu16so5920025pjb.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Apr 2021 23:19:34 -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.32\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 12 Apr 2021 23:19:32 -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=\"GtG7BlvA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=Ox+C7Af69yIOx2a+58sLdnlGiHUk+GH4jLb5Jk/KAYI=;\n\tb=GtG7BlvASClndtlgXEPc4ucS1Wi/A2uaDWInLDLgcmcDqer0kIaYN3pvb+q17XRr/j\n\ts+tsN9qwQFFYQub7elWukqPkfCC4bUp6GJDRtnAr58w2ffQ98XLhBdq/VhOUb5JcAk4m\n\tUETZl6+wDKuHZbqTj7k0r2lxOeyErXuwp3trg=","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:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=Ox+C7Af69yIOx2a+58sLdnlGiHUk+GH4jLb5Jk/KAYI=;\n\tb=dRA696e4lCrYZA7psSW0AYMMSyhM/IKoLq9Cpih8hBxg2A1ulMSMUjrTysXPoEaikL\n\tFco2DaKVLoSMAsE72d6US7tJDv/BAgfilpbEftOiZ2RbJ4KeIyd42va8qXHIBG1Nnd1t\n\tZhqRHi+dHLK7cuW1sGUaDSPQsOzoF15iZVf0yIsCV0UToDNWJU8GO6+juEeDddJQTLKK\n\tu04ReyzP6XJVnYzO7AunQ6NLhIWGeEc5AnLrNRL1IvlZ8yJQUx1O0wQGQR8ZySuenP8u\n\tJ6a4fd9kEvLiBiyB8QcjkDl1cmF5VtvM/4j0TOJ2ZcDBjyABVTQ8AhFhjhstZFkCcTe3\n\tFh/w==","X-Gm-Message-State":"AOAM533sdSpTvM3LtR9BmPkCmb6/8t9GhaOGN7ztePlbTO0oNWfbzgnn\n\tBa4Sxmf9nLn7WSM/9UOIoewaX6NP/6BQYQ==","X-Google-Smtp-Source":"ABdhPJy6ef7aLY7cGsGPiXsA7eZpUH2Q8GEoh+zKbOzN4SPhiFy76kKrOajnNZG3vrNifz2bSlQ9eA==","X-Received":"by 2002:a17:902:708b:b029:e6:77ca:3cb6 with SMTP id\n\tz11-20020a170902708bb02900e677ca3cb6mr30759437plk.84.1618294773434; \n\tMon, 12 Apr 2021 23:19:33 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 13 Apr 2021 15:19:24 +0900","Message-Id":"<20210413061925.3054927-2-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.1.295.g9ea45b61b8-goog","In-Reply-To":"<20210413061925.3054927-1-hiroh@chromium.org>","References":"<20210413061925.3054927-1-hiroh@chromium.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 2/3] libcamera: V4L2Device: Use\n\tstd::vector for v4l2_ext_control in setControls()","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---\n src/libcamera/v4l2_device.cpp | 18 +++++++++---------\n 1 file changed, 9 insertions(+), 9 deletions(-)","diff":"diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 78c289c2..8625dde8 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -280,12 +280,11 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n  */\n int V4L2Device::setControls(ControlList *ctrls)\n {\n-\tunsigned int count = ctrls->size();\n-\tif (count == 0)\n+\tif (ctrls->empty())\n \t\treturn 0;\n \n-\tstruct v4l2_ext_control v4l2Ctrls[count];\n-\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n+\tstd::vector<v4l2_ext_control> v4l2Ctrls(ctrls->size());\n+\tmemset(v4l2Ctrls.data(), 0, v4l2Ctrls.size());\n \n \tunsigned int i = 0;\n \tfor (auto &ctrl : *ctrls) {\n@@ -332,15 +331,15 @@ int V4L2Device::setControls(ControlList *ctrls)\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_S_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 set controls: \"\n \t\t\t\t\t << strerror(-ret);\n \t\t\treturn -EINVAL;\n@@ -349,11 +348,12 @@ int V4L2Device::setControls(ControlList *ctrls)\n \t\t/* A specific control failed. */\n \t\tLOG(V4L2, Error) << \"Unable to set control \" << errorIdx\n \t\t\t\t << \": \" << strerror(-ret);\n-\t\tcount = errorIdx - 1;\n+\n+\t\tv4l2Ctrls.resize(errorIdx);\n \t\tret = errorIdx;\n \t}\n \n-\tupdateControls(ctrls, v4l2Ctrls, count);\n+\tupdateControls(ctrls, v4l2Ctrls.data(), v4l2Ctrls.size());\n \n \treturn ret;\n }\n","prefixes":["libcamera-devel","2/3"]}