{"id":26321,"url":"https://patchwork.libcamera.org/api/1.1/patches/26321/?format=json","web_url":"https://patchwork.libcamera.org/patch/26321/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20260324123214.1762198-1-barnabas.pocze@ideasonboard.com>","date":"2026-03-24T12:32:13","name":"[v1,1/2] libcamera: v4l2_device: setControls(): Do not return index","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"d97903ba2b77b13fb2d569a261da1faee2193dc1","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/1.1/people/216/?format=json","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26321/mbox/","series":[{"id":5841,"url":"https://patchwork.libcamera.org/api/1.1/series/5841/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5841","date":"2026-03-24T12:32:13","name":"[v1,1/2] libcamera: v4l2_device: setControls(): Do not return index","version":1,"mbox":"https://patchwork.libcamera.org/series/5841/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26321/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26321/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 69288BE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 24 Mar 2026 12:32:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EBC4C62784;\n\tTue, 24 Mar 2026 13:32:19 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2BDD0622AD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Mar 2026 13:32:18 +0100 (CET)","from pb-laptop.local (185.221.143.129.nat.pool.zt.hu\n\t[185.221.143.129])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C4994225\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Mar 2026 13:31:00 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"OFARsvtD\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1774355460;\n\tbh=u9MtYestEjUN5b0tDlOfSTHp37URP6Ygarwmakksb5g=;\n\th=From:To:Subject:Date:From;\n\tb=OFARsvtDYA0D0ytRyGp853v/7puzeCO1AHuLwa+PiMFYILVPKN+5RxeLfz6AHN8Ye\n\tUcSR7593q+jdw6nNP3sHvfLPaqOR8FLjilRyfSEXcezVJwx/s9t9lNsmi0OKKZqFHk\n\t8uJen98GTent8wnE94C2u65Dvbiopf3JtYZ1zcaM=","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v1 1/2] libcamera: v4l2_device: setControls(): Do not return\n\tindex","Date":"Tue, 24 Mar 2026 13:32:13 +0100","Message-ID":"<20260324123214.1762198-1-barnabas.pocze@ideasonboard.com>","X-Mailer":"git-send-email 2.53.0","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","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":"This behaviour should be removed for the following reasons:\n\n  * a `ControlList` is an unordered container, an index is largely meaningless;\n  * most callers either ignore the return value, or blindly return it, likely\n    contradicting their own documentation (e.g. `CameraSensorLegacy::setFormat()`),\n    and the error is already very visibly logged;\n  * an error index of 0 is indistinguishable from success with this approach.\n\nInstead, return `-EIO` instead of the index.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n Documentation/guides/pipeline-handler.rst    |  6 ++----\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp |  2 +-\n src/libcamera/pipeline/vimc/vimc.cpp         |  2 +-\n src/libcamera/sensor/camera_sensor.cpp       | 15 +--------------\n src/libcamera/v4l2_device.cpp                | 14 ++++++--------\n 5 files changed, 11 insertions(+), 28 deletions(-)","diff":"diff --git a/Documentation/guides/pipeline-handler.rst b/Documentation/guides/pipeline-handler.rst\nindex 083cdb745..b33d8b857 100644\n--- a/Documentation/guides/pipeline-handler.rst\n+++ b/Documentation/guides/pipeline-handler.rst\n@@ -1076,7 +1076,7 @@ device:\n    ret = data->video_->setControls(&controls);\n    if (ret) {\n           LOG(VIVID, Error) << \"Failed to set controls: \" << ret;\n-          return ret < 0 ? ret : -EINVAL;\n+          return ret;\n    }\n \n These controls configure VIVID to use a default test pattern, and enable all\n@@ -1285,10 +1285,8 @@ before being set.\n                         << \" to \" << ctrl.second.toString();\n \n           int ret = data->video_->setControls(&controls);\n-          if (ret) {\n+          if (ret)\n                  LOG(VIVID, Error) << \"Failed to set controls: \" << ret;\n-                 return ret < 0 ? ret : -EINVAL;\n-          }\n \n           return ret;\n    }\ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 3bd51733d..3435a7604 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -439,7 +439,7 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, const ControlList &\n \tint ret = data->video_->setControls(&controls);\n \tif (ret) {\n \t\tLOG(UVC, Error) << \"Failed to set controls: \" << ret;\n-\t\treturn ret < 0 ? ret : -EINVAL;\n+\t\treturn ret;\n \t}\n \n \treturn ret;\ndiff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\nindex 08b100752..716f90818 100644\n--- a/src/libcamera/pipeline/vimc/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc/vimc.cpp\n@@ -434,7 +434,7 @@ int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)\n \tint ret = data->sensor_->setControls(&controls);\n \tif (ret) {\n \t\tLOG(VIMC, Error) << \"Failed to set controls: \" << ret;\n-\t\treturn ret < 0 ? ret : -EINVAL;\n+\t\treturn ret;\n \t}\n \n \treturn ret;\ndiff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp\nindex 05390d1e1..602518afc 100644\n--- a/src/libcamera/sensor/camera_sensor.cpp\n+++ b/src/libcamera/sensor/camera_sensor.cpp\n@@ -379,21 +379,8 @@ int CameraSensor::setEmbeddedDataEnabled(bool enable)\n  * ctrls entry. The control identifiers are defined by the V4L2 specification\n  * (V4L2_CID_*).\n  *\n- * If any control in \\a ctrls is not supported by the device, is disabled (i.e.\n- * has the V4L2_CTRL_FLAG_DISABLED flag set), is read-only, or if any other\n- * error occurs during validation of the requested controls, no control is\n- * written and this function returns -EINVAL.\n- *\n- * If an error occurs while writing the controls, the index of the first\n- * control that couldn't be written is returned. All controls below that index\n- * are written and their values are updated in \\a ctrls, while all other\n- * controls are not written and their values are not changed.\n- *\n- * \\sa V4L2Device::setControls()\n- *\n  * \\return 0 on success or an error code otherwise\n- * \\retval -EINVAL One of the control is not supported or not accessible\n- * \\retval i The index of the control that failed\n+ * \\sa V4L2Device::setControls()\n  */\n \n /**\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex b49d73b1c..53bd7865a 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -285,18 +285,16 @@ ControlList V4L2Device::getControls(Span<const uint32_t> ids, const V4L2Request\n  * \\param[in] request An optional request\n  *\n  * This function writes the value of all controls contained in \\a ctrls, and\n- * stores the values actually applied to the device in the corresponding\n- * \\a ctrls entry.\n+ * updates \\a ctrls with the values actually applied to the device.\n  *\n  * If any control in \\a ctrls is not supported by the device, is disabled (i.e.\n  * has the V4L2_CTRL_FLAG_DISABLED flag set), is read-only, if any other error\n  * occurs during validation of the requested controls, no control is written and\n  * this function returns -EINVAL.\n  *\n- * If an error occurs while writing the controls, the index of the first\n- * control that couldn't be written is returned. All controls below that index\n- * are written and their values are updated in \\a ctrls, while all other\n- * controls are not written and their values are not changed.\n+ * If an error occurs while writing the controls, -EIO is returned. All controls\n+ * that were successfully written have their values are updated in \\a ctrls,\n+ * while all other controls are not written and their values are not changed.\n  *\n  * If \\a request is set, the controls will be applied to that request. If the\n  * device doesn't support requests, -EACCESS will be returned. If \\a request is\n@@ -304,8 +302,8 @@ ControlList V4L2Device::getControls(Span<const uint32_t> ids, const V4L2Request\n  *\n  * \\return 0 on success or an error code otherwise\n  * \\retval -EINVAL One of the controls is not supported or not accessible\n+ * \\retval -EIO One or more controls were rejected by the device\n  * \\retval -EACCESS The device does not support requests\n- * \\retval i The index of the control that failed\n  */\n int V4L2Device::setControls(ControlList *ctrls, const V4L2Request *request)\n {\n@@ -419,7 +417,7 @@ int V4L2Device::setControls(ControlList *ctrls, const V4L2Request *request)\n \t\t\t\t << \": \" << strerror(-ret);\n \n \t\tv4l2Ctrls.resize(errorIdx);\n-\t\tret = errorIdx;\n+\t\tret = -EIO;\n \t}\n \n \tupdateControls(ctrls, v4l2Ctrls);\n","prefixes":["v1","1/2"]}