Show a patch.

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

{
    "id": 17896,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17896/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17896/",
    "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": "<20221124130308.2928570-1-kieran.bingham@ideasonboard.com>",
    "date": "2022-11-24T13:03:08",
    "name": "[libcamera-devel,v3] libcamera: v4l2_device: Workaround faulty control menus",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "ba9dc91cb0843825151dcb10662df4ea649e9f3a",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/1.1/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17896/mbox/",
    "series": [
        {
            "id": 3639,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3639/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3639",
            "date": "2022-11-24T13:03:08",
            "name": "[libcamera-devel,v3] libcamera: v4l2_device: Workaround faulty control menus",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/3639/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17896/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17896/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 3E609BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Nov 2022 13:03:15 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D3DB663313;\n\tThu, 24 Nov 2022 14:03:14 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E4A5F632EA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Nov 2022 14:03:12 +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 2E17C25B;\n\tThu, 24 Nov 2022 14:03:12 +0100 (CET)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669294994;\n\tbh=iRzARgFIDKNcZVWq46EM5OhuFrq5RfB1fLlgG5AvLJU=;\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=BZM9J1METolmD1sVzT5JSpsKlAB2skmISYxvLrEAtD9oLnc8A9XHw7ZMEMAUHRxtU\n\tEnsqZZfW4jRVWCxT568ZVNOo97AwzzKXultYWQWv9BuUtFg3vOsG26mWzmfDTdfVjm\n\tG/PpZMATImlAH70XSYWDGr/xl9iGlWQZtfNsXwD42x4DwQaMMLxpRAwkVhup5z7Wk3\n\tc4s46icAk0V8GytIVr1o1CYmzyEKh0UqzBXJtkaXgy68DjIJDlxXzWRZn9NXPYCLxJ\n\tr4URBufBB1qMk5xsuGSEKDkiXINtaw3yCvUVUH8lolmTfdxenEBlT71HBC/vMc3D+D\n\tdUQwnCDxlk6Zg==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1669294992;\n\tbh=iRzARgFIDKNcZVWq46EM5OhuFrq5RfB1fLlgG5AvLJU=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=eEJzDGpQmMXuOOrKv7HwHmtsrvZxPgCqad/eUYgQmIy0aO9acs7izSpl91PZ1oTD8\n\tjl39PTrvvtwClmc6pIC6yVlcyQpVVqke5QBgt6cXUTCEt4EbBRNFE6pO6FE/p4CGgL\n\ttGkOeOTBwKdisAK7UEbmlZeJywsy8LxC+4oa6ews="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"eEJzDGpQ\"; dkim-atps=neutral",
        "To": "libcamera devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Thu, 24 Nov 2022 13:03:08 +0000",
        "Message-Id": "<20221124130308.2928570-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 v3] 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 include/libcamera/internal/v4l2_device.h |  4 +--\n src/libcamera/v4l2_device.cpp            | 31 ++++++++++++++++++++----\n 2 files changed, 28 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..5dd51037960d 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,17 @@ 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 drivers 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\tLOG(V4L2, Warning)\n+\t\t\t<< \"Menu control '\" << ctrl.name << \"' has no entries\";\n+\t\treturn std::nullopt;\n+\t}\n+\n \treturn ControlInfo(indices,\n \t\t\t   ControlValue(static_cast<int32_t>(ctrl.default_value)));\n }\n@@ -631,7 +642,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 +691,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",
        "v3"
    ]
}