[igt-dev] [PATCH i-g-t 4/6] lib/igt_sysfs: Remove idx from sysfs_open

Michał Winiarski michal.winiarski at intel.com
Wed Mar 13 12:53:30 UTC 2019


Similar to sysfs_path - more explicit more better.

Signed-off-by: Michał Winiarski <michal.winiarski at intel.com>
---
 lib/igt_gt.c                       | 2 +-
 lib/igt_kms.c                      | 7 ++++++-
 lib/igt_sysfs.c                    | 8 ++------
 lib/igt_sysfs.h                    | 2 +-
 tests/i915/gem_exec_blt.c          | 2 +-
 tests/i915/gem_exec_capture.c      | 2 +-
 tests/i915/i915_hangman.c          | 4 +---
 tests/i915/i915_pm_rc6_residency.c | 2 +-
 tests/perf.c                       | 3 ++-
 tests/perf_pmu.c                   | 2 +-
 tests/vgem_basic.c                 | 2 +-
 tools/intel_l3_parity.c            | 2 +-
 12 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index c98a7553..59995243 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -76,7 +76,7 @@ static void eat_error_state(int dev)
 {
 	int dir;
 
-	dir = igt_sysfs_open(dev, NULL);
+	dir = igt_sysfs_open(dev);
 	if (dir < 0)
 		return;
 
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index e1eacc1e..8656ea11 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -52,6 +52,7 @@
 #include "igt_aux.h"
 #include "intel_chipset.h"
 #include "igt_debugfs.h"
+#include "igt_device.h"
 #include "igt_sysfs.h"
 #include "sw_sync.h"
 
@@ -806,10 +807,14 @@ bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,
 		break;
 	}
 
-	dir = igt_sysfs_open(drm_fd, &idx);
+	dir = igt_sysfs_open(drm_fd);
 	if (dir < 0)
 		return false;
 
