Show a patch.

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

{
    "id": 17897,
    "url": "https://patchwork.libcamera.org/api/patches/17897/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17897/",
    "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": "<20221124144553.3012369-1-kieran.bingham@ideasonboard.com>",
    "date": "2022-11-24T14:45:53",
    "name": "[libcamera-devel,v5] libcamera: v4l2_device: Workaround faulty control menus",
    "commit_ref": "96ed45b9711e5c70afc4f91eab0ed657ccfb9695",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "12c1a58dbbaf19021373ba119be7b1e736b3f92c",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17897/mbox/",
    "series": [
        {
            "id": 3640,
            "url": "https://patchwork.libcamera.org/api/series/3640/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3640",
            "date": "2022-11-24T14:45:53",
            "name": "[libcamera-devel,v5] libcamera: v4l2_device: Workaround faulty control menus",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/3640/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17897/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17897/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 33711BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Nov 2022 14:45:59 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7DAFE6331F;\n\tThu, 24 Nov 2022 15:45:58 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C8CF6330D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Nov 2022 15:45:57 +0100 (CET)",
            "from Monstersaurus.local\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DCC52496;\n\tThu, 24 Nov 2022 15:45:56 +0100 (CET)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669301158;\n\tbh=k1m8QQ1vKRcT8Yf95deLGhvehL5TdbzwSo0aCazGe8Y=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:Cc:From;\n\tb=C/9e7ddWUx821dvkotVSlyLWj/xuvV+TOz0LGBJIk9+wcozQgw7tNv3y/gIUUhN6W\n\t1LM92gWCRcaUPgOmNohfLWlk954GAdvLFOrQXAJGHxBzT31tZjKeMRz9GtwJ1wTEDD\n\t3hNoZvRbwGQN1L0eeL0T4ud6Q1tAfhbx6gZzMnkH5TdWFtn88ymbczeJE2z5fUyz64\n\tK9GzDO1KyQ7cgUDQWtXenROnJnlNyfsOZq9m3e6cOHw+MEAAsuWzhbKUYGCBCrtKv1\n\tlAWXmfJmBG9HFGRZusY2RXtKfZZ/kIQ7DvB6rukrgdYTe0G5B5pugVilXLjsEmo90U\n\t2x6C585CkyvnA==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1669301157;\n\tbh=k1m8QQ1vKRcT8Yf95deLGhvehL5TdbzwSo0aCazGe8Y=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=Oymq002ieUJL/iMdDeBkNElHdXAjZ+bx4mbAwHPEFxpMM5psSyP7gWcKxgvbIF/Vz\n\tlc4S0kHQE2Dxl5VBAQz160G0LmG5U5ep03BfbGrX8Fo5L1aghh/T3voK2F+Gk7c/QK\n\tbV+aQA89owCmyyTcfyyH/zacSr3Gmts6BlBudZtQ="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Oymq002i\"; dkim-atps=neutral",
        "To": "libcamera devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Thu, 24 Nov 2022 14:45:53 +0000",
        "Message-Id": "<20221124144553.3012369-1-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v5] libcamera: v4l2_device: Workaround\n\tfaulty control menus",
        "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": "Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "Cc": "Marian Buschsieweke <marian.buschsieweke@ovgu.de>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Some UVC cameras have been identified that can provide V4L2 menu\ncontrols without any menu items.\n\nThis leads to a segfault where we try to construct a\nControlInfo(Span<>,default) with an empty span.\n\nConvert the v4l2ControlInfo and v4l2MenuControlInfo helper functions to\nreturn std::optional<ControlInfo> to be able to account in the caller if\nthe control is valid, and only add acceptable controls to the supported\ncontrol list.\n\nMenu controls without a list of menu items are no longer added as a\nvalid control and a warning is logged.\n\nThis also fixes a potential crash that would have occured in the\nunlikely event that a ctrl.minimum was set to less than 0.\n\nBug: https://bugs.libcamera.org/show_bug.cgi?id=167\nReported-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n\nAs I posted two v3 patches, I've gone straight to v5 on this.\n\nNow there's only the common path error report, and a couple of minor\ntext fixes.\n\n\n include/libcamera/internal/v4l2_device.h |  4 ++--\n src/libcamera/v4l2_device.cpp            | 28 +++++++++++++++++++-----\n 2 files changed, 25 insertions(+), 7 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex 75304be11f77..50d4adbc5f2b 100644\n--- a/include/libcamera/internal/v4l2_device.h\n+++ b/include/libcamera/internal/v4l2_device.h\n@@ -70,8 +70,8 @@ protected:\n private:\n \tstatic ControlType v4l2CtrlType(uint32_t ctrlType);\n \tstatic std::unique_ptr<ControlId> v4l2ControlId(const v4l2_query_ext_ctrl &ctrl);\n-\tControlInfo v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl);\n-\tControlInfo v4l2MenuControlInfo(const v4l2_query_ext_ctrl &ctrl);\n+\tstd::optional<ControlInfo> v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl);\n+\tstd::optional<ControlInfo> v4l2MenuControlInfo(const v4l2_query_ext_ctrl &ctrl);\n \n \tvoid listControls();\n \tvoid updateControls(ControlList *ctrls,\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex c17b323f8af0..57a88d96b12c 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -529,7 +529,7 @@ std::unique_ptr<ControlId> V4L2Device::v4l2ControlId(const v4l2_query_ext_ctrl &\n  * \\param[in] ctrl The v4l2_query_ext_ctrl that represents a V4L2 control\n  * \\return A ControlInfo that represents \\a ctrl\n  */\n-ControlInfo V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl)\n+std::optional<ControlInfo> V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl)\n {\n \tswitch (ctrl.type) {\n \tcase V4L2_CTRL_TYPE_U8:\n@@ -566,14 +566,14 @@ ControlInfo V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl)\n  *\n  * \\return A ControlInfo that represents \\a ctrl\n  */\n-ControlInfo V4L2Device::v4l2MenuControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\n+std::optional<ControlInfo> V4L2Device::v4l2MenuControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\n {\n \tstd::vector<ControlValue> indices;\n \tstruct v4l2_querymenu menu = {};\n \tmenu.id = ctrl.id;\n \n \tif (ctrl.minimum < 0)\n-\t\treturn ControlInfo();\n+\t\treturn std::nullopt;\n \n \tfor (int32_t index = ctrl.minimum; index <= ctrl.maximum; ++index) {\n \t\tmenu.index = index;\n@@ -583,6 +583,14 @@ ControlInfo V4L2Device::v4l2MenuControlInfo(const struct v4l2_query_ext_ctrl &ct\n \t\tindices.push_back(index);\n \t}\n \n+\t/*\n+\t * Some faulty UVC devices are known to return an empty menu control.\n+\t * Controls without a menu option can not be set, or read, so they are\n+\t * not exposed.\n+\t */\n+\tif (indices.size() == 0)\n+\t\treturn std::nullopt;\n+\n \treturn ControlInfo(indices,\n \t\t\t   ControlValue(static_cast<int32_t>(ctrl.default_value)));\n }\n@@ -631,7 +639,17 @@ void V4L2Device::listControls()\n \t\tcontrolIdMap_[ctrl.id] = controlIds_.back().get();\n \t\tcontrolInfo_.emplace(ctrl.id, ctrl);\n \n-\t\tctrls.emplace(controlIds_.back().get(), v4l2ControlInfo(ctrl));\n+\t\tstd::optional<ControlInfo> info = v4l2ControlInfo(ctrl);\n+\n+\t\tif (!info) {\n+\t\t\tLOG(V4L2, Error)\n+\t\t\t\t<< \"Control \" << ctrl.name\n+\t\t\t\t<< \" cannot be registered\";\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tctrls.emplace(controlIds_.back().get(), *info);\n \t}\n \n \tcontrols_ = ControlInfoMap(std::move(ctrls), controlIdMap_);\n@@ -670,7 +688,7 @@ void V4L2Device::updateControlInfo()\n \t\t\tcontinue;\n \t\t}\n \n-\t\tinfo = v4l2ControlInfo(ctrl);\n+\t\tinfo = *v4l2ControlInfo(ctrl);\n \t}\n }\n \n",
    "prefixes": [
        "libcamera-devel",
        "v5"
    ]
}