[libcamera-devel] [PATCH] libcamera: v4l2_device: Workaround faulty control menus

Kieran Bingham kieran.bingham at ideasonboard.com
Wed Nov 2 11:35:42 CET 2022


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 <kieran.bingham at ideasonboard.com>
---
 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<int32_t>(ctrl.default_value));
+	}
+
 	return ControlInfo(indices,
 			   ControlValue(static_cast<int32_t>(ctrl.default_value)));
 }
-- 
2.34.1



More information about the libcamera-devel mailing list