From cf613fb2f6c3a2026ab10a057fd48a3f685086a7 Mon Sep 17 00:00:00 2001 From: Maxime Schmitt Date: Mon, 22 Aug 2022 19:38:28 +0200 Subject: [PATCH] Fix drm node file descriptor opening logic Fixes #157 --- src/extract_gpuinfo_amdgpu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/extract_gpuinfo_amdgpu.c b/src/extract_gpuinfo_amdgpu.c index b6ea8ca..5c92dde 100644 --- a/src/extract_gpuinfo_amdgpu.c +++ b/src/extract_gpuinfo_amdgpu.c @@ -357,14 +357,15 @@ static bool gpuinfo_amdgpu_get_device_handles( int fd = -1; - for (unsigned int j = DRM_NODE_MAX - 1;; j--) { - if (!(1 << j & devs[i]->available_nodes)) - continue; - - if ((fd = open(devs[i]->nodes[j], O_RDWR)) < 0) - continue; - - break; + // Try render node first + if (1 << DRM_NODE_RENDER & devs[i]->available_nodes) { + fd = open(devs[i]->nodes[DRM_NODE_RENDER], O_RDWR); + } + if (fd < 0) { + // Fallback to primary node (control nodes are unused according to the DRM documentation) + if (1 << DRM_NODE_PRIMARY & devs[i]->available_nodes) { + fd = open(devs[i]->nodes[DRM_NODE_PRIMARY], O_RDWR); + } } if (fd < 0)