From 3bc3cca230c5a064b2f554f26fdec27db0f5ead8 Mon Sep 17 00:00:00 2001 From: James Zhu Date: Mon, 7 Aug 2023 10:14:18 -0400 Subject: [PATCH] xf86drm: use drm device name to identify drm node type Currently drm node's minor range is used to identify node's type. Since kernel drm uses node type name and minor to generate drm device name, It will be more general to use drm device name to identify drm node type. Signed-off-by: James Zhu Reviewed-by: Simon Ser --- xf86drm.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 52b83ccc..ebc60956 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -1051,18 +1051,20 @@ static int drmGetMinorType(int major, int minor) minor = id; #endif - int type = minor >> 6; + char path[DRM_NODE_NAME_MAX]; + const char *dev_name; + int i; - if (minor < 0) - return -1; - - switch (type) { - case DRM_NODE_PRIMARY: - case DRM_NODE_RENDER: - return type; - default: - return -1; + for (i = DRM_NODE_PRIMARY; i < DRM_NODE_MAX; i++) { + dev_name = drmGetDeviceName(i); + if (!dev_name) + continue; + snprintf(path, sizeof(path), dev_name, DRM_DIR_NAME, minor); + if (!access(path, F_OK)) + return i; } + + return -1; } static const char *drmGetMinorName(int type)