From patchwork Wed Nov 2 10:35:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 17743 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1FABABD16B for ; Wed, 2 Nov 2022 10:35:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4EA9863075; Wed, 2 Nov 2022 11:35:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1667385348; bh=agf1X6R9Fl9Y7EWlO4QfnrLg3tPnnPWOpe6MQMf/2Qw=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=zoiTwubf/z6Dky6DK8kAOtHce65Kjh4xI+uvJXRBRYFXvkY7DVgMrHK0oSVoKb+mK iBOmKgBbdKT/etFbnd2QDV9qpW3am0vgSegbQyqkqlkWt1d+/MpVLz2fm2BqgFHZpX t9ayY9N3oNwO4DVp8jH6GL0wGrCGM+U+xe8+PdFd8vdJjWIEb9TmVwAGT+kgFgaCJB J49cOJl/eMzDNhSqherYY9+44qpJ7zyDLOvbbhq/MwvPnPg2g1gpM5ZBJqlu7e4FmK 5BHp/BzpuDXGxbfB5f7rGW9P+ldPHKqq3cLmvM7YcEFurXCwm6/aYi9trHWTN4YdU4 ZRshgE9sL3XMg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 774C163009 for ; Wed, 2 Nov 2022 11:35:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jlymVlvp"; dkim-atps=neutral Received: from Monstersaurus.tail69b4.ts.net (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DF73A1226; Wed, 2 Nov 2022 11:35:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1667385346; bh=agf1X6R9Fl9Y7EWlO4QfnrLg3tPnnPWOpe6MQMf/2Qw=; h=From:To:Cc:Subject:Date:From; b=jlymVlvpHBG4DzHGLg6NoxiGwaZOY3jWG6X0bw4TM0lEwJEnV4GuPQQGp/8U0Wtoa PXcUhLQcX9VnE4vX9IDuhzY9i0iXx0uMBjccwzvMfyNWtrzcC5uuOKo8nar4bi056t +NWJ/GG5d9yHuzQRIbvYIVSzXzL6v1euLwaqy8cU= To: libcamera devel Date: Wed, 2 Nov 2022 10:35:42 +0000 Message-Id: <20221102103542.3932541-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: v4l2_device: Workaround faulty control menus X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Some UVC cameras have been identified that can provide V4L2 menu controls without any menu items. This leads to a segfault where we try to construct a ControlInfo(Span<>,default) with an empty span. Returning ControlInfo(); instead results in a Fatal log error due to the control validation failing. Provide the default value as the only acceptable menu control item, and report the issue on the debug log. Bug: https://bugs.libcamera.org/show_bug.cgi?id=167 Signed-off-by: Kieran Bingham --- src/libcamera/v4l2_device.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index c17b323f8af0..f35820271f51 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -583,6 +583,16 @@ ControlInfo V4L2Device::v4l2MenuControlInfo(const struct v4l2_query_ext_ctrl &ct indices.push_back(index); } + /* + * Some faulty UVC drivers are known to return an empty menu control. + * In that event, populate the indicies with the default value only. + */ + if (indices.size() == 0) { + LOG(V4L2, Debug) + << "Menu control '" << ctrl.name << "' has no entries"; + indices.push_back(static_cast(ctrl.default_value)); + } + return ControlInfo(indices, ControlValue(static_cast(ctrl.default_value))); }