From e08ed8a272fda96b8f7224985177f313c3b2ddf6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 24 Mar 2017 20:52:44 +0000 Subject: lib/debugfs: Phase out igt_debugfs_fopen() Wrapping fdopen() proved dangerous, the underlying fd is not refcounted, and we must close it in the library or else we easily leak and exhaust all fd. Since we can't provide igt_debugfs_fopen(), move the burden onto the caller for those that require a stream FILE*. Signed-off-by: Chris Wilson --- tools/intel_dp_compliance.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'tools/intel_dp_compliance.c') diff --git a/tools/intel_dp_compliance.c b/tools/intel_dp_compliance.c index 4b4d255d..c40548e7 100644 --- a/tools/intel_dp_compliance.c +++ b/tools/intel_dp_compliance.c @@ -227,17 +227,27 @@ static void clear_test_active(void) fflush(test_active_fp); } +static FILE *fopenat(int dir, const char *name, const char *mode) +{ + int fd = openat(dir, name, O_RDWR); + return fdopen(fd, mode); +} + static void setup_debugfs_files(void) { - test_type_fp = igt_debugfs_fopen(drm_fd, INTEL_DP_TEST_TYPE_FILE, "r"); + int dir = igt_debugfs_dir(drm_fd); + + test_type_fp = fopenat(dir, INTEL_DP_TEST_TYPE_FILE, "r"); igt_require(test_type_fp); - test_data_fp = igt_debugfs_fopen(drm_fd, INTEL_DP_TEST_DATA_FILE, "r"); + test_data_fp = fopenat(dir, INTEL_DP_TEST_DATA_FILE, "r"); igt_require(test_data_fp); - test_active_fp = igt_debugfs_fopen(drm_fd, INTEL_DP_TEST_ACTIVE_FILE, "w+"); + test_active_fp = fopenat(dir, INTEL_DP_TEST_ACTIVE_FILE, "w+"); igt_require(test_active_fp); + close(dir); + /* Reset the active flag for safety */ clear_test_active(); } -- cgit v1.2.3