[PATCH v2] apps: cam: Skip devices without connectors

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri May 16 00:27:12 CEST 2025


Hi Milan,

Thank you for the patch.

On Thu, May 15, 2025 at 06:25:36PM +0200, Milan Zamazal wrote:
> 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

Can you share an example of such a device ? Are we talking about a
device that sets DRIVER_MODESET but is not a display device ?

> 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.
> 
> Changes in v2:
> - Rebased on current master.
> 
> 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;
>  	}

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list