[igt-dev] [PATCH i-g-t 08/29] lib: remove open-coded card index fetching

D Scott Phillips d.scott.phillips at intel.com
Wed Dec 11 00:52:14 UTC 2019


Replace open-coded card index fetching via stat with
igt_device_get_card_index() calls.

Signed-off-by: D Scott Phillips <d.scott.phillips at intel.com>
---
 lib/igt_debugfs.c | 17 ++++-------------
 lib/igt_sysfs.c   | 10 +++++-----
 2 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 676884c8..34b2e4ee 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -41,6 +41,7 @@
 #include "igt_aux.h"
 #include "igt_kms.h"
 #include "igt_debugfs.h"
+#include "igt_device.h"
 #include "igt_sysfs.h"
 
 /**
@@ -164,20 +165,10 @@ char *igt_debugfs_path(int device, char *path, int pathlen)
 	debugfs_root = igt_debugfs_mount();
 	igt_assert(debugfs_root);
 
-	memset(&st, 0, sizeof(st));
-	if (device != -1) { /* if no fd, we presume we want dri/0 */
-		if (fstat(device, &st)) {
-			igt_debug("Couldn't stat FD for DRM device: %m\n");
-			return NULL;
-		}
-
-		if (!S_ISCHR(st.st_mode)) {
-			igt_debug("FD for DRM device not a char device!\n");
-			return NULL;
-		}
-	}
+	idx = 0;
+	if (device >= 0)
+		idx = igt_device_get_card_index(device);
 
-	idx = minor(st.st_rdev);
 	snprintf(path, pathlen, "%s/dri/%d/name", debugfs_root, idx);
 	if (stat(path, &st))
 		return NULL;
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 7528c3bd..61293a4e 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -43,6 +43,8 @@
 #include "igt_sysfs.h"
 #include "igt_device.h"
 
+#define DRM_MAJOR 226
+
 /**
  * SECTION:igt_sysfs
  * @short_description: Support code for sysfs features
@@ -98,16 +100,14 @@ static int writeN(int fd, const char *buf, int len)
  */
 char *igt_sysfs_path(int device, char *path, int pathlen)
 {
-	struct stat st;
+	int idx;
 
 	if (device < 0)
 		return NULL;
 
-	if (fstat(device, &st) || !S_ISCHR(st.st_mode))
-		return NULL;
+	idx = igt_device_get_card_index(device);
 
-	snprintf(path, pathlen, "/sys/dev/char/%d:%d",
-		 major(st.st_rdev), minor(st.st_rdev));
+	snprintf(path, pathlen, "/sys/dev/char/%d:%d", DRM_MAJOR, idx);
 
 	if (access(path, F_OK))
 		return NULL;
-- 
2.23.0



More information about the igt-dev mailing list