+	idx = igt_device_get_card_index(drm_fd);
+	if (idx < 0 || idx > 63)
+		return false;
+
 	if (asprintf(&path, "card%d-%s-%d/status",
 		     idx,
 		     kmstest_connector_type_str(connector->connector_type),
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index fd075cd6..13a2ee04 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -136,7 +136,6 @@ char *igt_sysfs_path(int device, char *path, int pathlen)
 /**
  * igt_sysfs_open:
  * @device: fd of the device
- * @idx: optional pointer to store the card index of the opened device
  *
  * This opens the sysfs directory corresponding to device for use
  * with igt_sysfs_set() and igt_sysfs_get().
@@ -144,16 +143,13 @@ char *igt_sysfs_path(int device, char *path, int pathlen)
  * Returns:
  * The directory fd, or -1 on failure.
  */
-int igt_sysfs_open(int device, int *idx)
+int igt_sysfs_open(int device)
 {
 	char path[80];
 
 	if (!igt_sysfs_path(device, path, sizeof(path)))
 		return -1;
 
-	if (idx)
-		*idx = igt_device_get_card_index(device);
-
 	return open(path, O_RDONLY);
 }
 
@@ -200,7 +196,7 @@ int igt_sysfs_open_parameters(int device)
 {
 	int dir, params = -1;
 
-	dir = igt_sysfs_open(device, &params);
+	dir = igt_sysfs_open(device);
 	if (dir >= 0) {
 		params = openat(dir,
 				"device/driver/module/parameters",
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index b181a95f..c12e36d1 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -29,7 +29,7 @@
 #include <stdarg.h>
 
 char *igt_sysfs_path(int device, char *path, int pathlen);
-int igt_sysfs_open(int device, int *idx);
+int igt_sysfs_open(int device);
 int igt_sysfs_open_parameters(int device);
 bool igt_sysfs_set_parameter(int device,
 			     const char *parameter,
diff --git a/tests/i915/gem_exec_blt.c b/tests/i915/gem_exec_blt.c
index 0fcfdd4b..00926e55 100644
--- a/tests/i915/gem_exec_blt.c
+++ b/tests/i915/gem_exec_blt.c
@@ -315,7 +315,7 @@ int main(int argc, char **argv)
 		fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
 
-		sysfs = igt_sysfs_open(fd, NULL);
+		sysfs = igt_sysfs_open(fd);
 		igt_require(sysfs >= 0);
 
 		min = igt_sysfs_get_u32(sysfs, "gt_min_freq_mhz");
diff --git a/tests/i915/gem_exec_capture.c b/tests/i915/gem_exec_capture.c
index 56837dfc..4457496d 100644
--- a/tests/i915/gem_exec_capture.c
+++ b/tests/i915/gem_exec_capture.c
@@ -547,7 +547,7 @@ igt_main
 		igt_require(has_capture(fd));
 		igt_allow_hang(fd, 0, HANG_ALLOW_CAPTURE);
 
-		dir = igt_sysfs_open(fd, NULL);
+		dir = igt_sysfs_open(fd);
 		igt_require(igt_sysfs_set(dir, "error", "Begone!"));
 		igt_require(safer_strlen(igt_sysfs_get(dir, "error")) > 0);
 	}
diff --git a/tests/i915/i915_hangman.c b/tests/i915/i915_hangman.c
index 4e515e3a..9a1d5889 100644
--- a/tests/i915/i915_hangman.c
+++ b/tests/i915/i915_hangman.c
@@ -262,14 +262,12 @@ igt_main
 	igt_skip_on_simulation();
 
 	igt_fixture {
-		int idx;
-
 		device = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(device);
 
 		hang = igt_allow_hang(device, 0, HANG_ALLOW_CAPTURE);
 
-		sysfs = igt_sysfs_open(device, &idx);
+		sysfs = igt_sysfs_open(device);
 		igt_assert(sysfs != -1);
 
 		igt_require(has_error_state(sysfs));
diff --git a/tests/i915/i915_pm_rc6_residency.c b/tests/i915/i915_pm_rc6_residency.c
index abc30ac6..1b52e4f5 100644
--- a/tests/i915/i915_pm_rc6_residency.c
+++ b/tests/i915/i915_pm_rc6_residency.c
@@ -208,7 +208,7 @@ igt_main
 
 		fd = drm_open_driver(DRIVER_INTEL);
 		devid = intel_get_drm_devid(fd);
-		sysfs = igt_sysfs_open(fd, NULL);
+		sysfs = igt_sysfs_open(fd);
 
 		igt_require(has_rc6_residency("rc6"));
 
diff --git a/tests/perf.c b/tests/perf.c
index ac979a65..84555462 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -4112,7 +4112,8 @@ igt_main
 		igt_require_gem(drm_fd);
 
 		devid = intel_get_drm_devid(drm_fd);
-		sysfs = igt_sysfs_open(drm_fd, &card);
+		card = igt_device_get_card_index(drm_fd);
+		sysfs = igt_sysfs_open(drm_fd);
 
 		igt_require(init_sys_info());
 
diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c
index aa5b9921..1a08f564 100644
--- a/tests/perf_pmu.c
+++ b/tests/perf_pmu.c
@@ -1275,7 +1275,7 @@ test_frequency(int gem_fd)
 	igt_spin_t *spin;
 	int fd, sysfs;
 
-	sysfs = igt_sysfs_open(gem_fd, NULL);
+	sysfs = igt_sysfs_open(gem_fd);
 	igt_require(sysfs >= 0);
 
 	min_freq = igt_sysfs_get_u32(sysfs, "gt_RPn_freq_mhz");
diff --git a/tests/vgem_basic.c b/tests/vgem_basic.c
index 1a952c54..526636dd 100644
--- a/tests/vgem_basic.c
+++ b/tests/vgem_basic.c
@@ -262,7 +262,7 @@ static void test_dmabuf_fence_before(int fd)
 
 static void test_sysfs_read(int fd)
 {
-	int dir = igt_sysfs_open(fd, NULL);
+	int dir = igt_sysfs_open(fd);
 	DIR *dirp = fdopendir(dir);
 	struct dirent *de;
 
diff --git a/tools/intel_l3_parity.c b/tools/intel_l3_parity.c
index d1a9bc44..d8c997af 100644
--- a/tools/intel_l3_parity.c
+++ b/tools/intel_l3_parity.c
@@ -191,7 +191,7 @@ int main(int argc, char *argv[])
 
 	assert(intel_register_access_init(intel_get_pci_device(), 0, device) == 0);
 
-	dir = igt_sysfs_open(device, NULL);
+	dir = igt_sysfs_open(device);
 
 	for_each_slice(i) {
 		fd[i] = openat(dir, path[i], O_RDWR);
-- 
2.20.1



More information about the igt-dev mailing list