[libcamera-devel] libcamera: v4l2_device: Workaround faulty control menus
diff mbox series

Message ID 20221102103542.3932541-1-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • [libcamera-devel] libcamera: v4l2_device: Workaround faulty control menus
Related show

Commit Message

Kieran Bingham Nov. 2, 2022, 10:35 a.m. UTC
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@ideasonboard.com>
---
 src/libcamera/v4l2_device.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

Patch
diff mbox series

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)));
 }