[PATCH] libcamera: device_enumerator: exclude uvcvideo device when enumerate

Anle Pan anle.pan at nxp.com
Tue Mar 26 09:38:04 CET 2024


Camera service startup crash when camera and
usb camera are connected at the same time,
service will always reboot due to the null pointer
in populateEntities.

In this case, a UVC device was used to populate the
related entities, pads and links, which was not reasonable.

To fix the issue, ensure the media node is not
a "uvcvideo" device when enumerate before createDevice.

Change-Id: I656a542e83449df287d34a4e358ae2e26e784f17
Signed-off-by: Anle Pan <anle.pan at nxp.com>
---
 src/libcamera/device_enumerator_sysfs.cpp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/libcamera/device_enumerator_sysfs.cpp b/src/libcamera/device_enumerator_sysfs.cpp
index 9979d68a..224ec8c8 100644
--- a/src/libcamera/device_enumerator_sysfs.cpp
+++ b/src/libcamera/device_enumerator_sysfs.cpp
@@ -73,6 +73,27 @@ int DeviceEnumeratorSysfs::enumerate()
 			continue;
 		}
 
+		/* Check that the device node not a uvcvideo. */
+		struct media_device_info devinfo;
+		int fd = open(devnode.c_str(), O_RDWR | O_CLOEXEC);
+		if (fd < 0) {
+			LOG(DeviceEnumerator, Warning)
+				<< "Failed to open media device:" + devnode
+				<< " (" << strerror(errno) << "), skipping";
+			continue;
+		}
+		int retval = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &devinfo);
+		close(fd);
+		if (retval != 0) {
+			LOG(DeviceEnumerator, Warning)
+				<< "Failed to get info from device:" + devnode
+				<< " (" << strerror(errno) << "), skipping";
+			continue;
+		}
+		if (strstr("uvcvideo", devinfo.driver)) {
+			continue;
+		}
+
 		std::unique_ptr<MediaDevice> media = createDevice(devnode);
 		if (!media)
 			continue;
-- 
2.34.1



More information about the libcamera-devel mailing list