From patchwork Wed Nov 2 10:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 17744 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 B0956BDB16 for ; Wed, 2 Nov 2022 10:38:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F21C463075; Wed, 2 Nov 2022 11:38:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1667385491; bh=/gTK0r37EM7Ngj4dcICt+WRXKLmfvvvE/AB/YRWN0y8=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=i+NHXmVccjvIQRa5cIcdNcQXmHQsMJAogB2z1tlWPBRo7TggD9EI5Gv6Ahafbdk5p uQUdO8FRj78DVvPc3UwucDjHk0idggJlIVRVIxWgMqc2WYJopfbaniM+SuxZooj3S7 HJk9/g0pu6d+Pjkhvyx4tPFGtYYSHsTVDDs9Kj8PNn4WoFrLEn2Mak/ISQXVphgYks kCoeiayd1PtHwSfEAAS/aY6f+F6GVqJ2AzjcEy8F4pLwdP4uZCXdtN0OhqbwOMWKhx hTuOK88tQ43MA5v+XryOCBwS0NXg7eOvo4icgKjVCxTv9XfjkjEScaKnuldxRAGfZA irB68XYzda1Nw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C2F063009 for ; Wed, 2 Nov 2022 11:38:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RCl5GN/j"; 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 C377F1226; Wed, 2 Nov 2022 11:38:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1667385489; bh=/gTK0r37EM7Ngj4dcICt+WRXKLmfvvvE/AB/YRWN0y8=; h=From:To:Cc:Subject:Date:From; b=RCl5GN/jPmA3Iz1bYwNJ5v0gWpD64FkNsa2qkJ7H0MJU5/RCE6Goi43xMISOg/2AC gioj5gU/SF75ZAMeFGwotobOoZ6KakLa7+Jb1fUg8ff5b3nTJIhCcWEGG/Y9EHYOIK B9mTwAVhFq3E2oG3shZ8B2N28BCDzDA4O+8UoXkM= To: libcamera devel Date: Wed, 2 Nov 2022 10:38:04 +0000 Message-Id: <20221102103804.3933874-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] 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 Cc: Marian Buschsieweke 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 Reported-by: Marian Buschsieweke Signed-off-by: Kieran Bingham --- v2: - Sigh, I forgot the SoB/Trailers in the commit message. 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))); }