[PATCH] apps: cam: Skip devices without connectors

Milan Zamazal mzamazal at redhat.com
Thu Mar 20 21:51:05 CET 2025


Device::openCard() in the cam DRM helpers looks for a /dev/dri/card*
device that can be opened and that doesn't fail when asked about
DRM_CAP_DUMB_BUFFER capability (regardless whether the capability is
supported by the device).

There can be matching devices that are not display devices.  This can
lead to selection of such a device and inability to use KMS output with
`cam' application.  The ultimate goal is to display something on the
device and later the KMS sink will fail if there is no connector
attached to the device (although it can actually fail earlier, when
trying to set DRM_CLIENT_CAP_ATOMIC capability if this is not
supported).  Let's avoid selecting devices without connectors.

A question is whether the added check makes the check for
DRM_CAP_DUMB_BUFFER API redundant or not.

Signed-off-by: Milan Zamazal <mzamazal at redhat.com>
---
 src/apps/cam/drm.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/apps/cam/drm.cpp b/src/apps/cam/drm.cpp
index 47bbb6b0..e19e848c 100644
--- a/src/apps/cam/drm.cpp
+++ b/src/apps/cam/drm.cpp
@@ -479,6 +479,18 @@ int Device::openCard()
 			continue;
 		}
 
+		/* Skip devices without connectors. */
+		std::unique_ptr<drmModeRes, decltype(&drmModeFreeResources)> resources{
+			drmModeGetResources(fd_),
+			&drmModeFreeResources
+		};
+		if (!resources || resources->count_connectors <= 0) {
+			resources.reset();
+			drmClose(fd_);
+			fd_ = -1;
+			continue;
+		}
+
 		found = true;
 		break;
 	}
-- 
2.49.0



More information about the libcamera-devel mailing list