From: "Michał Winiarski" <michal.winiarski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [CI 7/8] lib/igt_sysfs: Simplify obtaining sysfs path
Date: Tue, 19 Mar 2019 11:15:15 +0100 [thread overview]
Message-ID: <20190319101516.11020-7-michal.winiarski@intel.com> (raw)
In-Reply-To: <20190319101516.11020-1-michal.winiarski@intel.com>
Now that we've extracted card index, we no longer have the need to
iterate over device nodes.
v2: Drop ret.
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
---
lib/igt_sysfs.c | 27 +++++----------------------
1 file changed, 5 insertions(+), 22 deletions(-)
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index aa880775..f806f4fc 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -106,30 +106,13 @@ 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;
+ snprintf(path, pathlen, "/sys/dev/char/%d:%d",
+ major(st.st_rdev), minor(st.st_rdev));
- 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);
-
- if (ret != 2 || major(st.st_rdev) != maj ||
- minor(st.st_rdev) != min)
- continue;
-
- path[len] = '\0';
-
- return path;
- }
+ if (access(path, F_OK))
+ 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
next prev parent reply other threads:[~2019-03-19 10:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-19 10:15 [igt-dev] [CI 1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
2019-03-19 10:15 ` [igt-dev] [CI 2/8] tests/perf: Simplify generic read/write, use sysfs helpers Michał Winiarski
2019-03-19 10:15 ` [igt-dev] [CI 3/8] tests/i915_pm_rps: Use " Michał Winiarski
2019-03-19 10:15 ` [igt-dev] [CI 4/8] lib/igt_device: Introduce igt_device_get_card_index Michał Winiarski
2019-03-19 10:15 ` [igt-dev] [CI 5/8] lib: Kill drm_get_card() Michał Winiarski
2019-03-19 10:15 ` [igt-dev] [CI 6/8] lib/igt_sysfs: Remove idx from sysfs_open Michał Winiarski
2019-03-19 10:15 ` Michał Winiarski [this message]
2019-03-19 10:15 ` [igt-dev] [CI 8/8] lib/igt_device: Move intel_get_pci_device under igt_device Michał Winiarski
2019-03-19 11:31 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [CI,1/8] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Patchwork
2019-03-19 18:47 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2019-03-14 12:50 [igt-dev] [CI 1/8] " Michał Winiarski
2019-03-14 12:50 ` [igt-dev] [CI 7/8] lib/igt_sysfs: Simplify obtaining sysfs path Michał Winiarski
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=20190319101516.11020-7-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