diff options
author | Michał Winiarski <michal.winiarski@intel.com> | 2019-03-06 13:20:45 +0100 |
---|---|---|
committer | Michał Winiarski <michal.winiarski@intel.com> | 2019-03-20 10:36:36 +0100 |
commit | 1bbe0b11a40cbb8433a3863745b7023e54c36ae3 (patch) | |
tree | fe97093aa1a13fbc4b4045f7594c343ed50182c5 | |
parent | 8e3fe6a3ed679fa2bf78149a8ed2e6088c7c67e3 (diff) |
lib/igt_sysfs: Simplify obtaining sysfs path
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>
-rw-r--r-- | lib/igt_sysfs.c | 27 |
1 files 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; } /** |