public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Michał Winiarski" <michal.winiarski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 5/6] lib/igt_sysfs: Simplify obtaining sysfs path
Date: Wed, 13 Mar 2019 13:53:31 +0100	[thread overview]
Message-ID: <20190313125332.12471-6-michal.winiarski@intel.com> (raw)
In-Reply-To: <20190313125332.12471-1-michal.winiarski@intel.com>

Now that we've extracted card index, we no longer have the need to
iterate over device nodes.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
 lib/igt_sysfs.c | 29 +++++++----------------------
 1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 13a2ee04..974bf45a 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -100,6 +100,7 @@ static int writeN(int fd, const char *buf, int len)
 char *igt_sysfs_path(int device, char *path, int pathlen)
 {
 	struct stat st;
+	int ret;
 
 	if (device < 0)
 		return NULL;
@@ -107,30 +108,14 @@ char *igt_sysfs_path(int device, char *path, int pathlen)
 	if (fstat(device, &st) || !S_ISCHR(st.st_mode))
 		return NULL;
 
-	for (int n = 0; n < 16; n++) {
-		int len, ret, maj, min;
-		FILE *file;
-
-		len = snprintf(path, pathlen, "/sys/class/drm/card%d", n);
-
-		sprintf(path + len, "/dev");
-		file = fopen(path, "r");
-		if (!file)
-			continue;
-
-		ret = fscanf(file, "%d:%d", &maj, &min);
-		fclose(file);
+	snprintf(path, pathlen, "/sys/dev/char/%d:%d",
+		 major(st.st_rdev), minor(st.st_rdev));
 
-		if (ret != 2 || major(st.st_rdev) != maj ||
-		    minor(st.st_rdev) != min)
-			continue;
-
-		path[len] = '\0';
-
-		return path;
-	}
+	ret = access(path, F_OK);
+	if (ret)
+		return NULL;
 
-	return NULL;
+	return path;
 }
 
 /**
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-03-13 12:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-13 12:53 [igt-dev] [PATCH i-g-t 0/6] Attempt to get rid of some globals Michał Winiarski
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 1/6] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
2019-03-13 12:58   ` Chris Wilson
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 2/6] lib/igt_device: Introduce igt_device_get_card_index Michał Winiarski
2019-03-13 13:02   ` Chris Wilson
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 3/6] lib: Kill drm_get_card() Michał Winiarski
2019-03-13 13:05   ` Chris Wilson
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 4/6] lib/igt_sysfs: Remove idx from sysfs_open Michał Winiarski
2019-03-13 13:08   ` Chris Wilson
2019-03-13 12:53 ` Michał Winiarski [this message]
2019-03-13 14:09   ` [igt-dev] [PATCH i-g-t 5/6] lib/igt_sysfs: Simplify obtaining sysfs path Chris Wilson
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 6/6] lib/igt_device: Move intel_get_pci_device under igt_device Michał Winiarski
2019-03-13 14:27   ` Chris Wilson
2019-03-13 14:06 ` [igt-dev] ✓ Fi.CI.BAT: success for Attempt to get rid of some globals Patchwork
2019-03-13 18:07 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190313125332.12471-6-michal.winiarski@intel.com \
    --to=michal.winiarski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox