Skip to contentSkip to conversation

XE test cleanup to handle xe_device

PATCH In review Bhanuprakash Modem 5 participants 46 messages Jun 26, 2023 – Jun 28, 2023 Library code Page 1 of 2

lore
Share & tools
lore
#0 lore raw

v4 cover XE test cleanup to handle xe_device

Instead of caching the xe_device struct at subtest level, cache just after opening the driver. And remove from the cache just before closing the driver. So, this series introduces new helper drm_close_driver() which helps to remove the xe_device & close the drm fd. So that every user must call drm_close_driver() instead of close().

V2, V3:
- Cleanup
- Split the patches into multiple
V4: - Fix the double closure of fd

Bhanuprakash Modem (24):
lib: Interface to close the drm fd
lib: Cache xe_device at driver open/close level lib/xe/xe_query: Add xe_config() interface lib/igt_msm: Use drm_close_driver() to close the drm fd tests/amdgpu: Close the fd before exit
tests/i915: Close the fd before exit
tests/kms: Close the fd before exit tests/nouveau_crc: Close the fd before exit tests/xe/xe_gpgpu_fill: Close the fd before exit tests/i915/kms_mmap_write_crc: Avoid closing the closed fd tests/i915/gem_close_race: Fix the double closure of fd
tests: Use drm_close_driver() to close the drm fd tests/amdgpu: Use drm_close_driver() to close the drm fd tests/chamelium: Use drm_close_driver() to close the drm fd tests/panfrost: Use drm_close_driver() to close the drm fd tests/v3d: Use drm_close_driver() to close the drm fd tests/vc4: Use drm_close_driver() to close the drm fd tests/vmwgfx: Use drm_close_driver() to close the drm fd tests/kms: Use drm_close_driver() to close the drm fd tests/xe: Use drm_close_driver() to close the drm fd tests/i915: Use drm_close_driver() to close the drm fd tests/xe/xe_debugfs: Use xe_config() helper to get the config
tests: Drop xe_device get/put from test level Revert "lib/igt_kms: Cache xe_device info for kms tests"

 lib/drmtest.c                               | 68 ++++++++++++++++++++-
 lib/drmtest.h                               |  1 +
 lib/igt_kms.c                               |  8 ---
 lib/igt_msm.c                               |  2 +-
 lib/igt_types.c                             |  6 ++
 lib/igt_vmwgfx.c                            |  2 +-
 lib/xe/xe_query.c                           |  8 +++
 lib/xe/xe_query.h                           |  1 +
 tests/amdgpu/amd_abm.c                      |  1 +
 tests/amdgpu/amd_assr.c                     |  1 +
 tests/amdgpu/amd_basic.c                    |  2 +-
 tests/amdgpu/amd_cs_nop.c                   |  2 +-
 tests/amdgpu/amd_deadlock.c                 |  2 +-
 tests/amdgpu/amd_freesync_video_mode.c      |  1 +
 tests/amdgpu/amd_info.c                     |  2 +-
 tests/amdgpu/amd_mem_leak.c                 |  1 +
 tests/amdgpu/amd_module_load.c              |  2 +-
 tests/amdgpu/amd_prime.c                    |  6 +-
 tests/amdgpu/amd_psr.c                      |  3 +-
 tests/amdgpu/amd_vrr_range.c                |  1 +
 tests/chamelium/kms_chamelium_audio.c       |  2 +-
 tests/chamelium/kms_chamelium_edid.c        |  2 +-
 tests/chamelium/kms_chamelium_frames.c      |  2 +-
 tests/chamelium/kms_chamelium_hpd.c         |  2 +-
 tests/core_auth.c                           | 10 +--
 tests/core_getclient.c                      |  2 +-
 tests/core_getstats.c                       |  2 +-
 tests/core_getversion.c                     |  2 +-
 tests/core_setmaster.c                      |  6 +-
 tests/core_setmaster_vs_auth.c              |  6 +-
 tests/debugfs_test.c                        |  2 +-
 tests/dmabuf_sync_file.c                    |  3 +
 tests/dumb_buffer.c                         |  2 +-
 tests/eviction_common.c                     |  2 +-
 tests/fbdev.c                               |  2 +-
 tests/i915/api_intel_allocator.c            |  6 +-
 tests/i915/api_intel_bb.c                   |  2 +-
 tests/i915/drm_fdinfo.c                     |  2 +-
 tests/i915/gem_bad_reloc.c                  |  2 +-
 tests/i915/gem_barrier_race.c               |  5 +-
 tests/i915/gem_basic.c                      |  2 +-
 tests/i915/gem_blits.c                      |  2 +-
 tests/i915/gem_busy.c                       |  2 +-
 tests/i915/gem_caching.c                    |  2 +-
 tests/i915/gem_ccs.c                        |  2 +-
 tests/i915/gem_close_race.c                 | 14 ++---
 tests/i915/gem_concurrent_all.c             |  5 ++
 tests/i915/gem_cs_tlb.c                     |  2 +-
 tests/i915/gem_ctx_bad_destroy.c            |  2 +-
 tests/i915/gem_ctx_create.c                 |  4 +-
 tests/i915/gem_ctx_exec.c                   |  5 +-
 tests/i915/gem_ctx_freq.c                   |  3 +
 tests/i915/gem_ctx_param.c                  |  2 +-
 tests/i915/gem_ctx_persistence.c            |  6 +-
 tests/i915/gem_ctx_shared.c                 |  2 +-
 tests/i915/gem_ctx_sseu.c                   |  2 +-
 tests/i915/gem_ctx_switch.c                 |  2 +-
 tests/i915/gem_eio.c                        | 19 +++---
 tests/i915/gem_evict_alignment.c            |  2 +-
 tests/i915/gem_evict_everything.c           |  2 +-
 tests/i915/gem_exec_alignment.c             |  2 +-
 tests/i915/gem_exec_async.c                 |  2 +-
 tests/i915/gem_exec_await.c                 |  2 +-
 tests/i915/gem_exec_basic.c                 |  2 +-
 tests/i915/gem_exec_big.c                   |  2 +-
 tests/i915/gem_exec_capture.c               |  2 +-
 tests/i915/gem_exec_create.c                |  2 +-
 tests/i915/gem_exec_fair.c                  |  2 +-
 tests/i915/gem_exec_fence.c                 |  4 +-
 tests/i915/gem_exec_flush.c                 |  2 +-
 tests/i915/gem_exec_gttfill.c               |  4 +-
 tests/i915/gem_exec_latency.c               |  2 +-
 tests/i915/gem_exec_nop.c                   |  2 +-
 tests/i915/gem_exec_parallel.c              |  4 +-
 tests/i915/gem_exec_params.c                |  2 +-
 tests/i915/gem_exec_reloc.c                 |  2 +-
 tests/i915/gem_exec_schedule.c              |  2 +-
 tests/i915/gem_exec_store.c                 |  2 +-
 tests/i915/gem_exec_suspend.c               |  2 +-
 tests/i915/gem_exec_whisper.c               |  6 +-
 tests/i915/gem_exercise_blt.c               |  2 +-
 tests/i915/gem_fd_exhaustion.c              |  2 +-
 tests/i915/gem_fence_thrash.c               |  2 +-
 tests/i915/gem_fenced_exec_thrash.c         |  2 +-
 tests/i915/gem_flink_basic.c                |  4 +-
 tests/i915/gem_flink_race.c                 |  6 +-
 tests/i915/gem_gtt_cpu_tlb.c                |  2 +-
 tests/i915/gem_gtt_hog.c                    |  2 +-
 tests/i915/gem_gtt_speed.c                  |  2 +-
 tests/i915/gem_huc_copy.c                   |  2 +-
 tests/i915/gem_lmem_evict.c                 |  4 +-
 tests/i915/gem_lmem_swapping.c              | 10 +--
 tests/i915/gem_madvise.c                    | 12 ++--
 tests/i915/gem_media_fill.c                 |  2 +-
 tests/i915/gem_mmap.c                       |  2 +-
 tests/i915/gem_mmap_gtt.c                   |  6 +-
 tests/i915/gem_mmap_offset.c                |  8 +--
 tests/i915/gem_mmap_wc.c                    |  2 +-
 tests/i915/gem_partial_pwrite_pread.c       |  2 +-
 tests/i915/gem_pipe_control_store_loop.c    |  2 +-
 tests/i915/gem_ppgtt.c                      |  8 +--
 tests/i915/gem_pread.c                      |  2 +-
 tests/i915/gem_pread_after_blit.c           |  2 +-
 tests/i915/gem_pwrite.c                     |  2 +-
 tests/i915/gem_pwrite_snooped.c             |  2 +-
 tests/i915/gem_pxp.c                        |  2 +-
 tests/i915/gem_read_read_speed.c            |  2 +-
 tests/i915/gem_readwrite.c                  |  2 +-
 tests/i915/gem_reg_read.c                   |  2 +-
 tests/i915/gem_render_copy.c                |  2 +-
 tests/i915/gem_render_copy_redux.c          |  2 +-
 tests/i915/gem_reset_stats.c                | 32 +++++-----
 tests/i915/gem_ringfill.c                   |  2 +-
 tests/i915/gem_set_tiling_vs_blt.c          |  2 +-
 tests/i915/gem_set_tiling_vs_gtt.c          |  2 +-
 tests/i915/gem_set_tiling_vs_pwrite.c       |  2 +-
 tests/i915/gem_shrink.c                     | 14 ++---
 tests/i915/gem_softpin.c                    |  4 +-
 tests/i915/gem_spin_batch.c                 |  2 +-
 tests/i915/gem_streaming_writes.c           |  2 +-
 tests/i915/gem_stress.c                     |  2 +-
 tests/i915/gem_sync.c                       |  2 +-
 tests/i915/gem_tiled_blits.c                |  2 +-
 tests/i915/gem_tiled_fence_blits.c          |  2 +-
 tests/i915/gem_tiled_partial_pwrite_pread.c |  2 +-
 tests/i915/gem_tiled_pread_basic.c          |  2 +-
 tests/i915/gem_tiled_pread_pwrite.c         |  2 +-
 tests/i915/gem_tiled_swapping.c             |  2 +-
 tests/i915/gem_tiled_wb.c                   |  2 +-
 tests/i915/gem_tiled_wc.c                   |  2 +-
 tests/i915/gem_tiling_max_stride.c          |  2 +-
 tests/i915/gem_unfence_active_buffers.c     |  2 +-
 tests/i915/gem_unref_active_buffers.c       |  2 +-
 tests/i915/gem_userptr_blits.c              |  6 +-
 tests/i915/gem_vm_create.c                  |  4 +-
 tests/i915/gem_wait.c                       |  2 +-
 tests/i915/gem_watchdog.c                   |  2 +-
 tests/i915/gem_workarounds.c                |  2 +-
 tests/i915/gen7_exec_parse.c                |  4 +-
 tests/i915/gen9_exec_parse.c                |  2 +-
 tests/i915/i915_fb_tiling.c                 |  2 +-
 tests/i915/i915_getparams_basic.c           |  2 +-
 tests/i915/i915_hangman.c                   |  4 +-
 tests/i915/i915_hwmon.c                     |  2 +-
 tests/i915/i915_module_load.c               |  8 +--
 tests/i915/i915_pciid.c                     |  2 +-
 tests/i915/i915_pm_backlight.c              |  2 +-
 tests/i915/i915_pm_dc.c                     |  2 +-
 tests/i915/i915_pm_freq_api.c               |  2 +-
 tests/i915/i915_pm_freq_mult.c              |  2 +-
 tests/i915/i915_pm_lpsp.c                   |  2 +-
 tests/i915/i915_pm_rc6_residency.c          |  2 +-
 tests/i915/i915_pm_rps.c                    |  5 +-
 tests/i915/i915_pm_sseu.c                   |  2 +-
 tests/i915/i915_power.c                     |  2 +-
 tests/i915/i915_query.c                     |  2 +-
 tests/i915/i915_suspend.c                   |  6 +-
 tests/i915/kms_big_fb.c                     |  2 +-
 tests/i915/kms_big_joiner.c                 |  2 +-
 tests/i915/kms_busy.c                       |  2 +-
 tests/i915/kms_ccs.c                        |  2 +-
 tests/i915/kms_cdclk.c                      |  2 +-
 tests/i915/kms_draw_crc.c                   |  2 +-
 tests/i915/kms_dsc.c                        |  2 +-
 tests/i915/kms_fbcon_fbt.c                  |  2 +-
 tests/i915/kms_fence_pin_leak.c             |  2 +-
 tests/i915/kms_flip_scaled_crc.c            |  2 +-
 tests/i915/kms_flip_tiling.c                |  2 +-
 tests/i915/kms_frontbuffer_tracking.c       |  2 +-
 tests/i915/kms_legacy_colorkey.c            |  2 +-
 tests/i915/kms_mmap_write_crc.c             |  3 +-
 tests/i915/kms_pipe_b_c_ivb.c               |  2 +-
 tests/i915/kms_psr.c                        |  2 +-
 tests/i915/kms_psr2_sf.c                    |  2 +-
 tests/i915/kms_psr2_su.c                    |  2 +-
 tests/i915/kms_psr_stress_test.c            |  2 +-
 tests/i915/kms_pwrite_crc.c                 |  2 +-
 tests/i915/perf.c                           |  6 +-
 tests/i915/perf_pmu.c                       |  6 +-
 tests/i915/sysfs_defaults.c                 |  2 +-
 tests/i915/sysfs_heartbeat_interval.c       |  2 +-
 tests/i915/sysfs_preempt_timeout.c          |  2 +-
 tests/i915/sysfs_timeslice_duration.c       |  2 +-
 tests/kms_3d.c                              |  8 +--
 tests/kms_addfb_basic.c                     | 13 +---
 tests/kms_async_flips.c                     |  2 +-
 tests/kms_atomic.c                          |  2 +-
 tests/kms_atomic_interruptible.c            |  2 +-
 tests/kms_atomic_transition.c               |  2 +-
 tests/kms_color.c                           |  2 +-
 tests/kms_concurrent.c                      |  2 +-
 tests/kms_content_protection.c              |  2 +-
 tests/kms_cursor_crc.c                      |  2 +-
 tests/kms_cursor_edge_walk.c                |  2 +-
 tests/kms_cursor_legacy.c                   |  2 +-
 tests/kms_dither.c                          |  2 +-
 tests/kms_dp_aux_dev.c                      |  2 +-
 tests/kms_flip.c                            | 11 +---
 tests/kms_flip_event_leak.c                 |  8 +--
 tests/kms_force_connector_basic.c           |  4 +-
 tests/kms_getfb.c                           | 19 +-----
 tests/kms_hdmi_inject.c                     |  9 +--
 tests/kms_hdr.c                             |  2 +-
 tests/kms_invalid_mode.c                    |  2 +-
 tests/kms_lease.c                           |  4 +-
 tests/kms_panel_fitting.c                   |  2 +-
 tests/kms_pipe_crc_basic.c                  |  2 +-
 tests/kms_plane.c                           |  2 +-
 tests/kms_plane_alpha_blend.c               |  2 +-
 tests/kms_plane_cursor.c                    |  2 +-
 tests/kms_plane_lowres.c                    |  2 +-
 tests/kms_plane_multiple.c                  |  2 +-
 tests/kms_plane_scaling.c                   |  2 +-
 tests/kms_prime.c                           |  6 +-
 tests/kms_prop_blob.c                       |  8 +--
 tests/kms_properties.c                      |  2 +-
 tests/kms_rmfb.c                            |  4 +-
 tests/kms_rotation_crc.c                    |  2 +-
 tests/kms_scaling_modes.c                   |  2 +-
 tests/kms_sequence.c                        |  2 +-
 tests/kms_setmode.c                         |  9 +--
 tests/kms_tiled_display.c                   |  2 +-
 tests/kms_tv_load_detect.c                  |  2 +-
 tests/kms_universal_plane.c                 |  2 +-
 tests/kms_vblank.c                          |  2 +-
 tests/kms_vrr.c                             |  1 +
 tests/kms_writeback.c                       |  1 +
 tests/nouveau_crc.c                         |  6 +-
 tests/panfrost_gem_new.c                    |  4 +-
 tests/panfrost_get_param.c                  |  2 +-
 tests/panfrost_prime.c                      |  4 +-
 tests/panfrost_submit.c                     |  6 +-
 tests/prime_busy.c                          |  2 +-
 tests/prime_mmap.c                          |  2 +-
 tests/prime_mmap_coherency.c                |  4 +-
 tests/prime_mmap_kms.c                      |  2 +-
 tests/prime_self_import.c                   | 26 ++++----
 tests/prime_vgem.c                          |  4 +-
 tests/syncobj_basic.c                       |  2 +-
 tests/syncobj_timeline.c                    |  2 +-
 tests/syncobj_wait.c                        |  2 +-
 tests/template.c                            |  2 +-
 tests/testdisplay.c                         |  4 +-
 tests/v3d/v3d_create_bo.c                   |  4 +-
 tests/v3d/v3d_get_bo_offset.c               |  2 +-
 tests/v3d/v3d_get_param.c                   |  2 +-
 tests/v3d/v3d_job_submission.c              |  2 +-
 tests/v3d/v3d_mmap.c                        |  2 +-
 tests/v3d/v3d_perfmon.c                     |  2 +-
 tests/v3d/v3d_submit_cl.c                   |  2 +-
 tests/v3d/v3d_submit_csd.c                  |  2 +-
 tests/v3d/v3d_wait_bo.c                     |  2 +-
 tests/vc4/vc4_create_bo.c                   |  4 +-
 tests/vc4/vc4_dmabuf_poll.c                 |  2 +-
 tests/vc4/vc4_label_bo.c                    |  2 +-
 tests/vc4/vc4_lookup_fail.c                 |  2 +-
 tests/vc4/vc4_mmap.c                        |  2 +-
 tests/vc4/vc4_perfmon.c                     |  2 +-
 tests/vc4/vc4_purgeable_bo.c                |  2 +-
 tests/vc4/vc4_tiling.c                      |  2 +-
 tests/vc4/vc4_wait_bo.c                     |  2 +-
 tests/vc4/vc4_wait_seqno.c                  |  2 +-
 tests/vgem_basic.c                          |  6 +-
 tests/vgem_slow.c                           |  2 +-
 tests/vmwgfx/vmw_execution_buffer.c         |  2 +-
 tests/vmwgfx/vmw_ref_count.c                |  4 +-
 tests/vmwgfx/vmw_surface_copy.c             |  2 +-
 tests/xe/xe_compute.c                       | 10 +--
 tests/xe/xe_create.c                        | 13 ++--
 tests/xe/xe_debugfs.c                       | 10 +--
 tests/xe/xe_dma_buf_sync.c                  | 15 ++---
 tests/xe/xe_evict.c                         | 11 +---
 tests/xe/xe_exec_balancer.c                 | 10 +--
 tests/xe/xe_exec_basic.c                    | 10 +--
 tests/xe/xe_exec_compute_mode.c             | 10 +--
 tests/xe/xe_exec_fault_mode.c               |  7 +--
 tests/xe/xe_exec_reset.c                    | 31 +++-------
 tests/xe/xe_exec_threads.c                  | 28 +++------
 tests/xe/xe_gpgpu_fill.c                    |  4 +-
 tests/xe/xe_guc_pc.c                        |  4 +-
 tests/xe/xe_huc_copy.c                      | 10 +--
 tests/xe/xe_intel_bb.c                      |  4 +-
 tests/xe/xe_mmap.c                          | 10 +--
 tests/xe/xe_mmio.c                          | 10 +--
 tests/xe/xe_module_load.c                   |  2 +-
 tests/xe/xe_noexec_ping_pong.c              |  4 +-
 tests/xe/xe_pm.c                            |  5 +-
 tests/xe/xe_prime_self_import.c             | 61 +++++-------------
 tests/xe/xe_query.c                         | 10 +--
 tests/xe/xe_spin_batch.c                    | 10 +--
 tests/xe/xe_vm.c                            |  7 +--
 tests/xe/xe_waitfence.c                     | 10 +--
 292 files changed, 581 insertions(+), 662 deletions(-)

--
2.40.0

#1 lore raw

PATCH v4 1/24 lib: Interface to close the drm fd

Add new helper drm_close_driver() to close the drm fd. Now every user could call drm_close_driver() instead of close().

V2: - Fix commit message
- Add debug prints
V3: - Check the validity of fd before close
V4: - s/igt_debug/igt_warn/

---
 lib/drmtest.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 lib/drmtest.h |  1 +
 2 files changed, 45 insertions(+)
lib/drmtest.c +44 -0
index 220cfb64d..a226ebd91 100644
@@ -636,6 +636,50 @@ int drm_open_driver(int chipset)
 	return fd;
 }
 
+static bool is_valid_fd(int fd)
+{
+	char path[32];
+	char buf[PATH_MAX];
+	int len;
+
+	if (fd < 0)
+		return false;
+
+	snprintf(path, sizeof(path), "/proc/self/fd/%d", fd);
+
+	memset(buf, 0, sizeof(buf));
+	len = readlink(path, buf, sizeof(buf) - 1);
+	if (len <= 0)
+		return false;
+
+	buf[len] = '\0';
+	if (strstr(buf, "/dev/dri/card") == buf ||
+	    strstr(buf, "/dev/dri/renderD") == buf)
+		return true;
+
+	return false;
+}
+
+/**
+ * drm_close_driver:
+ * @fd: a drm file descriptor
+ *
+ * Check the given drm file descriptor @fd is valid & Close if it is
+ * an valid drm fd.
+ *
+ * Returns: 0 on success or -1 on error.
+ */
+int drm_close_driver(int fd)
+{
+	if (!is_valid_fd(fd)) {
+		igt_warn("Don't attempt to close standard/invalid file "
+			 "descriptor: %d\n", fd);
+		return -1;
+	}
+
+	return close(fd);
+}
+
 /**
  * drm_open_driver_master:
  * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
lib/drmtest.h +1 -0
index ae86ee19a..9c3ea5d14 100644
@@ -105,6 +105,7 @@ int drm_open_driver_render(int chipset);
 int __drm_open_driver_another(int idx, int chipset);
 int __drm_open_driver(int chipset);
 int __drm_open_driver_render(int chipset);
+int drm_close_driver(int fd);
 
 int drm_reopen_driver(int fd);
 
Signature · 1 line
2.40.0
#2 lore raw

PATCH v4 2/24 lib: Cache xe_device at driver open/close level

In reply to Bhanuprakash Modem

Instead of caching the xe_device struct at subtest level, cache just after opening the driver. And remove from the cache just before closing the driver.

V2: - Place the logic in correct helpers (Zbigniew)

---
 lib/drmtest.c   | 24 +++++++++++++++++++++---
 lib/igt_types.c |  6 ++++++
 2 files changed, 27 insertions(+), 3 deletions(-)
lib/drmtest.c +21 -3
index a226ebd91..5cdb0196d 100644
@@ -64,6 +64,7 @@
 #include "intel_reg.h"
 #include "ioctl_wrappers.h"
 #include "igt_dummyload.h"
+#include "xe/xe_query.h"
 
 /**
  * SECTION:drmtest
@@ -497,9 +498,14 @@ int __drm_open_driver_another(int idx, int chipset)
 		fd = __open_driver("/dev/dri/card", 0, chipset, idx);
 	}
 
-	if (fd >= 0)
+	if (fd >= 0) {
 		_set_opened_fd(idx, fd);
 
+		/* Cache xe_device struct. */
+		if (is_xe_device(fd))
+			xe_device_get(fd);
+	}
+
 	return fd;
 }
 
@@ -523,6 +529,8 @@ int __drm_open_driver(int chipset)
 
 int __drm_open_driver_render(int chipset)
 {
+	int fd;
+
 	if (chipset != DRIVER_VGEM && igt_device_filter_count() > 0) {
 		struct igt_device_card card;
 		bool found;
@@ -532,10 +540,16 @@ int __drm_open_driver_render(int chipset)
 		if (!found || !strlen(card.render))
 			return -1;
 
-		return __open_driver_exact(card.render, chipset);
+		fd = __open_driver_exact(card.render, chipset);
+	} else {
+		fd = __open_driver("/dev/dri/renderD", 128, chipset, 0);
 	}
 
-	return __open_driver("/dev/dri/renderD", 128, chipset, 0);
+	/* Cache xe_device struct. */
+	if (fd >= 0 && is_xe_device(fd))
+		xe_device_get(fd);
+
+	return fd;
 }
 
 static int at_exit_drm_fd = -1;
@@ -677,6 +691,10 @@ int drm_close_driver(int fd)
 		return -1;
 	}
 
+	/* Remove xe_device from cache. */
+	if (is_xe_device(fd))
+		xe_device_put(fd);
+
 	return close(fd);
 }
 
lib/igt_types.c +6 -0
index 392f30fca..d5d444889 100644
@@ -5,13 +5,19 @@
 
 #include <unistd.h>
 
+#include "drmtest.h"
 #include "igt_types.h"
+#include "xe/xe_query.h"
 
 void igt_cleanup_fd(volatile int *fd)
 {
 	if (!fd || *fd < 0)
 		return;
 
+	/* Remove xe_device from cache. */
+	if (is_xe_device(*fd))
+		xe_device_put(*fd);
+
 	close(*fd);
 	*fd = -1;
 }
Signature · 1 line
2.40.0
#3 lore raw

PATCH v4 3/24 lib/xe/xe_query: Add xe_config() interface

In reply to Bhanuprakash Modem

Add support to get XE configuration from xe_device.

---
 lib/xe/xe_query.c | 8 ++++++++
 lib/xe/xe_query.h | 1 +
 2 files changed, 9 insertions(+)
lib/xe/xe_query.c +8 -0
index 47be8f301..48fb5afba 100644
@@ -479,6 +479,14 @@ uint32_t xe_min_page_size(int fd, uint64_t region)
 	return xe_mem_region(fd, region)->min_page_size;
 }
 
+/**
+ * xe_config:
+ * @fd: xe device fd
+ *
+ * Returns xe configuration of xe device @fd.
+ */
+xe_dev_FN(xe_config, config, struct drm_xe_query_config *);
+
 /**
  * xe_number_hw_engine:
  * @fd: xe device fd
lib/xe/xe_query.h +1 -0
index 943ca558a..3cbf32668 100644
@@ -86,6 +86,7 @@ struct drm_xe_engine_class_instance *xe_hw_engine(int fd, int idx);
 struct drm_xe_query_mem_region *xe_mem_region(int fd, uint64_t region);
 const char *xe_region_name(uint64_t region);
 uint32_t xe_min_page_size(int fd, uint64_t region);
+struct drm_xe_query_config *xe_config(int fd);
 unsigned int xe_number_hw_engines(int fd);
 bool xe_has_vram(int fd);
 uint64_t xe_vram_size(int fd, int gt);
Signature · 1 line
2.40.0
#4 lore raw

PATCH v4 4/24 lib/igt_msm: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 lib/igt_msm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/igt_msm.c +1 -1
index 8c0380f42..a236898b6 100644
@@ -87,7 +87,7 @@ igt_msm_dev_close(struct msm_device *dev)
 {
 	if (!dev)
 		return;
-	close(dev->fd);
+	drm_close_driver(dev->fd);
 	free(dev);
 }
 
Signature · 1 line
2.40.0
Reviewed-by on v4 4/24
#5 lore raw

Re: [igt-dev] [V4 i-g-t 04/24] lib/igt_msm: Use drm_close_driver() to close the drm fd

Hi Bhanuprakash,

Quoted 6 lines · Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

Quoted 20 lines
---
 lib/igt_msm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/igt_msm.c +1 -1
index 8c0380f42..a236898b6 100644
@@ -87,7 +87,7 @@ igt_msm_dev_close(struct msm_device *dev)
 {
 	if (!dev)
 		return;
-	close(dev->fd);
+	drm_close_driver(dev->fd);
 	free(dev);
 }
 
Signature · 1 line
2.40.0
#6 lore raw

PATCH v4 5/24 tests/amdgpu: Close the fd before exit

In reply to Bhanuprakash Modem

Close the file descriptor before exiting the test.

---
 tests/amdgpu/amd_abm.c                 | 1 +
 tests/amdgpu/amd_assr.c                | 1 +
 tests/amdgpu/amd_freesync_video_mode.c | 1 +
 tests/amdgpu/amd_mem_leak.c            | 1 +
 tests/amdgpu/amd_psr.c                 | 3 ++-
 tests/amdgpu/amd_vrr_range.c           | 1 +
 6 files changed, 7 insertions(+), 1 deletion(-)
tests/amdgpu/amd_abm.c +1 -0
index 9400ed806..082da7ed6 100644
@@ -378,5 +378,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/amdgpu/amd_assr.c +1 -0
index 80cbbe8e9..fc2367f99 100644
@@ -299,5 +299,6 @@ igt_main
 	igt_fixture
 	{
 		igt_display_fini(&data.display);
+		drm_close_driver(data.fd);
 	}
 }
tests/amdgpu/amd_freesync_video_mode.c +1 -0
index 579d24436..62d42a06c 100644
@@ -868,5 +868,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/amdgpu/amd_mem_leak.c +1 -0
index dee563cbe..e4a4b5c47 100644
@@ -232,5 +232,6 @@ igt_main
 	igt_fixture
 	{
 		igt_display_fini(&data.display);
+		drm_close_driver(data.fd);
 	}
 }
tests/amdgpu/amd_psr.c +2 -1
index 966a0dccf..3932e143a 100644
@@ -640,7 +640,7 @@ static void run_check_psr_su_cursor(data_t *data, bool test_mpo)
 	 * panning the primary plane at the top-left of screen
 	 * set alpha region in overlay plane and set alpha to 0.0 to show primary plane
 	 * set cursor plane and starting from position of (0, 0)
-	 */ 
+	 */
 	draw_color_alpha(&data->ov_fb[0], 0, 0, data->pfb_w, data->pfb_h, 1.0, 1.0, 1.0, .0);
 	igt_plane_set_fb(data->primary, &data->pm_fb[0]);
 	igt_plane_set_fb(data->overlay, &data->ov_fb[0]);
@@ -763,5 +763,6 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 		}
 		close(data.debugfs_fd);
 		igt_display_fini(&data.display);
+		drm_close_driver(data.fd);
 	}
 }
tests/amdgpu/amd_vrr_range.c +1 -0
index 611f41f95..a77895622 100644
@@ -408,5 +408,6 @@ igt_main
 	igt_fixture
 	{
 		igt_display_fini(&data.display);
+		drm_close_driver(data.fd);
 	}
 }
Signature · 1 line
2.40.0
#7 lore raw

PATCH v4 6/24 tests/i915: Close the fd before exit

In reply to Bhanuprakash Modem

Close the file descriptor before exiting the test.

V2: - Drop tests those are initializing the fd with igt_fd_t

---
 tests/dmabuf_sync_file.c        | 3 +++
 tests/i915/gem_barrier_race.c   | 3 +++
 tests/i915/gem_concurrent_all.c | 5 +++++
 tests/i915/gem_ctx_exec.c       | 3 +++
 tests/i915/gem_ctx_freq.c       | 3 +++
 tests/i915/gem_eio.c            | 3 +++
 tests/i915/i915_pm_rps.c        | 3 +++
 7 files changed, 23 insertions(+)
tests/dmabuf_sync_file.c +3 -0
index 25bb6ad75..cfa73117b 100644
@@ -380,4 +380,7 @@ igt_main
 		     "operations.");
 	igt_subtest("import-multiple-read-write")
 		test_import_multiple(fd, true);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_barrier_race.c +3 -0
index be71d20e7..0ac1da3a4 100644
@@ -165,4 +165,7 @@ igt_main
 			break;
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_concurrent_all.c +5 -0
index fb3b5f5d8..0bf46c0a2 100644
@@ -2015,4 +2015,9 @@ igt_main
 			}
 		}
 	}
+
+	igt_fixture {
+		drm_close_driver(fd);
+		drm_close_driver(vgem_drv);
+	}
 }
tests/i915/gem_ctx_exec.c +3 -0
index bd6671ec8..f3939df86 100644
@@ -605,4 +605,7 @@ igt_main
 		gem_context_destroy(fd, ctx_id);
 		put_ahnd(ahnd);
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_freq.c +3 -0
index d15f83600..8c0d7db3c 100644
@@ -261,4 +261,7 @@ igt_main
 			igt_dynamic_f("gt%u", gt)
 				sysfs_range(dirfd, gt);
 	}
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_eio.c +3 -0
index a5ebe6d2d..38fd19e89 100644
@@ -1321,4 +1321,7 @@ igt_main
 			intel_allocator_multiprocess_stop();
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/i915_pm_rps.c +3 -0
index eaacc7c90..238d39240 100644
@@ -999,4 +999,7 @@ igt_main
 		waitboost(drm_fd, true);
 		igt_disallow_hang(drm_fd, hang);
 	}
+
+	igt_fixture
+		drm_close_driver(drm_fd);
 }
Signature · 1 line
2.40.0
Reviewed-by on v4 6/24
#8 lore raw

Re: [igt-dev] [V4 i-g-t 06/24] tests/i915: Close the fd before exit

Hi Bhanuprakash,

Quoted 5 lines · Bhanuprakash Modem

Close the file descriptor before exiting the test.

V2: - Drop tests those are initializing the fd with igt_fd_t

Quoted 99 lines
---
 tests/dmabuf_sync_file.c        | 3 +++
 tests/i915/gem_barrier_race.c   | 3 +++
 tests/i915/gem_concurrent_all.c | 5 +++++
 tests/i915/gem_ctx_exec.c       | 3 +++
 tests/i915/gem_ctx_freq.c       | 3 +++
 tests/i915/gem_eio.c            | 3 +++
 tests/i915/i915_pm_rps.c        | 3 +++
 7 files changed, 23 insertions(+)
tests/dmabuf_sync_file.c +3 -0
index 25bb6ad75..cfa73117b 100644
@@ -380,4 +380,7 @@ igt_main
 		     "operations.");
 	igt_subtest("import-multiple-read-write")
 		test_import_multiple(fd, true);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_barrier_race.c +3 -0
index be71d20e7..0ac1da3a4 100644
@@ -165,4 +165,7 @@ igt_main
 			break;
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_concurrent_all.c +5 -0
index fb3b5f5d8..0bf46c0a2 100644
@@ -2015,4 +2015,9 @@ igt_main
 			}
 		}
 	}
+
+	igt_fixture {
+		drm_close_driver(fd);
+		drm_close_driver(vgem_drv);
+	}
 }
tests/i915/gem_ctx_exec.c +3 -0
index bd6671ec8..f3939df86 100644
@@ -605,4 +605,7 @@ igt_main
 		gem_context_destroy(fd, ctx_id);
 		put_ahnd(ahnd);
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_freq.c +3 -0
index d15f83600..8c0d7db3c 100644
@@ -261,4 +261,7 @@ igt_main
 			igt_dynamic_f("gt%u", gt)
 				sysfs_range(dirfd, gt);
 	}
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_eio.c +3 -0
index a5ebe6d2d..38fd19e89 100644
@@ -1321,4 +1321,7 @@ igt_main
 			intel_allocator_multiprocess_stop();
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/i915_pm_rps.c +3 -0
index eaacc7c90..238d39240 100644
@@ -999,4 +999,7 @@ igt_main
 		waitboost(drm_fd, true);
 		igt_disallow_hang(drm_fd, hang);
 	}
+
+	igt_fixture
+		drm_close_driver(drm_fd);
 }
Signature · 1 line
2.40.0
#9 lore raw

PATCH v4 7/24 tests/kms: Close the fd before exit

In reply to Bhanuprakash Modem

Close the file descriptor before exiting the test.

---
 tests/kms_vrr.c       | 1 +
 tests/kms_writeback.c | 1 +
 2 files changed, 2 insertions(+)
tests/kms_vrr.c +1 -0
index d2d79c4eb..6a766bfb9 100644
@@ -528,5 +528,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_writeback.c +1 -0
index c4808b02c..db1f0884f 100644
@@ -606,5 +606,6 @@ igt_main_args("b:c:dl", long_options, help_str, opt_handler, NULL)
 		detach_crtc(&display, output);
 		igt_remove_fb(display.drm_fd, &input_fb);
 		igt_display_fini(&display);
+		drm_close_driver(display.drm_fd);
 	}
 }
Signature · 1 line
2.40.0
Reviewed-by on v4 7/24
#10 lore raw

Re: [igt-dev] [V4 i-g-t 07/24] tests/kms: Close the fd before exit

Hi Bhanuprakash,

Quoted 3 lines · Bhanuprakash Modem

Close the file descriptor before exiting the test.

Quoted 30 lines
---
 tests/kms_vrr.c       | 1 +
 tests/kms_writeback.c | 1 +
 2 files changed, 2 insertions(+)
tests/kms_vrr.c +1 -0
index d2d79c4eb..6a766bfb9 100644
@@ -528,5 +528,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_writeback.c +1 -0
index c4808b02c..db1f0884f 100644
@@ -606,5 +606,6 @@ igt_main_args("b:c:dl", long_options, help_str, opt_handler, NULL)
 		detach_crtc(&display, output);
 		igt_remove_fb(display.drm_fd, &input_fb);
 		igt_display_fini(&display);
+		drm_close_driver(display.drm_fd);
 	}
 }
Signature · 1 line
2.40.0
#11 lore raw

PATCH v4 8/24 tests/nouveau_crc: Close the fd before exit

In reply to Bhanuprakash Modem

Close the file descriptor before exiting the test.

---
 tests/nouveau_crc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tests/nouveau_crc.c +4 -2
index 785d39bde..d5aa0e650 100644
@@ -409,7 +409,9 @@ igt_main
 			close(data.nv_crc_dir);
 		}
 	}
-	igt_fixture
-		igt_display_fini(&data.display);
 
+	igt_fixture {
+		igt_display_fini(&data.display);
+		drm_close_driver(data.drm_fd);
+	}
 }
Signature · 1 line
2.40.0
#12 lore raw

PATCH v4 9/24 tests/xe/xe_gpgpu_fill: Close the fd before exit

In reply to Bhanuprakash Modem

Close the file descriptor before exiting the test.

---
 tests/xe/xe_gpgpu_fill.c | 1 +
 1 file changed, 1 insertion(+)
tests/xe/xe_gpgpu_fill.c +1 -0
index 992fb92ad..12bf7c5fc 100644
@@ -131,5 +131,6 @@ igt_main
 	igt_fixture {
 		xe_device_put(data.drm_fd);
 		buf_ops_destroy(data.bops);
+		drm_close_driver(data.drm_fd);
 	}
 }
Signature · 1 line
2.40.0
#13 lore raw

PATCH v4 10/24 tests/i915/kms_mmap_write_crc: Avoid closing the closed fd

In reply to Bhanuprakash Modem

Avoid closing the closed fd.

---
 tests/i915/kms_mmap_write_crc.c | 1 -
 1 file changed, 1 deletion(-)
tests/i915/kms_mmap_write_crc.c +0 -1
index 87f511531..07bd542dc 100644
@@ -309,6 +309,5 @@ igt_main_args("n", NULL, NULL, opt_handler, NULL)
 		close(data.drm_fd);
 
 		igt_stop_helper(&hog);
-		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.40.0
#14 lore raw

PATCH v4 11/24 tests/i915/gem_close_race: Fix the double closure of fd

In reply to Bhanuprakash Modem

Don't close the fd in each thread, instead leave it to be closed by process termination

---
 tests/i915/gem_close_race.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/i915/gem_close_race.c +1 -1
index 1a2efeab2..22cdc5874 100644
@@ -303,7 +303,7 @@ static void thread(int fd, struct drm_gem_open name,
 			n++;
 		} while (1);
 
-		close(crashme.fd);
+		/* leave fd to be closed by process termination */
 	}
 
 	timer_delete(timer);
Signature · 1 line
2.40.0
Reviewed-by on v4 11/24
#15 lore raw

Re: [igt-dev] [V4 i-g-t 11/24] tests/i915/gem_close_race: Fix the double closure of fd

Hi Bhanuprakash,

Quoted 4 lines · Bhanuprakash Modem

Don't close the fd in each thread, instead leave it to be closed by process termination

Quoted 20 lines
---
 tests/i915/gem_close_race.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/i915/gem_close_race.c +1 -1
index 1a2efeab2..22cdc5874 100644
@@ -303,7 +303,7 @@ static void thread(int fd, struct drm_gem_open name,
 			n++;
 		} while (1);
 
-		close(crashme.fd);
+		/* leave fd to be closed by process termination */
 	}
 
 	timer_delete(timer);
Signature · 1 line
2.40.0
#16 lore raw

PATCH v4 12/24 tests: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 tests/core_auth.c              | 10 +++++-----
 tests/core_getclient.c         |  2 +-
 tests/core_getstats.c          |  2 +-
 tests/core_getversion.c        |  2 +-
 tests/core_setmaster.c         |  6 +++---
 tests/core_setmaster_vs_auth.c |  6 +++---
 tests/debugfs_test.c           |  2 +-
 tests/dumb_buffer.c            |  2 +-
 tests/eviction_common.c        |  2 +-
 tests/fbdev.c                  |  2 +-
 tests/prime_busy.c             |  2 +-
 tests/prime_mmap.c             |  2 +-
 tests/prime_mmap_coherency.c   |  4 ++--
 tests/prime_mmap_kms.c         |  2 +-
 tests/prime_self_import.c      | 26 +++++++++++++-------------
 tests/prime_vgem.c             |  4 ++--
 tests/syncobj_basic.c          |  2 +-
 tests/syncobj_timeline.c       |  2 +-
 tests/syncobj_wait.c           |  2 +-
 tests/template.c               |  2 +-
 tests/vgem_basic.c             |  6 +++---
 tests/vgem_slow.c              |  2 +-
 22 files changed, 46 insertions(+), 46 deletions(-)
tests/core_auth.c +5 -5
index ed736e1ae..bc1b3b8d5 100644
@@ -214,7 +214,7 @@ static void test_basic_auth(int master)
 	igt_assert(drmGetMagic(slave, &magic) == 0);
 	igt_assert_eq(magic, old_magic);
 
-	close(slave);
+	drm_close_driver(slave);
 }
 
 igt_main
@@ -226,7 +226,7 @@ igt_main
 
 		igt_assert(check_auth(fd) == true);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Use 2 clients, check second is authenticated even when first dropped.");
@@ -236,11 +236,11 @@ igt_main
 
 		igt_assert(check_auth(fd2) == true);
 
-		close(fd);
+		drm_close_driver(fd);
 
 		igt_assert(check_auth(fd2) == true);
 
-		close(fd2);
+		drm_close_driver(fd2);
 	}
 
 	/* above tests require that no drm fd is open */
@@ -249,7 +249,7 @@ igt_main
 
 		igt_fixture
 			master = drm_open_driver_master(DRIVER_ANY);
-	
+
 		igt_describe("Test magic numbers for master and slave.");
 		igt_subtest("basic-auth")
 			test_basic_auth(master);
tests/core_getclient.c +1 -1
index 993801ead..839fae36a 100644
@@ -70,5 +70,5 @@ igt_simple_main
 	ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
 	igt_assert(ret == -1 && errno == EINVAL);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_getstats.c +1 -1
index fef122583..8b5655053 100644
@@ -64,5 +64,5 @@ igt_simple_main
 	ret = ioctl(fd, DRM_IOCTL_GET_STATS, &stats);
 	igt_assert(ret == 0);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_getversion.c +1 -1
index 36ba01b86..32cb976e4 100644
@@ -58,5 +58,5 @@ igt_simple_main
 		igt_assert_lte(1, v->version_major);
 
 	drmFree(v);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_setmaster.c +3 -3
index 621bc2469..04ee6b8b5 100644
@@ -104,7 +104,7 @@ static void check_drop_set(void)
 	igt_assert_eq(drmDropMaster(master), 0);
 	igt_assert_eq(drmSetMaster(master), 0);
 
-	close(master);
+	drm_close_driver(master);
 }
 
 static unsigned tweak_perm(uint8_t *saved_perm, unsigned max_perm, bool save)
@@ -225,10 +225,10 @@ igt_main
 			igt_assert_eq(drmSetMaster(master), -1);
 			igt_assert_eq(errno, EACCES);
 
-			close(master);
+			drm_close_driver(master);
 		}
 		igt_waitchildren();
 
-		close(master);
+		drm_close_driver(master);
 	}
 }
tests/core_setmaster_vs_auth.c +3 -3
index adca1c111..b80ed3879 100644
@@ -78,7 +78,7 @@ igt_simple_main
 	igt_assert_neq(drmAuthMagic(master2, magic), 0);
 	igt_assert_eq(errno, EINVAL);
 
-	close(client);
-	close(master2);
-	close(master1);
+	drm_close_driver(client);
+	drm_close_driver(master2);
+	drm_close_driver(master1);
 }
tests/debugfs_test.c +1 -1
index 5ee615aba..b67bfabac 100644
@@ -255,6 +255,6 @@ igt_main
 	igt_fixture {
 		close(sysfs);
 		close(debugfs);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/dumb_buffer.c +1 -1
index 9495d28ff..9db857f9f 100644
@@ -416,6 +416,6 @@ igt_main
 		always_clear(fd, 30);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/eviction_common.c +1 -1
index 95af106c1..5948fbc64 100644
@@ -300,7 +300,7 @@ static int forking_evictions(int fd, struct igt_eviction_test_ops *ops,
 
 		/* drmfd closing will take care of additional bo refs */
 		if (flags & FORKING_EVICTIONS_DUP_DRMFD)
-			close(realfd);
+			drm_close_driver(realfd);
 	}
 
 	igt_waitchildren();
tests/fbdev.c +1 -1
index 794882a6a..154e78b0f 100644
@@ -443,6 +443,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_busy.c +1 -1
index 6b0d7310b..90d79864f 100644
@@ -184,6 +184,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap.c +1 -1
index efd4deff9..25b2939e9 100644
@@ -590,6 +590,6 @@ igt_main
 		free(query_info);
 		igt_collection_destroy(set);
 		igt_collection_destroy(dma_buf_set);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap_coherency.c +2 -2
index e5f7c92b2..01eb2002d 100644
@@ -267,7 +267,7 @@ static void blit_and_cmp(void)
 
 	intel_bb_destroy(local_batch);
 	buf_ops_destroy(local_bops);
-	close(local_fd);
+	drm_close_driver(local_fd);
 }
 
 /*
@@ -364,6 +364,6 @@ igt_main
 	igt_fixture {
 		buf_ops_destroy(bops);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap_kms.c +1 -1
index 8b127a13c..1a63be38f 100644
@@ -263,6 +263,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&gpu.display);
-		close(gpu.drm_fd);
+		drm_close_driver(gpu.drm_fd);
 	}
 }
tests/prime_self_import.c +13 -13
index 30f2bf013..2dbf4e20f 100644
@@ -147,8 +147,8 @@ static void test_with_fd_dup(void)
 	close(dma_buf_fd2);
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static void test_with_two_bos(void)
@@ -180,8 +180,8 @@ static void test_with_two_bos(void)
 
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static void test_with_one_bo_two_files(void)
@@ -205,8 +205,8 @@ static void test_with_one_bo_two_files(void)
 	/* dma-buf self importing an flink bo should give the same handle */
 	igt_assert_eq_u32(handle_import, handle_open);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 	close(dma_buf_fd1);
 	close(dma_buf_fd2);
 }
@@ -252,7 +252,7 @@ static void test_with_one_bo(void)
 	check_bo(fd1, handle, fd2, handle_import1);
 
 	/* Completely rip out exporting fd. */
-	close(fd1);
+	drm_close_driver(fd1);
 	check_bo(fd2, handle_import1, fd2, handle_import1);
 }
 
@@ -316,14 +316,14 @@ static void test_reimport_close_race(void)
 		igt_assert(status == 0);
 	}
 
-	close(fds[0]);
+	drm_close_driver(fds[0]);
 	close(fds[1]);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -398,13 +398,13 @@ static void test_export_close_race(void)
 		igt_assert(status == 0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -433,7 +433,7 @@ static void test_llseek_size(void)
 		close(dma_buf_fd);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_llseek_bad(void)
@@ -462,7 +462,7 @@ static void test_llseek_bad(void)
 
 	close(dma_buf_fd);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
tests/prime_vgem.c +2 -2
index 85b9cf880..876e04ed0 100644
@@ -1326,7 +1326,7 @@ igt_main
 
 
 	igt_fixture {
-		close(i915);
-		close(vgem);
+		drm_close_driver(i915);
+		drm_close_driver(vgem);
 	}
 }
tests/syncobj_basic.c +1 -1
index 3252dbd69..f079baf09 100644
@@ -266,7 +266,7 @@ igt_main
 		test_valid_cycle(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 }
tests/syncobj_timeline.c +1 -1
index 134a60995..b4e1d093a 100644
@@ -1936,6 +1936,6 @@ igt_main
 		test_32bits_limit(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/syncobj_wait.c +1 -1
index 2583ef72e..e0ff69b79 100644
@@ -1062,6 +1062,6 @@ igt_main
 		test_wait_interrupted(fd, WAIT_ALL);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/template.c +1 -1
index e23814fb7..ae2681c01 100644
@@ -76,6 +76,6 @@ igt_main
 	 */
 
 	igt_fixture {
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/vgem_basic.c +3 -3
index f2255a619..63c5c0971 100644
@@ -162,8 +162,8 @@ static void test_setversion(int fd)
 
 static void test_client(int fd)
 {
-	close(drm_open_driver(DRIVER_VGEM));
-	close(drm_open_driver_render(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver_render(DRIVER_VGEM));
 }
 
 static void test_create(int fd)
@@ -635,6 +635,6 @@ igt_main
 		test_debugfs_read(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/vgem_slow.c +1 -1
index 0c91cdb9d..cb9436628 100644
@@ -97,6 +97,6 @@ igt_main
 		test_nohang(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#17 lore raw

Re: [igt-dev] [V4 i-g-t 12/24] tests: Use drm_close_driver() to close the drm fd

Hi Bhanuprakash,

Quoted 66 lines · Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 tests/core_auth.c              | 10 +++++-----
 tests/core_getclient.c         |  2 +-
 tests/core_getstats.c          |  2 +-
 tests/core_getversion.c        |  2 +-
 tests/core_setmaster.c         |  6 +++---
 tests/core_setmaster_vs_auth.c |  6 +++---
 tests/debugfs_test.c           |  2 +-
 tests/dumb_buffer.c            |  2 +-
 tests/eviction_common.c        |  2 +-
 tests/fbdev.c                  |  2 +-
 tests/prime_busy.c             |  2 +-
 tests/prime_mmap.c             |  2 +-
 tests/prime_mmap_coherency.c   |  4 ++--
 tests/prime_mmap_kms.c         |  2 +-
 tests/prime_self_import.c      | 26 +++++++++++++-------------
 tests/prime_vgem.c             |  4 ++--
 tests/syncobj_basic.c          |  2 +-
 tests/syncobj_timeline.c       |  2 +-
 tests/syncobj_wait.c           |  2 +-
 tests/template.c               |  2 +-
 tests/vgem_basic.c             |  6 +++---
 tests/vgem_slow.c              |  2 +-
 22 files changed, 46 insertions(+), 46 deletions(-)
tests/core_auth.c +4 -4
index ed736e1ae..bc1b3b8d5 100644
@@ -214,7 +214,7 @@ static void test_basic_auth(int master)
 	igt_assert(drmGetMagic(slave, &magic) == 0);
 	igt_assert_eq(magic, old_magic);
 
-	close(slave);
+	drm_close_driver(slave);
 }
 
 igt_main
@@ -226,7 +226,7 @@ igt_main
 
 		igt_assert(check_auth(fd) == true);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Use 2 clients, check second is authenticated even when first dropped.");
@@ -236,11 +236,11 @@ igt_main
 
 		igt_assert(check_auth(fd2) == true);
 
-		close(fd);
+		drm_close_driver(fd);
 
 		igt_assert(check_auth(fd2) == true);
 
-		close(fd2);
+		drm_close_driver(fd2);
 	}
 
 	/* above tests require that no drm fd is open */

tests/core_auth.c igt_main · line 252

Quoted 5 lines
tests/core_auth.c +1 -1
@@ -249,7 +249,7 @@ igt_main
 
 		igt_fixture
 			master = drm_open_driver_master(DRIVER_ANY);
-	
+

Drop this change.

Quoted 230 lines
tests/core_auth.c +0 -0
 		igt_describe("Test magic numbers for master and slave.");
 		igt_subtest("basic-auth")
 			test_basic_auth(master);
tests/core_getclient.c +1 -1
index 993801ead..839fae36a 100644
@@ -70,5 +70,5 @@ igt_simple_main
 	ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
 	igt_assert(ret == -1 && errno == EINVAL);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_getstats.c +1 -1
index fef122583..8b5655053 100644
@@ -64,5 +64,5 @@ igt_simple_main
 	ret = ioctl(fd, DRM_IOCTL_GET_STATS, &stats);
 	igt_assert(ret == 0);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_getversion.c +1 -1
index 36ba01b86..32cb976e4 100644
@@ -58,5 +58,5 @@ igt_simple_main
 		igt_assert_lte(1, v->version_major);
 
 	drmFree(v);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_setmaster.c +3 -3
index 621bc2469..04ee6b8b5 100644
@@ -104,7 +104,7 @@ static void check_drop_set(void)
 	igt_assert_eq(drmDropMaster(master), 0);
 	igt_assert_eq(drmSetMaster(master), 0);
 
-	close(master);
+	drm_close_driver(master);
 }
 
 static unsigned tweak_perm(uint8_t *saved_perm, unsigned max_perm, bool save)
@@ -225,10 +225,10 @@ igt_main
 			igt_assert_eq(drmSetMaster(master), -1);
 			igt_assert_eq(errno, EACCES);
 
-			close(master);
+			drm_close_driver(master);
 		}
 		igt_waitchildren();
 
-		close(master);
+		drm_close_driver(master);
 	}
 }
tests/core_setmaster_vs_auth.c +3 -3
index adca1c111..b80ed3879 100644
@@ -78,7 +78,7 @@ igt_simple_main
 	igt_assert_neq(drmAuthMagic(master2, magic), 0);
 	igt_assert_eq(errno, EINVAL);
 
-	close(client);
-	close(master2);
-	close(master1);
+	drm_close_driver(client);
+	drm_close_driver(master2);
+	drm_close_driver(master1);
 }
tests/debugfs_test.c +1 -1
index 5ee615aba..b67bfabac 100644
@@ -255,6 +255,6 @@ igt_main
 	igt_fixture {
 		close(sysfs);
 		close(debugfs);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/dumb_buffer.c +1 -1
index 9495d28ff..9db857f9f 100644
@@ -416,6 +416,6 @@ igt_main
 		always_clear(fd, 30);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/eviction_common.c +1 -1
index 95af106c1..5948fbc64 100644
@@ -300,7 +300,7 @@ static int forking_evictions(int fd, struct igt_eviction_test_ops *ops,
 
 		/* drmfd closing will take care of additional bo refs */
 		if (flags & FORKING_EVICTIONS_DUP_DRMFD)
-			close(realfd);
+			drm_close_driver(realfd);
 	}
 
 	igt_waitchildren();
tests/fbdev.c +1 -1
index 794882a6a..154e78b0f 100644
@@ -443,6 +443,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_busy.c +1 -1
index 6b0d7310b..90d79864f 100644
@@ -184,6 +184,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap.c +1 -1
index efd4deff9..25b2939e9 100644
@@ -590,6 +590,6 @@ igt_main
 		free(query_info);
 		igt_collection_destroy(set);
 		igt_collection_destroy(dma_buf_set);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap_coherency.c +2 -2
index e5f7c92b2..01eb2002d 100644
@@ -267,7 +267,7 @@ static void blit_and_cmp(void)
 
 	intel_bb_destroy(local_batch);
 	buf_ops_destroy(local_bops);
-	close(local_fd);
+	drm_close_driver(local_fd);
 }
 
 /*
@@ -364,6 +364,6 @@ igt_main
 	igt_fixture {
 		buf_ops_destroy(bops);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap_kms.c +1 -1
index 8b127a13c..1a63be38f 100644
@@ -263,6 +263,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&gpu.display);
-		close(gpu.drm_fd);
+		drm_close_driver(gpu.drm_fd);
 	}
 }
tests/prime_self_import.c +7 -7
index 30f2bf013..2dbf4e20f 100644
@@ -147,8 +147,8 @@ static void test_with_fd_dup(void)
 	close(dma_buf_fd2);
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static void test_with_two_bos(void)
@@ -180,8 +180,8 @@ static void test_with_two_bos(void)
 
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static void test_with_one_bo_two_files(void)
@@ -205,8 +205,8 @@ static void test_with_one_bo_two_files(void)
 	/* dma-buf self importing an flink bo should give the same handle */
 	igt_assert_eq_u32(handle_import, handle_open);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 	close(dma_buf_fd1);
 	close(dma_buf_fd2);
 }
@@ -252,7 +252,7 @@ static void test_with_one_bo(void)
 	check_bo(fd1, handle, fd2, handle_import1);
 
 	/* Completely rip out exporting fd. */
-	close(fd1);
+	drm_close_driver(fd1);
 	check_bo(fd2, handle_import1, fd2, handle_import1);
 }
 

tests/prime_self_import.c static void test_reimport_close_race(void) · line 320

Quoted 6 lines
tests/prime_self_import.c +1 -1
@@ -316,14 +316,14 @@ static void test_reimport_close_race(void)
 		igt_assert(status == 0);
 	}
 
-	close(fds[0]);
+	drm_close_driver(fds[0]);
 	close(fds[1]);

------- ^^^^^
this should also be changed ?

Rest looks ok.

Regards,
Kamil

Quoted 145 lines
tests/prime_self_import.c +5 -5
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -398,13 +398,13 @@ static void test_export_close_race(void)
 		igt_assert(status == 0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -433,7 +433,7 @@ static void test_llseek_size(void)
 		close(dma_buf_fd);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_llseek_bad(void)
@@ -462,7 +462,7 @@ static void test_llseek_bad(void)
 
 	close(dma_buf_fd);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
tests/prime_vgem.c +2 -2
index 85b9cf880..876e04ed0 100644
@@ -1326,7 +1326,7 @@ igt_main
 
 
 	igt_fixture {
-		close(i915);
-		close(vgem);
+		drm_close_driver(i915);
+		drm_close_driver(vgem);
 	}
 }
tests/syncobj_basic.c +1 -1
index 3252dbd69..f079baf09 100644
@@ -266,7 +266,7 @@ igt_main
 		test_valid_cycle(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 }
tests/syncobj_timeline.c +1 -1
index 134a60995..b4e1d093a 100644
@@ -1936,6 +1936,6 @@ igt_main
 		test_32bits_limit(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/syncobj_wait.c +1 -1
index 2583ef72e..e0ff69b79 100644
@@ -1062,6 +1062,6 @@ igt_main
 		test_wait_interrupted(fd, WAIT_ALL);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/template.c +1 -1
index e23814fb7..ae2681c01 100644
@@ -76,6 +76,6 @@ igt_main
 	 */
 
 	igt_fixture {
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/vgem_basic.c +3 -3
index f2255a619..63c5c0971 100644
@@ -162,8 +162,8 @@ static void test_setversion(int fd)
 
 static void test_client(int fd)
 {
-	close(drm_open_driver(DRIVER_VGEM));
-	close(drm_open_driver_render(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver_render(DRIVER_VGEM));
 }
 
 static void test_create(int fd)
@@ -635,6 +635,6 @@ igt_main
 		test_debugfs_read(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/vgem_slow.c +1 -1
index 0c91cdb9d..cb9436628 100644
@@ -97,6 +97,6 @@ igt_main
 		test_nohang(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#18 lore raw

Re: [igt-dev] [V4 i-g-t 12/24] tests: Use drm_close_driver() to close the drm fd

Hi Kamil,

Quoted 70 lines · Kamil Konieczny

Hi Bhanuprakash,

Quoted 67 lines · Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
  tests/core_auth.c              | 10 +++++-----
  tests/core_getclient.c         |  2 +-
  tests/core_getstats.c          |  2 +-
  tests/core_getversion.c        |  2 +-
  tests/core_setmaster.c         |  6 +++---
  tests/core_setmaster_vs_auth.c |  6 +++---
  tests/debugfs_test.c           |  2 +-
  tests/dumb_buffer.c            |  2 +-
  tests/eviction_common.c        |  2 +-
  tests/fbdev.c                  |  2 +-
  tests/prime_busy.c             |  2 +-
  tests/prime_mmap.c             |  2 +-
  tests/prime_mmap_coherency.c   |  4 ++--
  tests/prime_mmap_kms.c         |  2 +-
  tests/prime_self_import.c      | 26 +++++++++++++-------------
  tests/prime_vgem.c             |  4 ++--
  tests/syncobj_basic.c          |  2 +-
  tests/syncobj_timeline.c       |  2 +-
  tests/syncobj_wait.c           |  2 +-
  tests/template.c               |  2 +-
  tests/vgem_basic.c             |  6 +++---
  tests/vgem_slow.c              |  2 +-
  22 files changed, 46 insertions(+), 46 deletions(-)
tests/core_auth.c +4 -4
index ed736e1ae..bc1b3b8d5 100644
@@ -214,7 +214,7 @@ static void test_basic_auth(int master)
  	igt_assert(drmGetMagic(slave, &magic) == 0);
  	igt_assert_eq(magic, old_magic);
 
-	close(slave);
+	drm_close_driver(slave);
  }
 
  igt_main
@@ -226,7 +226,7 @@ igt_main
 
  		igt_assert(check_auth(fd) == true);
 
-		close(fd);
+		drm_close_driver(fd);
  	}
 
  	igt_describe("Use 2 clients, check second is authenticated even when first dropped.");
@@ -236,11 +236,11 @@ igt_main
 
  		igt_assert(check_auth(fd2) == true);
 
-		close(fd);
+		drm_close_driver(fd);
 
  		igt_assert(check_auth(fd2) == true);
 
-		close(fd2);
+		drm_close_driver(fd2);
  	}
 
  	/* above tests require that no drm fd is open */
@@ -249,7 +249,7 @@ igt_main
 
Quoted 6 lines

tests/core_auth.c igt_main · line 252

Quoted 4 lines
tests/core_auth.c +1 -1
  		igt_fixture
  			master = drm_open_driver_master(DRIVER_ANY);
-	
+

Drop this change.

I haven't done this, some how my vim editor is adding this change. Will fix it new rev.

Quoted 234 lines
Quoted 234 lines
tests/core_auth.c +0 -0
  		igt_describe("Test magic numbers for master and slave.");
  		igt_subtest("basic-auth")
  			test_basic_auth(master);
tests/core_getclient.c +1 -1
index 993801ead..839fae36a 100644
@@ -70,5 +70,5 @@ igt_simple_main
  	ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
  	igt_assert(ret == -1 && errno == EINVAL);
 
-	close(fd);
+	drm_close_driver(fd);
  }
tests/core_getstats.c +1 -1
index fef122583..8b5655053 100644
@@ -64,5 +64,5 @@ igt_simple_main
  	ret = ioctl(fd, DRM_IOCTL_GET_STATS, &stats);
  	igt_assert(ret == 0);
 
-	close(fd);
+	drm_close_driver(fd);
  }
tests/core_getversion.c +1 -1
index 36ba01b86..32cb976e4 100644
@@ -58,5 +58,5 @@ igt_simple_main
  		igt_assert_lte(1, v->version_major);
 
  	drmFree(v);
-	close(fd);
+	drm_close_driver(fd);
  }
tests/core_setmaster.c +3 -3
index 621bc2469..04ee6b8b5 100644
@@ -104,7 +104,7 @@ static void check_drop_set(void)
  	igt_assert_eq(drmDropMaster(master), 0);
  	igt_assert_eq(drmSetMaster(master), 0);
 
-	close(master);
+	drm_close_driver(master);
  }
 
  static unsigned tweak_perm(uint8_t *saved_perm, unsigned max_perm, bool save)
@@ -225,10 +225,10 @@ igt_main
  			igt_assert_eq(drmSetMaster(master), -1);
  			igt_assert_eq(errno, EACCES);
 
-			close(master);
+			drm_close_driver(master);
  		}
  		igt_waitchildren();
 
-		close(master);
+		drm_close_driver(master);
  	}
  }
tests/core_setmaster_vs_auth.c +3 -3
index adca1c111..b80ed3879 100644
@@ -78,7 +78,7 @@ igt_simple_main
  	igt_assert_neq(drmAuthMagic(master2, magic), 0);
  	igt_assert_eq(errno, EINVAL);
 
-	close(client);
-	close(master2);
-	close(master1);
+	drm_close_driver(client);
+	drm_close_driver(master2);
+	drm_close_driver(master1);
  }
tests/debugfs_test.c +1 -1
index 5ee615aba..b67bfabac 100644
@@ -255,6 +255,6 @@ igt_main
  	igt_fixture {
  		close(sysfs);
  		close(debugfs);
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
tests/dumb_buffer.c +1 -1
index 9495d28ff..9db857f9f 100644
@@ -416,6 +416,6 @@ igt_main
  		always_clear(fd, 30);
 
  	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
tests/eviction_common.c +1 -1
index 95af106c1..5948fbc64 100644
@@ -300,7 +300,7 @@ static int forking_evictions(int fd, struct igt_eviction_test_ops *ops,
 
  		/* drmfd closing will take care of additional bo refs */
  		if (flags & FORKING_EVICTIONS_DUP_DRMFD)
-			close(realfd);
+			drm_close_driver(realfd);
  	}
 
  	igt_waitchildren();
tests/fbdev.c +1 -1
index 794882a6a..154e78b0f 100644
@@ -443,6 +443,6 @@ igt_main
  	}
 
  	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
tests/prime_busy.c +1 -1
index 6b0d7310b..90d79864f 100644
@@ -184,6 +184,6 @@ igt_main
 
  	igt_fixture {
  		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
tests/prime_mmap.c +1 -1
index efd4deff9..25b2939e9 100644
@@ -590,6 +590,6 @@ igt_main
  		free(query_info);
  		igt_collection_destroy(set);
  		igt_collection_destroy(dma_buf_set);
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
tests/prime_mmap_coherency.c +2 -2
index e5f7c92b2..01eb2002d 100644
@@ -267,7 +267,7 @@ static void blit_and_cmp(void)
 
  	intel_bb_destroy(local_batch);
  	buf_ops_destroy(local_bops);
-	close(local_fd);
+	drm_close_driver(local_fd);
  }
 
  /*
@@ -364,6 +364,6 @@ igt_main
  	igt_fixture {
  		buf_ops_destroy(bops);
 
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
tests/prime_mmap_kms.c +1 -1
index 8b127a13c..1a63be38f 100644
@@ -263,6 +263,6 @@ igt_main
 
  	igt_fixture {
  		igt_display_fini(&gpu.display);
-		close(gpu.drm_fd);
+		drm_close_driver(gpu.drm_fd);
  	}
  }
tests/prime_self_import.c +7 -7
index 30f2bf013..2dbf4e20f 100644
@@ -147,8 +147,8 @@ static void test_with_fd_dup(void)
  	close(dma_buf_fd2);
  	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
  }
 
  static void test_with_two_bos(void)
@@ -180,8 +180,8 @@ static void test_with_two_bos(void)
 
  	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
  }
 
  static void test_with_one_bo_two_files(void)
@@ -205,8 +205,8 @@ static void test_with_one_bo_two_files(void)
  	/* dma-buf self importing an flink bo should give the same handle */
  	igt_assert_eq_u32(handle_import, handle_open);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
  	close(dma_buf_fd1);
  	close(dma_buf_fd2);
  }
@@ -252,7 +252,7 @@ static void test_with_one_bo(void)
  	check_bo(fd1, handle, fd2, handle_import1);
 
  	/* Completely rip out exporting fd. */
-	close(fd1);
+	drm_close_driver(fd1);
  	check_bo(fd2, handle_import1, fd2, handle_import1);
  }
 
@@ -316,14 +316,14 @@ static void test_reimport_close_race(void)
  		igt_assert(status == 0);
  	}
 
Quoted 5 lines

tests/prime_self_import.c static void test_reimport_close_race(void) · line 320

Quoted 3 lines
tests/prime_self_import.c +1 -1
-	close(fds[0]);
+	drm_close_driver(fds[0]);
  	close(fds[1]);

------- ^^^^^
this should also be changed ?

fds[1] is not a drm fd. It is a dma-buf fd to export the gem buffer. So, we are not going to change it.

- Bhanu

Quoted 151 lines

Rest looks ok.

Regards,
Kamil

Quoted 145 lines
tests/prime_self_import.c +5 -5
  	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
  	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
  	igt_assert_eq(obj_count, 0);
  }
@@ -398,13 +398,13 @@ static void test_export_close_race(void)
  		igt_assert(status == 0);
  	}
 
-	close(fd);
+	drm_close_driver(fd);
 
  	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
  	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
  	igt_assert_eq(obj_count, 0);
  }
@@ -433,7 +433,7 @@ static void test_llseek_size(void)
  		close(dma_buf_fd);
  	}
 
-	close(fd);
+	drm_close_driver(fd);
  }
 
  static void test_llseek_bad(void)
@@ -462,7 +462,7 @@ static void test_llseek_bad(void)
 
  	close(dma_buf_fd);
 
-	close(fd);
+	drm_close_driver(fd);
  }
 
  igt_main
tests/prime_vgem.c +2 -2
index 85b9cf880..876e04ed0 100644
@@ -1326,7 +1326,7 @@ igt_main
 
 
  	igt_fixture {
-		close(i915);
-		close(vgem);
+		drm_close_driver(i915);
+		drm_close_driver(vgem);
  	}
  }
tests/syncobj_basic.c +1 -1
index 3252dbd69..f079baf09 100644
@@ -266,7 +266,7 @@ igt_main
  		test_valid_cycle(fd);
 
  	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
  	}
 
  }
tests/syncobj_timeline.c +1 -1
index 134a60995..b4e1d093a 100644
@@ -1936,6 +1936,6 @@ igt_main
  		test_32bits_limit(fd);
 
  	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
tests/syncobj_wait.c +1 -1
index 2583ef72e..e0ff69b79 100644
@@ -1062,6 +1062,6 @@ igt_main
  		test_wait_interrupted(fd, WAIT_ALL);
 
  	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
tests/template.c +1 -1
index e23814fb7..ae2681c01 100644
@@ -76,6 +76,6 @@ igt_main
  	 */
 
  	igt_fixture {
-		close(drm_fd);
+		drm_close_driver(drm_fd);
  	}
  }
tests/vgem_basic.c +3 -3
index f2255a619..63c5c0971 100644
@@ -162,8 +162,8 @@ static void test_setversion(int fd)
 
  static void test_client(int fd)
  {
-	close(drm_open_driver(DRIVER_VGEM));
-	close(drm_open_driver_render(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver_render(DRIVER_VGEM));
  }
 
  static void test_create(int fd)
@@ -635,6 +635,6 @@ igt_main
  		test_debugfs_read(fd);
 
  	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
tests/vgem_slow.c +1 -1
index 0c91cdb9d..cb9436628 100644
@@ -97,6 +97,6 @@ igt_main
  		test_nohang(fd);
 
  	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
  	}
  }
Signature · 1 line
2.40.0
#19 lore raw

PATCH v4 12/24 tests: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

V2: - Fix few nits

---
 tests/core_auth.c              |  8 ++++----
 tests/core_getclient.c         |  2 +-
 tests/core_getstats.c          |  2 +-
 tests/core_getversion.c        |  2 +-
 tests/core_setmaster.c         |  6 +++---
 tests/core_setmaster_vs_auth.c |  6 +++---
 tests/debugfs_test.c           |  2 +-
 tests/dumb_buffer.c            |  2 +-
 tests/eviction_common.c        |  2 +-
 tests/fbdev.c                  |  2 +-
 tests/prime_busy.c             |  2 +-
 tests/prime_mmap.c             |  2 +-
 tests/prime_mmap_coherency.c   |  4 ++--
 tests/prime_mmap_kms.c         |  2 +-
 tests/prime_self_import.c      | 26 +++++++++++++-------------
 tests/prime_vgem.c             |  4 ++--
 tests/syncobj_basic.c          |  2 +-
 tests/syncobj_timeline.c       |  2 +-
 tests/syncobj_wait.c           |  2 +-
 tests/template.c               |  2 +-
 tests/vgem_basic.c             |  6 +++---
 tests/vgem_slow.c              |  2 +-
 22 files changed, 45 insertions(+), 45 deletions(-)
tests/core_auth.c +4 -4
index ed736e1ae..6103d0ffc 100644
@@ -214,7 +214,7 @@ static void test_basic_auth(int master)
 	igt_assert(drmGetMagic(slave, &magic) == 0);
 	igt_assert_eq(magic, old_magic);
 
-	close(slave);
+	drm_close_driver(slave);
 }
 
 igt_main
@@ -226,7 +226,7 @@ igt_main
 
 		igt_assert(check_auth(fd) == true);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Use 2 clients, check second is authenticated even when first dropped.");
@@ -236,11 +236,11 @@ igt_main
 
 		igt_assert(check_auth(fd2) == true);
 
-		close(fd);
+		drm_close_driver(fd);
 
 		igt_assert(check_auth(fd2) == true);
 
-		close(fd2);
+		drm_close_driver(fd2);
 	}
 
 	/* above tests require that no drm fd is open */
tests/core_getclient.c +1 -1
index 993801ead..839fae36a 100644
@@ -70,5 +70,5 @@ igt_simple_main
 	ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
 	igt_assert(ret == -1 && errno == EINVAL);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_getstats.c +1 -1
index fef122583..8b5655053 100644
@@ -64,5 +64,5 @@ igt_simple_main
 	ret = ioctl(fd, DRM_IOCTL_GET_STATS, &stats);
 	igt_assert(ret == 0);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_getversion.c +1 -1
index 36ba01b86..32cb976e4 100644
@@ -58,5 +58,5 @@ igt_simple_main
 		igt_assert_lte(1, v->version_major);
 
 	drmFree(v);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_setmaster.c +3 -3
index 621bc2469..04ee6b8b5 100644
@@ -104,7 +104,7 @@ static void check_drop_set(void)
 	igt_assert_eq(drmDropMaster(master), 0);
 	igt_assert_eq(drmSetMaster(master), 0);
 
-	close(master);
+	drm_close_driver(master);
 }
 
 static unsigned tweak_perm(uint8_t *saved_perm, unsigned max_perm, bool save)
@@ -225,10 +225,10 @@ igt_main
 			igt_assert_eq(drmSetMaster(master), -1);
 			igt_assert_eq(errno, EACCES);
 
-			close(master);
+			drm_close_driver(master);
 		}
 		igt_waitchildren();
 
-		close(master);
+		drm_close_driver(master);
 	}
 }
tests/core_setmaster_vs_auth.c +3 -3
index adca1c111..b80ed3879 100644
@@ -78,7 +78,7 @@ igt_simple_main
 	igt_assert_neq(drmAuthMagic(master2, magic), 0);
 	igt_assert_eq(errno, EINVAL);
 
-	close(client);
-	close(master2);
-	close(master1);
+	drm_close_driver(client);
+	drm_close_driver(master2);
+	drm_close_driver(master1);
 }
tests/debugfs_test.c +1 -1
index 5ee615aba..b67bfabac 100644
@@ -255,6 +255,6 @@ igt_main
 	igt_fixture {
 		close(sysfs);
 		close(debugfs);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/dumb_buffer.c +1 -1
index 9495d28ff..9db857f9f 100644
@@ -416,6 +416,6 @@ igt_main
 		always_clear(fd, 30);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/eviction_common.c +1 -1
index 95af106c1..5948fbc64 100644
@@ -300,7 +300,7 @@ static int forking_evictions(int fd, struct igt_eviction_test_ops *ops,
 
 		/* drmfd closing will take care of additional bo refs */
 		if (flags & FORKING_EVICTIONS_DUP_DRMFD)
-			close(realfd);
+			drm_close_driver(realfd);
 	}
 
 	igt_waitchildren();
tests/fbdev.c +1 -1
index 794882a6a..154e78b0f 100644
@@ -443,6 +443,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_busy.c +1 -1
index 6b0d7310b..90d79864f 100644
@@ -184,6 +184,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap.c +1 -1
index efd4deff9..25b2939e9 100644
@@ -590,6 +590,6 @@ igt_main
 		free(query_info);
 		igt_collection_destroy(set);
 		igt_collection_destroy(dma_buf_set);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap_coherency.c +2 -2
index e5f7c92b2..01eb2002d 100644
@@ -267,7 +267,7 @@ static void blit_and_cmp(void)
 
 	intel_bb_destroy(local_batch);
 	buf_ops_destroy(local_bops);
-	close(local_fd);
+	drm_close_driver(local_fd);
 }
 
 /*
@@ -364,6 +364,6 @@ igt_main
 	igt_fixture {
 		buf_ops_destroy(bops);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap_kms.c +1 -1
index 8b127a13c..1a63be38f 100644
@@ -263,6 +263,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&gpu.display);
-		close(gpu.drm_fd);
+		drm_close_driver(gpu.drm_fd);
 	}
 }
tests/prime_self_import.c +13 -13
index 30f2bf013..2dbf4e20f 100644
@@ -147,8 +147,8 @@ static void test_with_fd_dup(void)
 	close(dma_buf_fd2);
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static void test_with_two_bos(void)
@@ -180,8 +180,8 @@ static void test_with_two_bos(void)
 
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static void test_with_one_bo_two_files(void)
@@ -205,8 +205,8 @@ static void test_with_one_bo_two_files(void)
 	/* dma-buf self importing an flink bo should give the same handle */
 	igt_assert_eq_u32(handle_import, handle_open);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 	close(dma_buf_fd1);
 	close(dma_buf_fd2);
 }
@@ -252,7 +252,7 @@ static void test_with_one_bo(void)
 	check_bo(fd1, handle, fd2, handle_import1);
 
 	/* Completely rip out exporting fd. */
-	close(fd1);
+	drm_close_driver(fd1);
 	check_bo(fd2, handle_import1, fd2, handle_import1);
 }
 
@@ -316,14 +316,14 @@ static void test_reimport_close_race(void)
 		igt_assert(status == 0);
 	}
 
-	close(fds[0]);
+	drm_close_driver(fds[0]);
 	close(fds[1]);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -398,13 +398,13 @@ static void test_export_close_race(void)
 		igt_assert(status == 0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -433,7 +433,7 @@ static void test_llseek_size(void)
 		close(dma_buf_fd);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_llseek_bad(void)
@@ -462,7 +462,7 @@ static void test_llseek_bad(void)
 
 	close(dma_buf_fd);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
tests/prime_vgem.c +2 -2
index 85b9cf880..876e04ed0 100644
@@ -1326,7 +1326,7 @@ igt_main
 
 
 	igt_fixture {
-		close(i915);
-		close(vgem);
+		drm_close_driver(i915);
+		drm_close_driver(vgem);
 	}
 }
tests/syncobj_basic.c +1 -1
index 3252dbd69..f079baf09 100644
@@ -266,7 +266,7 @@ igt_main
 		test_valid_cycle(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 }
tests/syncobj_timeline.c +1 -1
index 134a60995..b4e1d093a 100644
@@ -1936,6 +1936,6 @@ igt_main
 		test_32bits_limit(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/syncobj_wait.c +1 -1
index 2583ef72e..e0ff69b79 100644
@@ -1062,6 +1062,6 @@ igt_main
 		test_wait_interrupted(fd, WAIT_ALL);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/template.c +1 -1
index e23814fb7..ae2681c01 100644
@@ -76,6 +76,6 @@ igt_main
 	 */
 
 	igt_fixture {
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/vgem_basic.c +3 -3
index f2255a619..63c5c0971 100644
@@ -162,8 +162,8 @@ static void test_setversion(int fd)
 
 static void test_client(int fd)
 {
-	close(drm_open_driver(DRIVER_VGEM));
-	close(drm_open_driver_render(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver_render(DRIVER_VGEM));
 }
 
 static void test_create(int fd)
@@ -635,6 +635,6 @@ igt_main
 		test_debugfs_read(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/vgem_slow.c +1 -1
index 0c91cdb9d..cb9436628 100644
@@ -97,6 +97,6 @@ igt_main
 		test_nohang(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
Reviewed-by on v4 12/24
#20 lore raw

Re: [igt-dev] [V4 i-g-t 12/24] tests: Use drm_close_driver() to close the drm fd

Hi Bhanuprakash,

Quoted 6 lines · Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

V2: - Fix few nits

Quoted 439 lines
---
 tests/core_auth.c              |  8 ++++----
 tests/core_getclient.c         |  2 +-
 tests/core_getstats.c          |  2 +-
 tests/core_getversion.c        |  2 +-
 tests/core_setmaster.c         |  6 +++---
 tests/core_setmaster_vs_auth.c |  6 +++---
 tests/debugfs_test.c           |  2 +-
 tests/dumb_buffer.c            |  2 +-
 tests/eviction_common.c        |  2 +-
 tests/fbdev.c                  |  2 +-
 tests/prime_busy.c             |  2 +-
 tests/prime_mmap.c             |  2 +-
 tests/prime_mmap_coherency.c   |  4 ++--
 tests/prime_mmap_kms.c         |  2 +-
 tests/prime_self_import.c      | 26 +++++++++++++-------------
 tests/prime_vgem.c             |  4 ++--
 tests/syncobj_basic.c          |  2 +-
 tests/syncobj_timeline.c       |  2 +-
 tests/syncobj_wait.c           |  2 +-
 tests/template.c               |  2 +-
 tests/vgem_basic.c             |  6 +++---
 tests/vgem_slow.c              |  2 +-
 22 files changed, 45 insertions(+), 45 deletions(-)
tests/core_auth.c +4 -4
index ed736e1ae..6103d0ffc 100644
@@ -214,7 +214,7 @@ static void test_basic_auth(int master)
 	igt_assert(drmGetMagic(slave, &magic) == 0);
 	igt_assert_eq(magic, old_magic);
 
-	close(slave);
+	drm_close_driver(slave);
 }
 
 igt_main
@@ -226,7 +226,7 @@ igt_main
 
 		igt_assert(check_auth(fd) == true);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Use 2 clients, check second is authenticated even when first dropped.");
@@ -236,11 +236,11 @@ igt_main
 
 		igt_assert(check_auth(fd2) == true);
 
-		close(fd);
+		drm_close_driver(fd);
 
 		igt_assert(check_auth(fd2) == true);
 
-		close(fd2);
+		drm_close_driver(fd2);
 	}
 
 	/* above tests require that no drm fd is open */
tests/core_getclient.c +1 -1
index 993801ead..839fae36a 100644
@@ -70,5 +70,5 @@ igt_simple_main
 	ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
 	igt_assert(ret == -1 && errno == EINVAL);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_getstats.c +1 -1
index fef122583..8b5655053 100644
@@ -64,5 +64,5 @@ igt_simple_main
 	ret = ioctl(fd, DRM_IOCTL_GET_STATS, &stats);
 	igt_assert(ret == 0);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_getversion.c +1 -1
index 36ba01b86..32cb976e4 100644
@@ -58,5 +58,5 @@ igt_simple_main
 		igt_assert_lte(1, v->version_major);
 
 	drmFree(v);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/core_setmaster.c +3 -3
index 621bc2469..04ee6b8b5 100644
@@ -104,7 +104,7 @@ static void check_drop_set(void)
 	igt_assert_eq(drmDropMaster(master), 0);
 	igt_assert_eq(drmSetMaster(master), 0);
 
-	close(master);
+	drm_close_driver(master);
 }
 
 static unsigned tweak_perm(uint8_t *saved_perm, unsigned max_perm, bool save)
@@ -225,10 +225,10 @@ igt_main
 			igt_assert_eq(drmSetMaster(master), -1);
 			igt_assert_eq(errno, EACCES);
 
-			close(master);
+			drm_close_driver(master);
 		}
 		igt_waitchildren();
 
-		close(master);
+		drm_close_driver(master);
 	}
 }
tests/core_setmaster_vs_auth.c +3 -3
index adca1c111..b80ed3879 100644
@@ -78,7 +78,7 @@ igt_simple_main
 	igt_assert_neq(drmAuthMagic(master2, magic), 0);
 	igt_assert_eq(errno, EINVAL);
 
-	close(client);
-	close(master2);
-	close(master1);
+	drm_close_driver(client);
+	drm_close_driver(master2);
+	drm_close_driver(master1);
 }
tests/debugfs_test.c +1 -1
index 5ee615aba..b67bfabac 100644
@@ -255,6 +255,6 @@ igt_main
 	igt_fixture {
 		close(sysfs);
 		close(debugfs);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/dumb_buffer.c +1 -1
index 9495d28ff..9db857f9f 100644
@@ -416,6 +416,6 @@ igt_main
 		always_clear(fd, 30);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/eviction_common.c +1 -1
index 95af106c1..5948fbc64 100644
@@ -300,7 +300,7 @@ static int forking_evictions(int fd, struct igt_eviction_test_ops *ops,
 
 		/* drmfd closing will take care of additional bo refs */
 		if (flags & FORKING_EVICTIONS_DUP_DRMFD)
-			close(realfd);
+			drm_close_driver(realfd);
 	}
 
 	igt_waitchildren();
tests/fbdev.c +1 -1
index 794882a6a..154e78b0f 100644
@@ -443,6 +443,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_busy.c +1 -1
index 6b0d7310b..90d79864f 100644
@@ -184,6 +184,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap.c +1 -1
index efd4deff9..25b2939e9 100644
@@ -590,6 +590,6 @@ igt_main
 		free(query_info);
 		igt_collection_destroy(set);
 		igt_collection_destroy(dma_buf_set);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap_coherency.c +2 -2
index e5f7c92b2..01eb2002d 100644
@@ -267,7 +267,7 @@ static void blit_and_cmp(void)
 
 	intel_bb_destroy(local_batch);
 	buf_ops_destroy(local_bops);
-	close(local_fd);
+	drm_close_driver(local_fd);
 }
 
 /*
@@ -364,6 +364,6 @@ igt_main
 	igt_fixture {
 		buf_ops_destroy(bops);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap_kms.c +1 -1
index 8b127a13c..1a63be38f 100644
@@ -263,6 +263,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&gpu.display);
-		close(gpu.drm_fd);
+		drm_close_driver(gpu.drm_fd);
 	}
 }
tests/prime_self_import.c +13 -13
index 30f2bf013..2dbf4e20f 100644
@@ -147,8 +147,8 @@ static void test_with_fd_dup(void)
 	close(dma_buf_fd2);
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static void test_with_two_bos(void)
@@ -180,8 +180,8 @@ static void test_with_two_bos(void)
 
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static void test_with_one_bo_two_files(void)
@@ -205,8 +205,8 @@ static void test_with_one_bo_two_files(void)
 	/* dma-buf self importing an flink bo should give the same handle */
 	igt_assert_eq_u32(handle_import, handle_open);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 	close(dma_buf_fd1);
 	close(dma_buf_fd2);
 }
@@ -252,7 +252,7 @@ static void test_with_one_bo(void)
 	check_bo(fd1, handle, fd2, handle_import1);
 
 	/* Completely rip out exporting fd. */
-	close(fd1);
+	drm_close_driver(fd1);
 	check_bo(fd2, handle_import1, fd2, handle_import1);
 }
 
@@ -316,14 +316,14 @@ static void test_reimport_close_race(void)
 		igt_assert(status == 0);
 	}
 
-	close(fds[0]);
+	drm_close_driver(fds[0]);
 	close(fds[1]);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -398,13 +398,13 @@ static void test_export_close_race(void)
 		igt_assert(status == 0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -433,7 +433,7 @@ static void test_llseek_size(void)
 		close(dma_buf_fd);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_llseek_bad(void)
@@ -462,7 +462,7 @@ static void test_llseek_bad(void)
 
 	close(dma_buf_fd);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
tests/prime_vgem.c +2 -2
index 85b9cf880..876e04ed0 100644
@@ -1326,7 +1326,7 @@ igt_main
 
 
 	igt_fixture {
-		close(i915);
-		close(vgem);
+		drm_close_driver(i915);
+		drm_close_driver(vgem);
 	}
 }
tests/syncobj_basic.c +1 -1
index 3252dbd69..f079baf09 100644
@@ -266,7 +266,7 @@ igt_main
 		test_valid_cycle(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 }
tests/syncobj_timeline.c +1 -1
index 134a60995..b4e1d093a 100644
@@ -1936,6 +1936,6 @@ igt_main
 		test_32bits_limit(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/syncobj_wait.c +1 -1
index 2583ef72e..e0ff69b79 100644
@@ -1062,6 +1062,6 @@ igt_main
 		test_wait_interrupted(fd, WAIT_ALL);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/template.c +1 -1
index e23814fb7..ae2681c01 100644
@@ -76,6 +76,6 @@ igt_main
 	 */
 
 	igt_fixture {
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/vgem_basic.c +3 -3
index f2255a619..63c5c0971 100644
@@ -162,8 +162,8 @@ static void test_setversion(int fd)
 
 static void test_client(int fd)
 {
-	close(drm_open_driver(DRIVER_VGEM));
-	close(drm_open_driver_render(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver(DRIVER_VGEM));
+	drm_close_driver(drm_open_driver_render(DRIVER_VGEM));
 }
 
 static void test_create(int fd)
@@ -635,6 +635,6 @@ igt_main
 		test_debugfs_read(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/vgem_slow.c +1 -1
index 0c91cdb9d..cb9436628 100644
@@ -97,6 +97,6 @@ igt_main
 		test_nohang(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#21 lore raw

PATCH v4 13/24 tests/amdgpu: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 tests/amdgpu/amd_basic.c       | 2 +-
 tests/amdgpu/amd_cs_nop.c      | 2 +-
 tests/amdgpu/amd_deadlock.c    | 2 +-
 tests/amdgpu/amd_info.c        | 2 +-
 tests/amdgpu/amd_module_load.c | 2 +-
 tests/amdgpu/amd_prime.c       | 6 +++---
 6 files changed, 8 insertions(+), 8 deletions(-)
tests/amdgpu/amd_basic.c +1 -1
index 38525a85e..f7d7f036f 100644
@@ -696,6 +696,6 @@ igt_main
 
 	igt_fixture {
 		amdgpu_device_deinitialize(device);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/amdgpu/amd_cs_nop.c +1 -1
index ea3f6aae8..323c1b16a 100644
@@ -239,6 +239,6 @@ igt_main
 	igt_fixture {
 		amdgpu_cs_ctx_free(context);
 		amdgpu_device_deinitialize(device);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/amdgpu/amd_deadlock.c +1 -1
index df650c921..d805b8d18 100644
@@ -118,6 +118,6 @@ igt_main
 
 	igt_fixture {
 		amdgpu_device_deinitialize(device);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/amdgpu/amd_info.c +1 -1
index d6aea827b..c1137ab4d 100644
@@ -154,6 +154,6 @@ igt_main
 
 	igt_fixture {
 		amdgpu_device_deinitialize(dev);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/amdgpu/amd_module_load.c +1 -1
index 77df96d50..cbc9106f6 100644
@@ -54,7 +54,7 @@ static void sanity_check(void)
 		err = -errno;
 
 	igt_set_timeout(0, NULL);
-	close(fd);
+	drm_close_driver(fd);
 
 	igt_assert_eq(err, 0);
 }
tests/amdgpu/amd_prime.c +3 -3
index 62924f15b..6916c3173 100644
@@ -166,7 +166,7 @@ static void amd_plug(amdgpu_device_handle device, struct cork *c)
 static void unplug(struct cork *c)
 {
 	vgem_fence_signal(c->device, c->fence);
-	close(c->device);
+	drm_close_driver(c->device);
 }
 
 static void i915_to_amd(int i915, int amd, amdgpu_device_handle device)
@@ -461,7 +461,7 @@ igt_main
 
 	igt_fixture {
 		amdgpu_device_deinitialize(device);
-		close(amd);
-		close(i915);
+		drm_close_driver(amd);
+		drm_close_driver(i915);
 	}
 }
Signature · 1 line
2.40.0
#22 lore raw

PATCH v4 14/24 tests/chamelium: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 tests/chamelium/kms_chamelium_audio.c  | 2 +-
 tests/chamelium/kms_chamelium_edid.c   | 2 +-
 tests/chamelium/kms_chamelium_frames.c | 2 +-
 tests/chamelium/kms_chamelium_hpd.c    | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
tests/chamelium/kms_chamelium_audio.c +1 -1
index 6c6177fc5..8fbc1f80e 100644
@@ -870,6 +870,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/chamelium/kms_chamelium_edid.c +1 -1
index 4a52e6922..446bbd204 100644
@@ -585,6 +585,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/chamelium/kms_chamelium_frames.c +1 -1
index 22a7ba936..a56afada4 100644
@@ -1102,6 +1102,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/chamelium/kms_chamelium_hpd.c +1 -1
index efd40ba54..8b3189ca0 100644
@@ -564,6 +564,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
Signature · 1 line
2.40.0
Reviewed-by on v4 14/24
#23 lore raw

Re: [igt-dev] [V4 i-g-t 14/24] tests/chamelium: Use drm_close_driver() to close the drm fd

Hi Bhanuprakash,

Quoted 5 lines · Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

Quoted 58 lines
---
 tests/chamelium/kms_chamelium_audio.c  | 2 +-
 tests/chamelium/kms_chamelium_edid.c   | 2 +-
 tests/chamelium/kms_chamelium_frames.c | 2 +-
 tests/chamelium/kms_chamelium_hpd.c    | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
tests/chamelium/kms_chamelium_audio.c +1 -1
index 6c6177fc5..8fbc1f80e 100644
@@ -870,6 +870,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/chamelium/kms_chamelium_edid.c +1 -1
index 4a52e6922..446bbd204 100644
@@ -585,6 +585,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/chamelium/kms_chamelium_frames.c +1 -1
index 22a7ba936..a56afada4 100644
@@ -1102,6 +1102,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/chamelium/kms_chamelium_hpd.c +1 -1
index efd40ba54..8b3189ca0 100644
@@ -564,6 +564,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
Signature · 1 line
2.40.0
#24 lore raw

PATCH v4 15/24 tests/panfrost: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 tests/panfrost_gem_new.c   | 4 ++--
 tests/panfrost_get_param.c | 2 +-
 tests/panfrost_prime.c     | 4 ++--
 tests/panfrost_submit.c    | 6 +++---
 4 files changed, 8 insertions(+), 8 deletions(-)
tests/panfrost_gem_new.c +2 -2
index 940525ff1..4f27e029d 100644
@@ -82,9 +82,9 @@ igt_main
 		munmap(map, size);
 		igt_panfrost_free_bo(fd2, bo);
 
-		close(fd2);
+		drm_close_driver(fd2);
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/panfrost_get_param.c +1 -1
index 11c2632b8..7d1ebecb4 100644
@@ -69,5 +69,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/panfrost_prime.c +2 -2
index 40ba036b2..dbc1cb46b 100644
@@ -96,7 +96,7 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
-		close(kms_fd);
+		drm_close_driver(fd);
+		drm_close_driver(kms_fd);
 	}
 }
tests/panfrost_submit.c +3 -3
index 4747d2957..70af55e0b 100644
@@ -154,7 +154,7 @@ igt_main
                 check_done(headers[2]);
                 igt_panfrost_free_job(fd, submit[0]);
                 igt_panfrost_free_job(tmpfd, submit[1]);
-                close(tmpfd);
+                drm_close_driver(tmpfd);
         }
 
         igt_subtest("pan-submit-and-close") {
@@ -165,7 +165,7 @@ igt_main
                 submit = igt_panfrost_job_loop(tmpfd);
                 do_ioctl(tmpfd, DRM_IOCTL_PANFROST_SUBMIT, submit->args);
                 igt_panfrost_free_job(tmpfd, submit);
-                close(tmpfd);
+                drm_close_driver(tmpfd);
         }
 
         igt_subtest("pan-unhandled-pagefault") {
@@ -197,6 +197,6 @@ igt_main
         }
 
         igt_fixture {
-                close(fd);
+                drm_close_driver(fd);
         }
 }
Signature · 1 line
2.40.0
Acked-by on v4 15/24
#25 lore raw

Re: [igt-dev] [V4 i-g-t 15/24] tests/panfrost: Use drm_close_driver() to close the drm fd

Quoted 5 lines · On Mon, 26 Jun 2023 10:40:22 +0530 Bhanuprakash Modem…

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

Quoted 78 lines
---
 tests/panfrost_gem_new.c   | 4 ++--
 tests/panfrost_get_param.c | 2 +-
 tests/panfrost_prime.c     | 4 ++--
 tests/panfrost_submit.c    | 6 +++---
 4 files changed, 8 insertions(+), 8 deletions(-)
tests/panfrost_gem_new.c +2 -2
index 940525ff1..4f27e029d 100644
@@ -82,9 +82,9 @@ igt_main
 		munmap(map, size);
 		igt_panfrost_free_bo(fd2, bo);
 
-		close(fd2);
+		drm_close_driver(fd2);
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/panfrost_get_param.c +1 -1
index 11c2632b8..7d1ebecb4 100644
@@ -69,5 +69,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/panfrost_prime.c +2 -2
index 40ba036b2..dbc1cb46b 100644
@@ -96,7 +96,7 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
-		close(kms_fd);
+		drm_close_driver(fd);
+		drm_close_driver(kms_fd);
 	}
 }
tests/panfrost_submit.c +3 -3
index 4747d2957..70af55e0b 100644
@@ -154,7 +154,7 @@ igt_main
                 check_done(headers[2]);
                 igt_panfrost_free_job(fd, submit[0]);
                 igt_panfrost_free_job(tmpfd, submit[1]);
-                close(tmpfd);
+                drm_close_driver(tmpfd);
         }
 
         igt_subtest("pan-submit-and-close") {
@@ -165,7 +165,7 @@ igt_main
                 submit = igt_panfrost_job_loop(tmpfd);
                 do_ioctl(tmpfd, DRM_IOCTL_PANFROST_SUBMIT, submit->args);
                 igt_panfrost_free_job(tmpfd, submit);
-                close(tmpfd);
+                drm_close_driver(tmpfd);
         }
 
         igt_subtest("pan-unhandled-pagefault") {
@@ -197,6 +197,6 @@ igt_main
         }
 
         igt_fixture {
-                close(fd);
+                drm_close_driver(fd);
         }
 }
#26 lore raw

PATCH v4 16/24 tests/v3d: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 tests/v3d/v3d_create_bo.c      | 4 ++--
 tests/v3d/v3d_get_bo_offset.c  | 2 +-
 tests/v3d/v3d_get_param.c      | 2 +-
 tests/v3d/v3d_job_submission.c | 2 +-
 tests/v3d/v3d_mmap.c           | 2 +-
 tests/v3d/v3d_perfmon.c        | 2 +-
 tests/v3d/v3d_submit_cl.c      | 2 +-
 tests/v3d/v3d_submit_csd.c     | 2 +-
 tests/v3d/v3d_wait_bo.c        | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)
tests/v3d/v3d_create_bo.c +2 -2
index 4142fb5f6..07d237e96 100644
@@ -63,9 +63,9 @@ igt_main
 			igt_assert_eq_u32(((uint32_t *)bo->map)[i], 0x0);
 		igt_v3d_free_bo(fd2, bo);
 
-		close(fd2);
+		drm_close_driver(fd2);
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/v3d/v3d_get_bo_offset.c +1 -1
index 5c208f940..533488420 100644
@@ -67,5 +67,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/v3d/v3d_get_param.c +1 -1
index 0ca330eb5..0d8fbf3d6 100644
@@ -69,5 +69,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/v3d/v3d_job_submission.c +1 -1
index d6e415bb2..e4ca7e89d 100644
@@ -219,5 +219,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/v3d/v3d_mmap.c +1 -1
index 567940a80..642c55c65 100644
@@ -75,5 +75,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/v3d/v3d_perfmon.c +1 -1
index 3f55ddb1d..4d6ea465f 100644
@@ -142,5 +142,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/v3d/v3d_submit_cl.c +1 -1
index 725bc1dff..293b146e2 100644
@@ -376,5 +376,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/v3d/v3d_submit_csd.c +1 -1
index 3ec0ee49f..0e19913c6 100644
@@ -360,5 +360,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/v3d/v3d_wait_bo.c +1 -1
index 9e51b6a05..6ed999426 100644
@@ -122,6 +122,6 @@ igt_main
 
 	igt_fixture {
 		igt_v3d_free_bo(fd, bo);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#27 lore raw

PATCH v4 17/24 tests/vc4: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 tests/vc4/vc4_create_bo.c    | 4 ++--
 tests/vc4/vc4_dmabuf_poll.c  | 2 +-
 tests/vc4/vc4_label_bo.c     | 2 +-
 tests/vc4/vc4_lookup_fail.c  | 2 +-
 tests/vc4/vc4_mmap.c         | 2 +-
 tests/vc4/vc4_perfmon.c      | 2 +-
 tests/vc4/vc4_purgeable_bo.c | 2 +-
 tests/vc4/vc4_tiling.c       | 2 +-
 tests/vc4/vc4_wait_bo.c      | 2 +-
 tests/vc4/vc4_wait_seqno.c   | 2 +-
 10 files changed, 11 insertions(+), 11 deletions(-)
tests/vc4/vc4_create_bo.c +2 -2
index c17f25b04..ba7db1985 100644
@@ -72,9 +72,9 @@ igt_main
 		munmap(map, size);
 		gem_close(fd2, handle);
 
-		close(fd2);
+		drm_close_driver(fd2);
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/vc4/vc4_dmabuf_poll.c +1 -1
index c76d4950e..56f60b202 100644
@@ -73,5 +73,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/vc4/vc4_label_bo.c +1 -1
index 252bd1ed8..5d626a92d 100644
@@ -82,5 +82,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/vc4/vc4_lookup_fail.c +1 -1
index 5e709a7d3..9f179a3fd 100644
@@ -67,5 +67,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/vc4/vc4_mmap.c +1 -1
index 8094f4a2d..fef25f334 100644
@@ -49,5 +49,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/vc4/vc4_perfmon.c +1 -1
index 664633a3f..b25e92096 100644
@@ -135,5 +135,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/vc4/vc4_purgeable_bo.c +1 -1
index 9d6a3b438..7e9ac1718 100644
@@ -249,5 +249,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/vc4/vc4_tiling.c +1 -1
index f5bf31f56..e9d3ebfb3 100644
@@ -124,5 +124,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/vc4/vc4_wait_bo.c +1 -1
index c88a4ac46..d309acc95 100644
@@ -111,5 +111,5 @@ igt_main
 		test_used_bo(fd, ~0ull);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/vc4/vc4_wait_seqno.c +1 -1
index 78984fa32..e029a613e 100644
@@ -55,5 +55,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
Signature · 1 line
2.40.0
#28 lore raw

PATCH v4 18/24 tests/vmwgfx: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 lib/igt_vmwgfx.c                    | 2 +-
 tests/vmwgfx/vmw_execution_buffer.c | 2 +-
 tests/vmwgfx/vmw_ref_count.c        | 4 ++--
 tests/vmwgfx/vmw_surface_copy.c     | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
lib/igt_vmwgfx.c +1 -1
index 8fb6e553c..12b07b4a8 100644
@@ -135,7 +135,7 @@ void vmw_svga_device_fini(struct vmw_svga_device *device)
 	vmw_bitvector_free(device->rt_view_bv);
 	vmw_bitvector_free(device->ds_view_bv);
 	vmw_bitvector_free(device->shader_bv);
-	close(device->drm_fd);
+	drm_close_driver(device->drm_fd);
 }
 
 bool vmw_save_data_as_png(struct vmw_surface *surface, void *data,
tests/vmwgfx/vmw_execution_buffer.c +1 -1
index 42322514e..b89770b30 100644
@@ -308,6 +308,6 @@ igt_main_args("st:", long_options, NULL, parse_options, NULL)
 	igt_fixture
 	{
 		vmw_ioctl_context_destroy(fd, cid);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/vmwgfx/vmw_ref_count.c +2 -2
index 013214ff0..da4b41f89 100644
@@ -314,7 +314,7 @@ igt_main
 
 	igt_fixture
 	{
-		close(fd1);
-		close(fd2);
+		drm_close_driver(fd1);
+		drm_close_driver(fd2);
 	}
 }
tests/vmwgfx/vmw_surface_copy.c +1 -1
index d7c2711a8..57e90334f 100644
@@ -336,6 +336,6 @@ igt_main
 	igt_fixture
 	{
 		vmw_ioctl_context_destroy(fd, cid);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#29 lore raw

PATCH v4 19/24 tests/kms: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

V2: - New patch for chamelium tests

---
 tests/i915/kms_big_fb.c               | 2 +-
 tests/i915/kms_big_joiner.c           | 2 +-
 tests/i915/kms_busy.c                 | 2 +-
 tests/i915/kms_ccs.c                  | 2 +-
 tests/i915/kms_cdclk.c                | 2 +-
 tests/i915/kms_draw_crc.c             | 2 +-
 tests/i915/kms_dsc.c                  | 2 +-
 tests/i915/kms_fbcon_fbt.c            | 2 +-
 tests/i915/kms_fence_pin_leak.c       | 2 +-
 tests/i915/kms_flip_scaled_crc.c      | 2 +-
 tests/i915/kms_flip_tiling.c          | 2 +-
 tests/i915/kms_frontbuffer_tracking.c | 2 +-
 tests/i915/kms_legacy_colorkey.c      | 2 +-
 tests/i915/kms_mmap_write_crc.c       | 2 +-
 tests/i915/kms_pipe_b_c_ivb.c         | 2 +-
 tests/i915/kms_psr.c                  | 2 +-
 tests/i915/kms_psr2_sf.c              | 2 +-
 tests/i915/kms_psr2_su.c              | 2 +-
 tests/i915/kms_psr_stress_test.c      | 2 +-
 tests/i915/kms_pwrite_crc.c           | 2 +-
 tests/kms_3d.c                        | 2 +-
 tests/kms_addfb_basic.c               | 4 ++--
 tests/kms_async_flips.c               | 2 +-
 tests/kms_atomic.c                    | 2 +-
 tests/kms_atomic_interruptible.c      | 2 +-
 tests/kms_atomic_transition.c         | 2 +-
 tests/kms_color.c                     | 2 +-
 tests/kms_concurrent.c                | 2 +-
 tests/kms_content_protection.c        | 2 +-
 tests/kms_cursor_crc.c                | 2 +-
 tests/kms_cursor_edge_walk.c          | 2 +-
 tests/kms_cursor_legacy.c             | 2 +-
 tests/kms_dither.c                    | 2 +-
 tests/kms_dp_aux_dev.c                | 2 +-
 tests/kms_flip.c                      | 2 +-
 tests/kms_flip_event_leak.c           | 4 ++--
 tests/kms_force_connector_basic.c     | 4 ++--
 tests/kms_getfb.c                     | 4 ++--
 tests/kms_hdmi_inject.c               | 2 +-
 tests/kms_hdr.c                       | 2 +-
 tests/kms_invalid_mode.c              | 2 +-
 tests/kms_lease.c                     | 4 ++--
 tests/kms_panel_fitting.c             | 2 +-
 tests/kms_pipe_crc_basic.c            | 2 +-
 tests/kms_plane.c                     | 2 +-
 tests/kms_plane_alpha_blend.c         | 2 +-
 tests/kms_plane_cursor.c              | 2 +-
 tests/kms_plane_lowres.c              | 2 +-
 tests/kms_plane_multiple.c            | 2 +-
 tests/kms_plane_scaling.c             | 2 +-
 tests/kms_prime.c                     | 6 +++---
 tests/kms_prop_blob.c                 | 8 ++++----
 tests/kms_properties.c                | 2 +-
 tests/kms_rmfb.c                      | 4 ++--
 tests/kms_rotation_crc.c              | 2 +-
 tests/kms_scaling_modes.c             | 2 +-
 tests/kms_sequence.c                  | 2 +-
 tests/kms_setmode.c                   | 2 +-
 tests/kms_tiled_display.c             | 2 +-
 tests/kms_tv_load_detect.c            | 2 +-
 tests/kms_universal_plane.c           | 2 +-
 tests/kms_vblank.c                    | 2 +-
 62 files changed, 73 insertions(+), 73 deletions(-)
tests/i915/kms_big_fb.c +1 -1
index c120a14a6..44ea117a1 100644
@@ -1054,6 +1054,6 @@ igt_main
 	igt_fixture {
 		igt_display_fini(&data.display);
 		buf_ops_destroy(data.bops);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_big_joiner.c +1 -1
index b9dda58f6..2ff23398a 100644
@@ -302,6 +302,6 @@ igt_main
 	igt_fixture {
 		igt_remove_fb(data.drm_fd, &data.fb);
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_busy.c +1 -1
index e953b814e..ecc7f02d9 100644
@@ -513,6 +513,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/i915/kms_ccs.c +1 -1
index abe464b47..f04552dd7 100644
@@ -712,6 +712,6 @@ igt_main_args("cs:", NULL, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_cdclk.c +1 -1
index 0f9b8dc58..40eca24f0 100644
@@ -397,6 +397,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_draw_crc.c +1 -1
index db6d71f2e..01ecb7bb9 100644
@@ -242,7 +242,7 @@ static void teardown_environment(void)
 
 	buf_ops_destroy(bops);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 static const char *format_str(int format_index)
tests/i915/kms_dsc.c +1 -1
index c07078068..0a3e29924 100644
@@ -338,6 +338,6 @@ igt_main_args("l", NULL, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_fbcon_fbt.c +1 -1
index 6c557dca7..71c5285f1 100644
@@ -408,7 +408,7 @@ static void teardown_environment(struct drm_info *drm)
 
 	drmModeFreeResources(drm->res);
 	close(drm->debugfs_fd);
-	close(drm->fd);
+	drm_close_driver(drm->fd);
 	kmstest_restore_vt_mode();
 }
 
tests/i915/kms_fence_pin_leak.c +1 -1
index 127c01c16..3d63acfef 100644
@@ -238,5 +238,5 @@ igt_simple_main
 
 	buf_ops_destroy(data.bops);
 	igt_display_fini(&data.display);
-	close(data.drm_fd);
+	drm_close_driver(data.drm_fd);
 }
tests/i915/kms_flip_scaled_crc.c +1 -1
index f5dc430e3..30da1fcf3 100644
@@ -694,6 +694,6 @@ igt_main
 		}
 		kmstest_set_vt_text_mode();
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_flip_tiling.c +1 -1
index a22f12382..02a5fe8e3 100644
@@ -240,6 +240,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_frontbuffer_tracking.c +1 -1
index 8155d4e49..b2183b08e 100644
@@ -1353,7 +1353,7 @@ static void teardown_drm(void)
 {
 	buf_ops_destroy(drm.bops);
 	igt_display_fini(&drm.display);
-	close(drm.fd);
+	drm_close_driver(drm.fd);
 }
 
 static void setup_modeset(void)
tests/i915/kms_legacy_colorkey.c +1 -1
index 5b2fd64ba..450cb2e3f 100644
@@ -87,6 +87,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&display);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/i915/kms_mmap_write_crc.c +1 -1
index 07bd542dc..5a9eeec48 100644
@@ -306,7 +306,7 @@ igt_main_args("n", NULL, NULL, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 
 		igt_stop_helper(&hog);
 	}
tests/i915/kms_pipe_b_c_ivb.c +1 -1
index af11e3262..192771794 100644
@@ -291,6 +291,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_psr.c +1 -1
index 6c89de45d..3f8f83b42 100644
@@ -670,6 +670,6 @@ igt_main_args("", long_options, help_str, opt_handler, &data)
 		close(data.debugfs_fd);
 		buf_ops_destroy(data.bops);
 		display_fini(&data);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_psr2_sf.c +1 -1
index ffc41f983..b4734e5f1 100644
@@ -1298,6 +1298,6 @@ igt_main
 	igt_fixture {
 		close(data.debugfs_fd);
 		display_fini(&data);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_psr2_su.c +1 -1
index 65e67b8c9..3081887ca 100644
@@ -373,6 +373,6 @@ igt_main
 	igt_fixture {
 		close(data.debugfs_fd);
 		display_fini(&data);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_psr_stress_test.c +1 -1
index a4cb3194e..23dcb4077 100644
@@ -378,6 +378,6 @@ igt_main
 		buf_ops_destroy(data.bops);
 		igt_display_fini(&data.display);
 		close(data.debugfs_fd);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_pwrite_crc.c +1 -1
index 3278d876d..7bddeecba 100644
@@ -193,5 +193,5 @@ igt_simple_main
 	run_test(&data);
 
 	igt_display_fini(&data.display);
-	close(data.drm_fd);
+	drm_close_driver(data.drm_fd);
 }
tests/kms_3d.c +1 -1
index 437c8a481..55e1d8058 100644
@@ -119,5 +119,5 @@ igt_simple_main
 	if (is_xe_device(drm_fd))
 		xe_device_put(drm_fd);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
tests/kms_addfb_basic.c +2 -2
index e375f3ad2..53a6a007a 100644
@@ -933,7 +933,7 @@ static void master_tests(int fd)
 		do_ioctl_err(master2_fd, DRM_IOCTL_MODE_RMFB, &f.fb_id, ENOENT);
 
 		igt_device_drop_master(master2_fd);
-		close(master2_fd);
+		drm_close_driver(master2_fd);
 
 		igt_device_set_master(fd);
 	}
@@ -1012,6 +1012,6 @@ igt_main
 		if (is_xe_device(fd))
 			xe_device_put(fd);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/kms_async_flips.c +1 -1
index 5cb797dec..0a1199158 100644
@@ -676,6 +676,6 @@ igt_main
 		igt_display_reset(&data.display);
 		igt_display_commit(&data.display);
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_atomic.c +1 -1
index 037db2d36..b65045abc 100644
@@ -1460,6 +1460,6 @@ igt_main
 		igt_remove_fb(display.drm_fd, &fb);
 
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/kms_atomic_interruptible.c +1 -1
index 74b2e246a..2acdcb29d 100644
@@ -389,6 +389,6 @@ igt_main
 	/* TODO: legacy gamma_set/get, object set/getprop, getcrtc, getconnector */
 	igt_fixture {
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/kms_atomic_transition.c +1 -1
index 9f39d033d..6ab5267ca 100644
@@ -1182,6 +1182,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_color.c +1 -1
index 1d93ebbee..b15b9572c 100644
@@ -1120,6 +1120,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_concurrent.c +1 -1
index e1e581723..d915a98b2 100644
@@ -400,6 +400,6 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 		if (is_intel_device(data.drm_fd))
 			intel_allocator_multiprocess_stop();
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_content_protection.c +1 -1
index 344cac505..6cdf81a28 100644
@@ -884,6 +884,6 @@ igt_main
 	igt_fixture {
 		test_content_protection_cleanup();
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_cursor_crc.c +1 -1
index bd65c2e55..0506fd6f1 100644
@@ -1016,6 +1016,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 		}
 
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_cursor_edge_walk.c +1 -1
index 5f423a18f..462b51e20 100644
@@ -391,6 +391,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_cursor_legacy.c +1 -1
index f7a6202cf..c1e7c2113 100644
@@ -1843,6 +1843,6 @@ igt_main
 		if (intel_psr2_restore)
 			i915_psr2_sel_fetch_restore(display.drm_fd);
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/kms_dither.c +1 -1
index 95be6e136..d6c16dd0b 100644
@@ -247,6 +247,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_dp_aux_dev.c +1 -1
index 69edc1585..19cbe216a 100644
@@ -147,5 +147,5 @@ igt_simple_main
 	igt_require(valid_connectors);
 
 	drmModeFreeResources(res);
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
tests/kms_flip.c +1 -1
index f1e0700c1..efff06e1c 100755
@@ -1930,6 +1930,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 		if (is_xe_device(drm_fd))
 			xe_device_put(drm_fd);
 
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/kms_flip_event_leak.c +2 -2
index b79cd5030..7e46f5ec0 100644
@@ -79,7 +79,7 @@ static void test(data_t *data, enum pipe pipe, igt_output_t *output)
 
 	if (is_xe_device(fd))
 		xe_device_put(fd);
-	ret = close(fd);
+	ret = drm_close_driver(fd);
 	igt_assert_eq(ret, 0);
 
 	igt_device_set_master(data->drm_fd);
@@ -121,6 +121,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_force_connector_basic.c +2 -2
index 7e35693cf..950af8d8a 100644
@@ -65,7 +65,7 @@ static void reset_connectors(void)
 		free(param);
 	}
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 static void force_load_detect(int drm_fd, drmModeConnectorPtr connector, drmModeRes *res)
@@ -415,7 +415,7 @@ end:
 
 	igt_fixture {
 		drmModeFreeConnector(connector);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 
 		reset_connectors();
 	}
tests/kms_getfb.c +2 -2
index f44f42551..46cad39bd 100644
@@ -457,7 +457,7 @@ static void test_handle_protection(void) {
 		if (is_xe_device(non_master_fd))
 			xe_device_get(non_master_fd);
 
-		close(non_master_fd);
+		drm_close_driver(non_master_fd);
 	}
 }
 
@@ -489,6 +489,6 @@ igt_main
 		if (is_xe_device(fd))
 			xe_device_put(fd);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/kms_hdmi_inject.c +1 -1
index 2085d1453..e3db34502 100644
@@ -227,6 +227,6 @@ igt_main
 		if (is_xe_device(drm_fd))
 			xe_device_put(drm_fd);
 
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/kms_hdr.c +1 -1
index e9e52a9a1..ba19761e2 100644
@@ -666,6 +666,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.fd);
+		drm_close_driver(data.fd);
 	}
 }
tests/kms_invalid_mode.c +1 -1
index 671876308..c26f8befe 100644
@@ -300,6 +300,6 @@ igt_main
 		igt_display_fini(&data.display);
 		igt_reset_connectors();
 		drmModeFreeResources(data.res);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_lease.c +2 -2
index 29a774ae8..c8ae98206 100644
@@ -1082,7 +1082,7 @@ static void multimaster_lease(data_t *data)
 	drmSetClientCap(master2_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
 	lease2_fd = create_simple_lease(master2_fd, data);
 
-	close(master2_fd); /* close is an implicit DropMaster */
+	drm_close_driver(master2_fd); /* close is an implicit DropMaster */
 	igt_assert(!is_master(lease2_fd));
 
 	igt_device_set_master(data->master.fd);
@@ -1278,6 +1278,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(display);
-		close(data.master.fd);
+		drm_close_driver(data.master.fd);
 	}
 }
tests/kms_panel_fitting.c +1 -1
index 97ef1ae48..ae1c65928 100644
@@ -288,6 +288,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_pipe_crc_basic.c +1 -1
index 9ce9f5e53..95cc1d7fa 100644
@@ -511,6 +511,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane.c +1 -1
index dfc6a8c57..67cff61d6 100644
@@ -1336,6 +1336,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane_alpha_blend.c +1 -1
index 0d03e178a..341b85c7e 100644
@@ -715,6 +715,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 				    COMMIT_ATOMIC : COMMIT_LEGACY);
 
 		igt_display_fini(&data.display);
-		close(data.gfx_fd);
+		drm_close_driver(data.gfx_fd);
 	}
 }
tests/kms_plane_cursor.c +1 -1
index 59b105c60..a7acb18e1 100644
@@ -331,6 +331,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane_lowres.c +1 -1
index db9f5a54c..7aaf83c41 100644
@@ -342,6 +342,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane_multiple.c +1 -1
index 7dd9d586d..1f2bd65c3 100644
@@ -478,6 +478,6 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane_scaling.c +1 -1
index 77bb905b4..920290e4d 100644
@@ -1324,6 +1324,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_prime.c +3 -3
index dd5ab993e..52f587961 100644
@@ -431,7 +431,7 @@ igt_main
 			if (kms_poll_disabled)
 				kms_poll_state_restore();
 
-			close(second_fd_hybrid);
+			drm_close_driver(second_fd_hybrid);
 		}
 	}
 
@@ -454,9 +454,9 @@ igt_main
 		}
 
 		igt_fixture
-			close(second_fd_vgem);
+			drm_close_driver(second_fd_vgem);
 	}
 
 	igt_fixture
-		close(first_fd);
+		drm_close_driver(first_fd);
 }
tests/kms_prop_blob.c +4 -4
index 6a5a5f410..fc172b5a3 100644
@@ -182,7 +182,7 @@ test_lifetime(int fd)
 	/* Make sure properties are cleaned up on client exit. */
 	prop_id2 = create_prop(fd2);
 	igt_assert_eq(validate_prop(fd, prop_id2), 0);
-	igt_assert_eq(close(fd2), 0);
+	igt_assert_eq(drm_close_driver(fd2), 0);
 	igt_assert_eq(validate_prop(fd, prop_id2), ENOENT);
 
 	igt_assert_eq(validate_prop(fd, prop_id), 0);
@@ -210,7 +210,7 @@ test_multiple(int fd)
 		igt_assert_eq(destroy_prop(fd2, prop_ids[i]), 0);
 		igt_assert_eq(validate_prop(fd2, prop_ids[i]), ENOENT);
 	}
-	igt_assert_eq(close(fd2), 0);
+	igt_assert_eq(drm_close_driver(fd2), 0);
 
 	fd2 = drm_open_driver(DRIVER_ANY);
 	igt_assert_fd(fd2);
@@ -221,7 +221,7 @@ test_multiple(int fd)
 		igt_assert_eq(validate_prop(fd, prop_ids[i]), 0);
 		igt_assert_eq(validate_prop(fd2, prop_ids[i]), 0);
 	}
-	igt_assert_eq(close(fd2), 0);
+	igt_assert_eq(drm_close_driver(fd2), 0);
 
 	for (i = 0; i < ARRAY_SIZE(prop_ids); i++)
 		igt_assert_eq(validate_prop(fd, prop_ids[i]), ENOENT);
@@ -350,5 +350,5 @@ igt_main
 	prop_tests(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/kms_properties.c +1 -1
index 2fe8dfa66..8645808d1 100644
@@ -810,6 +810,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/kms_rmfb.c +2 -2
index 50df42953..9a41c1d14 100644
@@ -121,7 +121,7 @@ test_rmfb(struct rmfb_data *data, igt_output_t *output, enum pipe pipe, bool reo
 	drmModeFreeCrtc(crtc);
 
 	if (reopen) {
-		close(data->drm_fd);
+		drm_close_driver(data->drm_fd);
 
 		data->drm_fd = drm_open_driver_master(DRIVER_ANY);
 		drmSetClientCap(data->drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
@@ -204,6 +204,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_rotation_crc.c +1 -1
index 0a22cc225..5ad04407d 100644
@@ -1292,6 +1292,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.gfx_fd);
+		drm_close_driver(data.gfx_fd);
 	}
 }
tests/kms_scaling_modes.c +1 -1
index 906ae76de..31b806ae2 100644
@@ -138,6 +138,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_sequence.c +1 -1
index c8a3d6bbd..1b96f0017 100644
@@ -303,6 +303,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/kms_setmode.c +1 -1
index a611d9382..a85f4eaf2 100644
@@ -978,6 +978,6 @@ igt_main_args("det:", NULL, help_str, opt_handler, NULL)
 		if (is_xe_device(drm_fd))
 			xe_device_put(drm_fd);
 
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/kms_tiled_display.c +1 -1
index d9baf9878..eba1b2764 100644
@@ -623,6 +623,6 @@ igt_main
 		free(data.conns);
 		kmstest_restore_vt_mode();
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_tv_load_detect.c +1 -1
index 80ced9918..c8e5338d2 100644
@@ -84,6 +84,6 @@ igt_main
 
 	igt_fixture {
 		drmModeFreeConnector(tv_connector);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/kms_universal_plane.c +1 -1
index 635a136ab..957d600f1 100644
@@ -918,6 +918,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_vblank.c +1 -1
index da0ada78e..1aa8c1083 100644
@@ -601,6 +601,6 @@ igt_main
 			run_subtests_for_pipe(&data);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
Reviewed-by on v4 19/24
#30 lore raw

Re: [igt-dev] [V4 i-g-t 19/24] tests/kms: Use drm_close_driver() to close the drm fd

Hi Bhanuprakash,

Quoted 6 lines · Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

V2: - New patch for chamelium tests

Quoted 906 lines
---
 tests/i915/kms_big_fb.c               | 2 +-
 tests/i915/kms_big_joiner.c           | 2 +-
 tests/i915/kms_busy.c                 | 2 +-
 tests/i915/kms_ccs.c                  | 2 +-
 tests/i915/kms_cdclk.c                | 2 +-
 tests/i915/kms_draw_crc.c             | 2 +-
 tests/i915/kms_dsc.c                  | 2 +-
 tests/i915/kms_fbcon_fbt.c            | 2 +-
 tests/i915/kms_fence_pin_leak.c       | 2 +-
 tests/i915/kms_flip_scaled_crc.c      | 2 +-
 tests/i915/kms_flip_tiling.c          | 2 +-
 tests/i915/kms_frontbuffer_tracking.c | 2 +-
 tests/i915/kms_legacy_colorkey.c      | 2 +-
 tests/i915/kms_mmap_write_crc.c       | 2 +-
 tests/i915/kms_pipe_b_c_ivb.c         | 2 +-
 tests/i915/kms_psr.c                  | 2 +-
 tests/i915/kms_psr2_sf.c              | 2 +-
 tests/i915/kms_psr2_su.c              | 2 +-
 tests/i915/kms_psr_stress_test.c      | 2 +-
 tests/i915/kms_pwrite_crc.c           | 2 +-
 tests/kms_3d.c                        | 2 +-
 tests/kms_addfb_basic.c               | 4 ++--
 tests/kms_async_flips.c               | 2 +-
 tests/kms_atomic.c                    | 2 +-
 tests/kms_atomic_interruptible.c      | 2 +-
 tests/kms_atomic_transition.c         | 2 +-
 tests/kms_color.c                     | 2 +-
 tests/kms_concurrent.c                | 2 +-
 tests/kms_content_protection.c        | 2 +-
 tests/kms_cursor_crc.c                | 2 +-
 tests/kms_cursor_edge_walk.c          | 2 +-
 tests/kms_cursor_legacy.c             | 2 +-
 tests/kms_dither.c                    | 2 +-
 tests/kms_dp_aux_dev.c                | 2 +-
 tests/kms_flip.c                      | 2 +-
 tests/kms_flip_event_leak.c           | 4 ++--
 tests/kms_force_connector_basic.c     | 4 ++--
 tests/kms_getfb.c                     | 4 ++--
 tests/kms_hdmi_inject.c               | 2 +-
 tests/kms_hdr.c                       | 2 +-
 tests/kms_invalid_mode.c              | 2 +-
 tests/kms_lease.c                     | 4 ++--
 tests/kms_panel_fitting.c             | 2 +-
 tests/kms_pipe_crc_basic.c            | 2 +-
 tests/kms_plane.c                     | 2 +-
 tests/kms_plane_alpha_blend.c         | 2 +-
 tests/kms_plane_cursor.c              | 2 +-
 tests/kms_plane_lowres.c              | 2 +-
 tests/kms_plane_multiple.c            | 2 +-
 tests/kms_plane_scaling.c             | 2 +-
 tests/kms_prime.c                     | 6 +++---
 tests/kms_prop_blob.c                 | 8 ++++----
 tests/kms_properties.c                | 2 +-
 tests/kms_rmfb.c                      | 4 ++--
 tests/kms_rotation_crc.c              | 2 +-
 tests/kms_scaling_modes.c             | 2 +-
 tests/kms_sequence.c                  | 2 +-
 tests/kms_setmode.c                   | 2 +-
 tests/kms_tiled_display.c             | 2 +-
 tests/kms_tv_load_detect.c            | 2 +-
 tests/kms_universal_plane.c           | 2 +-
 tests/kms_vblank.c                    | 2 +-
 62 files changed, 73 insertions(+), 73 deletions(-)
tests/i915/kms_big_fb.c +1 -1
index c120a14a6..44ea117a1 100644
@@ -1054,6 +1054,6 @@ igt_main
 	igt_fixture {
 		igt_display_fini(&data.display);
 		buf_ops_destroy(data.bops);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_big_joiner.c +1 -1
index b9dda58f6..2ff23398a 100644
@@ -302,6 +302,6 @@ igt_main
 	igt_fixture {
 		igt_remove_fb(data.drm_fd, &data.fb);
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_busy.c +1 -1
index e953b814e..ecc7f02d9 100644
@@ -513,6 +513,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/i915/kms_ccs.c +1 -1
index abe464b47..f04552dd7 100644
@@ -712,6 +712,6 @@ igt_main_args("cs:", NULL, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_cdclk.c +1 -1
index 0f9b8dc58..40eca24f0 100644
@@ -397,6 +397,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_draw_crc.c +1 -1
index db6d71f2e..01ecb7bb9 100644
@@ -242,7 +242,7 @@ static void teardown_environment(void)
 
 	buf_ops_destroy(bops);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 static const char *format_str(int format_index)
tests/i915/kms_dsc.c +1 -1
index c07078068..0a3e29924 100644
@@ -338,6 +338,6 @@ igt_main_args("l", NULL, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_fbcon_fbt.c +1 -1
index 6c557dca7..71c5285f1 100644
@@ -408,7 +408,7 @@ static void teardown_environment(struct drm_info *drm)
 
 	drmModeFreeResources(drm->res);
 	close(drm->debugfs_fd);
-	close(drm->fd);
+	drm_close_driver(drm->fd);
 	kmstest_restore_vt_mode();
 }
 
tests/i915/kms_fence_pin_leak.c +1 -1
index 127c01c16..3d63acfef 100644
@@ -238,5 +238,5 @@ igt_simple_main
 
 	buf_ops_destroy(data.bops);
 	igt_display_fini(&data.display);
-	close(data.drm_fd);
+	drm_close_driver(data.drm_fd);
 }
tests/i915/kms_flip_scaled_crc.c +1 -1
index f5dc430e3..30da1fcf3 100644
@@ -694,6 +694,6 @@ igt_main
 		}
 		kmstest_set_vt_text_mode();
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_flip_tiling.c +1 -1
index a22f12382..02a5fe8e3 100644
@@ -240,6 +240,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_frontbuffer_tracking.c +1 -1
index 8155d4e49..b2183b08e 100644
@@ -1353,7 +1353,7 @@ static void teardown_drm(void)
 {
 	buf_ops_destroy(drm.bops);
 	igt_display_fini(&drm.display);
-	close(drm.fd);
+	drm_close_driver(drm.fd);
 }
 
 static void setup_modeset(void)
tests/i915/kms_legacy_colorkey.c +1 -1
index 5b2fd64ba..450cb2e3f 100644
@@ -87,6 +87,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&display);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/i915/kms_mmap_write_crc.c +1 -1
index 07bd542dc..5a9eeec48 100644
@@ -306,7 +306,7 @@ igt_main_args("n", NULL, NULL, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 
 		igt_stop_helper(&hog);
 	}
tests/i915/kms_pipe_b_c_ivb.c +1 -1
index af11e3262..192771794 100644
@@ -291,6 +291,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_psr.c +1 -1
index 6c89de45d..3f8f83b42 100644
@@ -670,6 +670,6 @@ igt_main_args("", long_options, help_str, opt_handler, &data)
 		close(data.debugfs_fd);
 		buf_ops_destroy(data.bops);
 		display_fini(&data);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_psr2_sf.c +1 -1
index ffc41f983..b4734e5f1 100644
@@ -1298,6 +1298,6 @@ igt_main
 	igt_fixture {
 		close(data.debugfs_fd);
 		display_fini(&data);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_psr2_su.c +1 -1
index 65e67b8c9..3081887ca 100644
@@ -373,6 +373,6 @@ igt_main
 	igt_fixture {
 		close(data.debugfs_fd);
 		display_fini(&data);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_psr_stress_test.c +1 -1
index a4cb3194e..23dcb4077 100644
@@ -378,6 +378,6 @@ igt_main
 		buf_ops_destroy(data.bops);
 		igt_display_fini(&data.display);
 		close(data.debugfs_fd);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/kms_pwrite_crc.c +1 -1
index 3278d876d..7bddeecba 100644
@@ -193,5 +193,5 @@ igt_simple_main
 	run_test(&data);
 
 	igt_display_fini(&data.display);
-	close(data.drm_fd);
+	drm_close_driver(data.drm_fd);
 }
tests/kms_3d.c +1 -1
index 437c8a481..55e1d8058 100644
@@ -119,5 +119,5 @@ igt_simple_main
 	if (is_xe_device(drm_fd))
 		xe_device_put(drm_fd);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
tests/kms_addfb_basic.c +2 -2
index e375f3ad2..53a6a007a 100644
@@ -933,7 +933,7 @@ static void master_tests(int fd)
 		do_ioctl_err(master2_fd, DRM_IOCTL_MODE_RMFB, &f.fb_id, ENOENT);
 
 		igt_device_drop_master(master2_fd);
-		close(master2_fd);
+		drm_close_driver(master2_fd);
 
 		igt_device_set_master(fd);
 	}
@@ -1012,6 +1012,6 @@ igt_main
 		if (is_xe_device(fd))
 			xe_device_put(fd);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/kms_async_flips.c +1 -1
index 5cb797dec..0a1199158 100644
@@ -676,6 +676,6 @@ igt_main
 		igt_display_reset(&data.display);
 		igt_display_commit(&data.display);
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_atomic.c +1 -1
index 037db2d36..b65045abc 100644
@@ -1460,6 +1460,6 @@ igt_main
 		igt_remove_fb(display.drm_fd, &fb);
 
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/kms_atomic_interruptible.c +1 -1
index 74b2e246a..2acdcb29d 100644
@@ -389,6 +389,6 @@ igt_main
 	/* TODO: legacy gamma_set/get, object set/getprop, getcrtc, getconnector */
 	igt_fixture {
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/kms_atomic_transition.c +1 -1
index 9f39d033d..6ab5267ca 100644
@@ -1182,6 +1182,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_color.c +1 -1
index 1d93ebbee..b15b9572c 100644
@@ -1120,6 +1120,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_concurrent.c +1 -1
index e1e581723..d915a98b2 100644
@@ -400,6 +400,6 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 		if (is_intel_device(data.drm_fd))
 			intel_allocator_multiprocess_stop();
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_content_protection.c +1 -1
index 344cac505..6cdf81a28 100644
@@ -884,6 +884,6 @@ igt_main
 	igt_fixture {
 		test_content_protection_cleanup();
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_cursor_crc.c +1 -1
index bd65c2e55..0506fd6f1 100644
@@ -1016,6 +1016,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 		}
 
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_cursor_edge_walk.c +1 -1
index 5f423a18f..462b51e20 100644
@@ -391,6 +391,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_cursor_legacy.c +1 -1
index f7a6202cf..c1e7c2113 100644
@@ -1843,6 +1843,6 @@ igt_main
 		if (intel_psr2_restore)
 			i915_psr2_sel_fetch_restore(display.drm_fd);
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/kms_dither.c +1 -1
index 95be6e136..d6c16dd0b 100644
@@ -247,6 +247,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_dp_aux_dev.c +1 -1
index 69edc1585..19cbe216a 100644
@@ -147,5 +147,5 @@ igt_simple_main
 	igt_require(valid_connectors);
 
 	drmModeFreeResources(res);
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
tests/kms_flip.c +1 -1
index f1e0700c1..efff06e1c 100755
@@ -1930,6 +1930,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 		if (is_xe_device(drm_fd))
 			xe_device_put(drm_fd);
 
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/kms_flip_event_leak.c +2 -2
index b79cd5030..7e46f5ec0 100644
@@ -79,7 +79,7 @@ static void test(data_t *data, enum pipe pipe, igt_output_t *output)
 
 	if (is_xe_device(fd))
 		xe_device_put(fd);
-	ret = close(fd);
+	ret = drm_close_driver(fd);
 	igt_assert_eq(ret, 0);
 
 	igt_device_set_master(data->drm_fd);
@@ -121,6 +121,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_force_connector_basic.c +2 -2
index 7e35693cf..950af8d8a 100644
@@ -65,7 +65,7 @@ static void reset_connectors(void)
 		free(param);
 	}
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 static void force_load_detect(int drm_fd, drmModeConnectorPtr connector, drmModeRes *res)
@@ -415,7 +415,7 @@ end:
 
 	igt_fixture {
 		drmModeFreeConnector(connector);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 
 		reset_connectors();
 	}
tests/kms_getfb.c +2 -2
index f44f42551..46cad39bd 100644
@@ -457,7 +457,7 @@ static void test_handle_protection(void) {
 		if (is_xe_device(non_master_fd))
 			xe_device_get(non_master_fd);
 
-		close(non_master_fd);
+		drm_close_driver(non_master_fd);
 	}
 }
 
@@ -489,6 +489,6 @@ igt_main
 		if (is_xe_device(fd))
 			xe_device_put(fd);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/kms_hdmi_inject.c +1 -1
index 2085d1453..e3db34502 100644
@@ -227,6 +227,6 @@ igt_main
 		if (is_xe_device(drm_fd))
 			xe_device_put(drm_fd);
 
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/kms_hdr.c +1 -1
index e9e52a9a1..ba19761e2 100644
@@ -666,6 +666,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.fd);
+		drm_close_driver(data.fd);
 	}
 }
tests/kms_invalid_mode.c +1 -1
index 671876308..c26f8befe 100644
@@ -300,6 +300,6 @@ igt_main
 		igt_display_fini(&data.display);
 		igt_reset_connectors();
 		drmModeFreeResources(data.res);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_lease.c +2 -2
index 29a774ae8..c8ae98206 100644
@@ -1082,7 +1082,7 @@ static void multimaster_lease(data_t *data)
 	drmSetClientCap(master2_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
 	lease2_fd = create_simple_lease(master2_fd, data);
 
-	close(master2_fd); /* close is an implicit DropMaster */
+	drm_close_driver(master2_fd); /* close is an implicit DropMaster */
 	igt_assert(!is_master(lease2_fd));
 
 	igt_device_set_master(data->master.fd);
@@ -1278,6 +1278,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(display);
-		close(data.master.fd);
+		drm_close_driver(data.master.fd);
 	}
 }
tests/kms_panel_fitting.c +1 -1
index 97ef1ae48..ae1c65928 100644
@@ -288,6 +288,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_pipe_crc_basic.c +1 -1
index 9ce9f5e53..95cc1d7fa 100644
@@ -511,6 +511,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane.c +1 -1
index dfc6a8c57..67cff61d6 100644
@@ -1336,6 +1336,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane_alpha_blend.c +1 -1
index 0d03e178a..341b85c7e 100644
@@ -715,6 +715,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 				    COMMIT_ATOMIC : COMMIT_LEGACY);
 
 		igt_display_fini(&data.display);
-		close(data.gfx_fd);
+		drm_close_driver(data.gfx_fd);
 	}
 }
tests/kms_plane_cursor.c +1 -1
index 59b105c60..a7acb18e1 100644
@@ -331,6 +331,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane_lowres.c +1 -1
index db9f5a54c..7aaf83c41 100644
@@ -342,6 +342,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane_multiple.c +1 -1
index 7dd9d586d..1f2bd65c3 100644
@@ -478,6 +478,6 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_plane_scaling.c +1 -1
index 77bb905b4..920290e4d 100644
@@ -1324,6 +1324,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_prime.c +3 -3
index dd5ab993e..52f587961 100644
@@ -431,7 +431,7 @@ igt_main
 			if (kms_poll_disabled)
 				kms_poll_state_restore();
 
-			close(second_fd_hybrid);
+			drm_close_driver(second_fd_hybrid);
 		}
 	}
 
@@ -454,9 +454,9 @@ igt_main
 		}
 
 		igt_fixture
-			close(second_fd_vgem);
+			drm_close_driver(second_fd_vgem);
 	}
 
 	igt_fixture
-		close(first_fd);
+		drm_close_driver(first_fd);
 }
tests/kms_prop_blob.c +4 -4
index 6a5a5f410..fc172b5a3 100644
@@ -182,7 +182,7 @@ test_lifetime(int fd)
 	/* Make sure properties are cleaned up on client exit. */
 	prop_id2 = create_prop(fd2);
 	igt_assert_eq(validate_prop(fd, prop_id2), 0);
-	igt_assert_eq(close(fd2), 0);
+	igt_assert_eq(drm_close_driver(fd2), 0);
 	igt_assert_eq(validate_prop(fd, prop_id2), ENOENT);
 
 	igt_assert_eq(validate_prop(fd, prop_id), 0);
@@ -210,7 +210,7 @@ test_multiple(int fd)
 		igt_assert_eq(destroy_prop(fd2, prop_ids[i]), 0);
 		igt_assert_eq(validate_prop(fd2, prop_ids[i]), ENOENT);
 	}
-	igt_assert_eq(close(fd2), 0);
+	igt_assert_eq(drm_close_driver(fd2), 0);
 
 	fd2 = drm_open_driver(DRIVER_ANY);
 	igt_assert_fd(fd2);
@@ -221,7 +221,7 @@ test_multiple(int fd)
 		igt_assert_eq(validate_prop(fd, prop_ids[i]), 0);
 		igt_assert_eq(validate_prop(fd2, prop_ids[i]), 0);
 	}
-	igt_assert_eq(close(fd2), 0);
+	igt_assert_eq(drm_close_driver(fd2), 0);
 
 	for (i = 0; i < ARRAY_SIZE(prop_ids); i++)
 		igt_assert_eq(validate_prop(fd, prop_ids[i]), ENOENT);
@@ -350,5 +350,5 @@ igt_main
 	prop_tests(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/kms_properties.c +1 -1
index 2fe8dfa66..8645808d1 100644
@@ -810,6 +810,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/kms_rmfb.c +2 -2
index 50df42953..9a41c1d14 100644
@@ -121,7 +121,7 @@ test_rmfb(struct rmfb_data *data, igt_output_t *output, enum pipe pipe, bool reo
 	drmModeFreeCrtc(crtc);
 
 	if (reopen) {
-		close(data->drm_fd);
+		drm_close_driver(data->drm_fd);
 
 		data->drm_fd = drm_open_driver_master(DRIVER_ANY);
 		drmSetClientCap(data->drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
@@ -204,6 +204,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_rotation_crc.c +1 -1
index 0a22cc225..5ad04407d 100644
@@ -1292,6 +1292,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.gfx_fd);
+		drm_close_driver(data.gfx_fd);
 	}
 }
tests/kms_scaling_modes.c +1 -1
index 906ae76de..31b806ae2 100644
@@ -138,6 +138,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_sequence.c +1 -1
index c8a3d6bbd..1b96f0017 100644
@@ -303,6 +303,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/kms_setmode.c +1 -1
index a611d9382..a85f4eaf2 100644
@@ -978,6 +978,6 @@ igt_main_args("det:", NULL, help_str, opt_handler, NULL)
 		if (is_xe_device(drm_fd))
 			xe_device_put(drm_fd);
 
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/kms_tiled_display.c +1 -1
index d9baf9878..eba1b2764 100644
@@ -623,6 +623,6 @@ igt_main
 		free(data.conns);
 		kmstest_restore_vt_mode();
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_tv_load_detect.c +1 -1
index 80ced9918..c8e5338d2 100644
@@ -84,6 +84,6 @@ igt_main
 
 	igt_fixture {
 		drmModeFreeConnector(tv_connector);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/kms_universal_plane.c +1 -1
index 635a136ab..957d600f1 100644
@@ -918,6 +918,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/kms_vblank.c +1 -1
index da0ada78e..1aa8c1083 100644
@@ -601,6 +601,6 @@ igt_main
 			run_subtests_for_pipe(&data);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#31 lore raw

PATCH v4 20/24 tests/xe: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

---
 tests/testdisplay.c             |  4 ++--
 tests/xe/xe_compute.c           |  2 +-
 tests/xe/xe_create.c            |  4 ++--
 tests/xe/xe_debugfs.c           |  2 +-
 tests/xe/xe_dma_buf_sync.c      |  4 ++--
 tests/xe/xe_evict.c             |  6 +++---
 tests/xe/xe_exec_balancer.c     |  2 +-
 tests/xe/xe_exec_basic.c        |  2 +-
 tests/xe/xe_exec_compute_mode.c |  2 +-
 tests/xe/xe_exec_fault_mode.c   |  2 +-
 tests/xe/xe_exec_reset.c        |  8 ++++----
 tests/xe/xe_exec_threads.c      |  8 ++++----
 tests/xe/xe_guc_pc.c            |  2 +-
 tests/xe/xe_huc_copy.c          |  2 +-
 tests/xe/xe_intel_bb.c          |  2 +-
 tests/xe/xe_mmap.c              |  2 +-
 tests/xe/xe_mmio.c              |  2 +-
 tests/xe/xe_module_load.c       |  2 +-
 tests/xe/xe_noexec_ping_pong.c  |  2 +-
 tests/xe/xe_pm.c                |  2 +-
 tests/xe/xe_prime_self_import.c | 30 +++++++++++++++---------------
 tests/xe/xe_query.c             |  2 +-
 tests/xe/xe_spin_batch.c        |  2 +-
 tests/xe/xe_vm.c                |  2 +-
 tests/xe/xe_waitfence.c         |  2 +-
 25 files changed, 50 insertions(+), 50 deletions(-)
tests/testdisplay.c +2 -2
index ee272dfb2..294d4c604 100644
@@ -548,7 +548,7 @@ int update_display(bool probe)
 
 __noreturn static void cleanup_and_exit(int ret)
 {
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 	exit(ret);
 }
 
@@ -779,7 +779,7 @@ out_hotplug:
 out_mainloop:
 	g_main_loop_unref(mainloop);
 out_close:
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 
 	igt_assert_eq(ret, 0);
 }
tests/xe/xe_compute.c +1 -1
index 28fd8bd11..1bb4e9821 100644
@@ -46,6 +46,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_create.c +2 -2
index b427c51fd..744f2c799 100644
@@ -177,7 +177,7 @@ static void create_engines(int fd, enum engine_destroy ed)
 	igt_waitchildren();
 
 	xe_vm_destroy(fd, vm);
-	close(fd);
+	drm_close_driver(fd);
 
 	seconds = igt_seconds_elapsed(&tv);
 	igt_assert_f(seconds < MAXTIME,
@@ -231,6 +231,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_debugfs.c +1 -1
index 985bff6d2..c404da258 100644
@@ -271,6 +271,6 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_dma_buf_sync.c +2 -2
index 71184c969..d6342746a 100644
@@ -219,7 +219,7 @@ test_export_dma_buf(struct drm_xe_engine_class_instance *hwe0,
 
 	for (i = 0; i < N_FD; ++i) {
 		xe_device_put(fd[i]);
-		close(fd[i]);
+		drm_close_driver(fd[i]);
 	}
 
 }
@@ -256,6 +256,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_evict.c +3 -3
index 2c39d4390..21cf27dc0 100644
@@ -201,7 +201,7 @@ test_evict(int fd, struct drm_xe_engine_class_instance *eci,
 		xe_vm_destroy(fd, vm3);
 	}
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -369,7 +369,7 @@ test_evict_cm(int fd, struct drm_xe_engine_class_instance *eci,
 	if (flags & MULTI_VM)
 		xe_vm_destroy(fd, vm2);
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 struct thread_data {
@@ -700,5 +700,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/xe/xe_exec_balancer.c +1 -1
index 83a7b77ba..e5fe1ea2a 100644
@@ -701,6 +701,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_basic.c +1 -1
index ae192f8e3..9aeb861aa 100644
@@ -350,6 +350,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_compute_mode.c +1 -1
index e2c9d0f38..966aae566 100644
@@ -366,6 +366,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_fault_mode.c +1 -1
index 6d9e64868..566a5981f 100644
@@ -562,6 +562,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_reset.c +4 -4
index 30b0548bf..8699ad26b 100644
@@ -286,7 +286,7 @@ test_balancer(int fd, int gt, int class, int n_engines, int n_execs,
 				xe_engine_destroy(fd, engines[i]);
 		}
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 		/* FIXME: wait for idle */
 		usleep(150000);
 		return;
@@ -461,7 +461,7 @@ test_legacy_mode(int fd, struct drm_xe_engine_class_instance *eci,
 				xe_engine_destroy(fd, engines[i]);
 		}
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 		/* FIXME: wait for idle */
 		usleep(150000);
 		return;
@@ -636,7 +636,7 @@ test_compute_mode(int fd, struct drm_xe_engine_class_instance *eci,
 				xe_engine_destroy(fd, engines[i]);
 		}
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 		/* FIXME: wait for idle */
 		usleep(150000);
 		return;
@@ -927,6 +927,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_threads.c +4 -4
index aac2450ee..f34f33b94 100644
@@ -245,7 +245,7 @@ test_balancer(int fd, int gt, uint32_t vm, uint64_t addr, uint64_t userptr,
 		xe_vm_destroy(fd, vm);
 	if (owns_fd) {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
 
@@ -459,7 +459,7 @@ test_compute_mode(int fd, uint32_t vm, uint64_t addr, uint64_t userptr,
 		xe_vm_destroy(fd, vm);
 	if (owns_fd) {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
 
@@ -703,7 +703,7 @@ test_legacy_mode(int fd, uint32_t vm, uint64_t addr, uint64_t userptr,
 		xe_vm_destroy(fd, vm);
 	if (owns_fd) {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
 
@@ -1407,6 +1407,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_guc_pc.c +1 -1
index 89d5ae9ef..3e2e44d99 100644
@@ -490,6 +490,6 @@ igt_main
 		}
 		close(sysfs);
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_huc_copy.c +1 -1
index fdac907d6..ccdfe8622 100644
@@ -192,6 +192,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_intel_bb.c +1 -1
index 83fe29242..5b22b967b 100644
@@ -1143,6 +1143,6 @@ igt_main_args("dpib", NULL, help_str, opt_handler, NULL)
 	igt_fixture {
 		xe_device_put(xe);
 		buf_ops_destroy(bops);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_mmap.c +1 -1
index 420c7f86c..1cc55cf3c 100644
@@ -140,6 +140,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_mmio.c +1 -1
index ca3408934..b8f0596ce 100644
@@ -90,6 +90,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_module_load.c +1 -1
index 3b2dc1fdc..575d57268 100644
@@ -87,7 +87,7 @@ static void load_and_check_xe(const char *opts)
 	/* driver is ready, check if it's bound */
 	drm_fd = __drm_open_driver(DRIVER_XE);
 	igt_fail_on_f(drm_fd < 0, "Cannot open the xe DRM driver after modprobing xe.\n");
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 static const char * const unwanted_drivers[] = {
tests/xe/xe_noexec_ping_pong.c +1 -1
index 1d04d4608..ee0e33e6b 100644
@@ -104,5 +104,5 @@ igt_simple_main
 	test_ping_pong(fd, xe_hw_engine(fd, 0));
 
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/xe/xe_pm.c +1 -1
index bba799bcb..289337cd3 100644
@@ -445,6 +445,6 @@ igt_main
 		set_d3cold_allowed(device.pci_xe, d3cold_allowed);
 		igt_restore_runtime_pm();
 		xe_device_put(device.fd_xe);
-		close(device.fd_xe);
+		drm_close_driver(device.fd_xe);
 	}
 }
tests/xe/xe_prime_self_import.c +15 -15
index 7a7e3d5ed..c1065b2e8 100644
@@ -123,9 +123,9 @@ static void test_with_fd_dup(void)
 	check_bo(fd2, handle_import, fd2, handle_import);
 
 	xe_device_put(fd1);
-	close(fd1);
+	drm_close_driver(fd1);
 	xe_device_put(fd2);
-	close(fd2);
+	drm_close_driver(fd2);
 }
 
 /**
@@ -166,9 +166,9 @@ static void test_with_two_bos(void)
 	check_bo(fd2, handle_import, fd2, handle_import);
 
 	xe_device_put(fd1);
-	close(fd1);
+	drm_close_driver(fd1);
 	xe_device_put(fd2);
-	close(fd2);
+	drm_close_driver(fd2);
 }
 
 /**
@@ -201,9 +201,9 @@ static void test_with_one_bo_two_files(void)
 	igt_assert_eq_u32(handle_import, handle_open);
 
 	xe_device_put(fd1);
-	close(fd1);
+	drm_close_driver(fd1);
 	xe_device_put(fd2);
-	close(fd2);
+	drm_close_driver(fd2);
 	close(dma_buf_fd1);
 	close(dma_buf_fd2);
 }
@@ -258,10 +258,10 @@ static void test_with_one_bo(void)
 
 	/* Completely rip out exporting fd. */
 	xe_device_put(fd1);
-	close(fd1);
+	drm_close_driver(fd1);
 	check_bo(fd2, handle_import1, fd2, handle_import1);
 	xe_device_put(fd2);
-	close(fd2);
+	drm_close_driver(fd2);
 }
 
 static void *thread_fn_reimport_vs_close(void *p)
@@ -334,7 +334,7 @@ static void *thread_fn_reimport_vs_close(void *p)
 
 	pthread_barrier_destroy(&g_barrier);
 	xe_device_put(fds[0]);
-	close(fds[0]);
+	drm_close_driver(fds[0]);
 	close(fds[1]);
 
 	/* TODO: Read object count */
@@ -342,7 +342,7 @@ static void *thread_fn_reimport_vs_close(void *p)
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -428,7 +428,7 @@ static void test_export_close_race(void)
 
 	pthread_barrier_destroy(&g_barrier);
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 
 	/* TODO: Read object count */
 	obj_count = 0;
@@ -436,7 +436,7 @@ static void test_export_close_race(void)
 	igt_info("leaked %i objects\n", obj_count);
 
 	xe_device_put(fake);
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
@@ -472,7 +472,7 @@ static void test_llseek_size(void)
 	}
 
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 /**
@@ -508,7 +508,7 @@ static void test_llseek_bad(void)
 	close(dma_buf_fd);
 
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -541,6 +541,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_query.c +1 -1
index 40bd19ae7..22eeb2b43 100644
@@ -492,6 +492,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_spin_batch.c +1 -1
index 29a837251..1503b30a9 100644
@@ -167,6 +167,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_vm.c +1 -1
index 479ded70f..28269c604 100644
@@ -1856,6 +1856,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_waitfence.c +1 -1
index c6b2db125..d2e422f83 100644
@@ -132,6 +132,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#32 lore raw

PATCH v4 21/24 tests/i915: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

V2: - New patch for generic tests
V3: - Rebase

---
 tests/i915/api_intel_allocator.c            |  6 ++--
 tests/i915/api_intel_bb.c                   |  2 +-
 tests/i915/drm_fdinfo.c                     |  2 +-
 tests/i915/gem_bad_reloc.c                  |  2 +-
 tests/i915/gem_barrier_race.c               |  2 +-
 tests/i915/gem_basic.c                      |  2 +-
 tests/i915/gem_blits.c                      |  2 +-
 tests/i915/gem_busy.c                       |  2 +-
 tests/i915/gem_caching.c                    |  2 +-
 tests/i915/gem_ccs.c                        |  2 +-
 tests/i915/gem_close_race.c                 | 12 ++++----
 tests/i915/gem_cs_tlb.c                     |  2 +-
 tests/i915/gem_ctx_bad_destroy.c            |  2 +-
 tests/i915/gem_ctx_create.c                 |  4 +--
 tests/i915/gem_ctx_exec.c                   |  2 +-
 tests/i915/gem_ctx_param.c                  |  2 +-
 tests/i915/gem_ctx_persistence.c            |  6 ++--
 tests/i915/gem_ctx_shared.c                 |  2 +-
 tests/i915/gem_ctx_sseu.c                   |  2 +-
 tests/i915/gem_ctx_switch.c                 |  2 +-
 tests/i915/gem_eio.c                        | 16 +++++------
 tests/i915/gem_evict_alignment.c            |  2 +-
 tests/i915/gem_evict_everything.c           |  2 +-
 tests/i915/gem_exec_alignment.c             |  2 +-
 tests/i915/gem_exec_async.c                 |  2 +-
 tests/i915/gem_exec_await.c                 |  2 +-
 tests/i915/gem_exec_basic.c                 |  2 +-
 tests/i915/gem_exec_big.c                   |  2 +-
 tests/i915/gem_exec_capture.c               |  2 +-
 tests/i915/gem_exec_create.c                |  2 +-
 tests/i915/gem_exec_fair.c                  |  2 +-
 tests/i915/gem_exec_fence.c                 |  4 +--
 tests/i915/gem_exec_flush.c                 |  2 +-
 tests/i915/gem_exec_gttfill.c               |  4 +--
 tests/i915/gem_exec_latency.c               |  2 +-
 tests/i915/gem_exec_nop.c                   |  2 +-
 tests/i915/gem_exec_parallel.c              |  4 +--
 tests/i915/gem_exec_params.c                |  2 +-
 tests/i915/gem_exec_reloc.c                 |  2 +-
 tests/i915/gem_exec_schedule.c              |  2 +-
 tests/i915/gem_exec_store.c                 |  2 +-
 tests/i915/gem_exec_suspend.c               |  2 +-
 tests/i915/gem_exec_whisper.c               |  6 ++--
 tests/i915/gem_exercise_blt.c               |  2 +-
 tests/i915/gem_fd_exhaustion.c              |  2 +-
 tests/i915/gem_fence_thrash.c               |  2 +-
 tests/i915/gem_fenced_exec_thrash.c         |  2 +-
 tests/i915/gem_flink_basic.c                |  4 +--
 tests/i915/gem_flink_race.c                 |  6 ++--
 tests/i915/gem_gtt_cpu_tlb.c                |  2 +-
 tests/i915/gem_gtt_hog.c                    |  2 +-
 tests/i915/gem_gtt_speed.c                  |  2 +-
 tests/i915/gem_huc_copy.c                   |  2 +-
 tests/i915/gem_lmem_evict.c                 |  4 +--
 tests/i915/gem_lmem_swapping.c              | 10 +++----
 tests/i915/gem_madvise.c                    | 12 ++++----
 tests/i915/gem_media_fill.c                 |  2 +-
 tests/i915/gem_mmap.c                       |  2 +-
 tests/i915/gem_mmap_gtt.c                   |  6 ++--
 tests/i915/gem_mmap_offset.c                |  8 +++---
 tests/i915/gem_mmap_wc.c                    |  2 +-
 tests/i915/gem_partial_pwrite_pread.c       |  2 +-
 tests/i915/gem_pipe_control_store_loop.c    |  2 +-
 tests/i915/gem_ppgtt.c                      |  8 +++---
 tests/i915/gem_pread.c                      |  2 +-
 tests/i915/gem_pread_after_blit.c           |  2 +-
 tests/i915/gem_pwrite.c                     |  2 +-
 tests/i915/gem_pwrite_snooped.c             |  2 +-
 tests/i915/gem_pxp.c                        |  2 +-
 tests/i915/gem_read_read_speed.c            |  2 +-
 tests/i915/gem_readwrite.c                  |  2 +-
 tests/i915/gem_reg_read.c                   |  2 +-
 tests/i915/gem_render_copy.c                |  2 +-
 tests/i915/gem_render_copy_redux.c          |  2 +-
 tests/i915/gem_reset_stats.c                | 32 ++++++++++-----------
 tests/i915/gem_ringfill.c                   |  2 +-
 tests/i915/gem_set_tiling_vs_blt.c          |  2 +-
 tests/i915/gem_set_tiling_vs_gtt.c          |  2 +-
 tests/i915/gem_set_tiling_vs_pwrite.c       |  2 +-
 tests/i915/gem_shrink.c                     | 14 ++++-----
 tests/i915/gem_softpin.c                    |  4 +--
 tests/i915/gem_spin_batch.c                 |  2 +-
 tests/i915/gem_streaming_writes.c           |  2 +-
 tests/i915/gem_stress.c                     |  2 +-
 tests/i915/gem_sync.c                       |  2 +-
 tests/i915/gem_tiled_blits.c                |  2 +-
 tests/i915/gem_tiled_fence_blits.c          |  2 +-
 tests/i915/gem_tiled_partial_pwrite_pread.c |  2 +-
 tests/i915/gem_tiled_pread_basic.c          |  2 +-
 tests/i915/gem_tiled_pread_pwrite.c         |  2 +-
 tests/i915/gem_tiled_swapping.c             |  2 +-
 tests/i915/gem_tiled_wb.c                   |  2 +-
 tests/i915/gem_tiled_wc.c                   |  2 +-
 tests/i915/gem_tiling_max_stride.c          |  2 +-
 tests/i915/gem_unfence_active_buffers.c     |  2 +-
 tests/i915/gem_unref_active_buffers.c       |  2 +-
 tests/i915/gem_userptr_blits.c              |  6 ++--
 tests/i915/gem_vm_create.c                  |  4 +--
 tests/i915/gem_wait.c                       |  2 +-
 tests/i915/gem_watchdog.c                   |  2 +-
 tests/i915/gem_workarounds.c                |  2 +-
 tests/i915/gen7_exec_parse.c                |  4 +--
 tests/i915/gen9_exec_parse.c                |  2 +-
 tests/i915/i915_fb_tiling.c                 |  2 +-
 tests/i915/i915_getparams_basic.c           |  2 +-
 tests/i915/i915_hangman.c                   |  4 +--
 tests/i915/i915_hwmon.c                     |  2 +-
 tests/i915/i915_module_load.c               |  8 +++---
 tests/i915/i915_pciid.c                     |  2 +-
 tests/i915/i915_pm_backlight.c              |  2 +-
 tests/i915/i915_pm_dc.c                     |  2 +-
 tests/i915/i915_pm_freq_api.c               |  2 +-
 tests/i915/i915_pm_freq_mult.c              |  2 +-
 tests/i915/i915_pm_lpsp.c                   |  2 +-
 tests/i915/i915_pm_rc6_residency.c          |  2 +-
 tests/i915/i915_pm_rps.c                    |  2 +-
 tests/i915/i915_pm_sseu.c                   |  2 +-
 tests/i915/i915_power.c                     |  2 +-
 tests/i915/i915_query.c                     |  2 +-
 tests/i915/i915_suspend.c                   |  6 ++--
 tests/i915/perf.c                           |  6 ++--
 tests/i915/perf_pmu.c                       |  6 ++--
 tests/i915/sysfs_defaults.c                 |  2 +-
 tests/i915/sysfs_heartbeat_interval.c       |  2 +-
 tests/i915/sysfs_preempt_timeout.c          |  2 +-
 tests/i915/sysfs_timeslice_duration.c       |  2 +-
 126 files changed, 205 insertions(+), 205 deletions(-)
tests/i915/api_intel_allocator.c +3 -3
index cc6f8daa4..b7e3efb87 100644
@@ -579,7 +579,7 @@ static void reopen(int fd)
 
 	__reopen_allocs(fd, fd2, true);
 
-	close(fd2);
+	drm_close_driver(fd2);
 }
 
 #define REOPEN_TIMEOUT 3
@@ -605,7 +605,7 @@ static void reopen_fork(int fd)
 	/* Check references at the end */
 	__reopen_allocs(fd, fd2, true);
 
-	close(fd2);
+	drm_close_driver(fd2);
 
 	intel_allocator_multiprocess_stop();
 }
@@ -924,5 +924,5 @@ igt_main
 		gem_pool(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/api_intel_bb.c +1 -1
index 85ca86eed..47049ba23 100644
@@ -1908,6 +1908,6 @@ igt_main_args("dpibc:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/drm_fdinfo.c +1 -1
index d061e901f..c0e0ba190 100644
@@ -910,6 +910,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_bad_reloc.c +1 -1
index d5336b62d..b058639ea 100644
@@ -231,5 +231,5 @@ igt_main
 		negative_reloc_blt(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_barrier_race.c +1 -1
index 0ac1da3a4..591ddc222 100644
@@ -120,7 +120,7 @@ static void intel_context_first_pin_last_unpin_loop(int fd, uint64_t engine, int
 
 	} while (!READ_ONCE(*done));
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_remote_request(int fd, uint64_t engine, unsigned int timeout)
tests/i915/gem_basic.c +1 -1
index 6843bec16..3485f92c8 100644
@@ -145,7 +145,7 @@ igt_main
 			gpu_fd = __drm_open_driver_another(child, DRIVER_INTEL);
 			igt_assert_f(gpu_fd > 0, "cannot open gpu-%d, errno=%d\n", child, errno);
 			test_create_close(gpu_fd);
-			close(gpu_fd);
+			drm_close_driver(gpu_fd);
 		}
 
 		igt_waitchildren();
tests/i915/gem_blits.c +1 -1
index 681fe0466..9b268e9dc 100644
@@ -904,6 +904,6 @@ igt_main
 
 	igt_fixture {
 		put_ahnd(device.ahnd);
-		close(device.fd);
+		drm_close_driver(device.fd);
 	}
 }
tests/i915/gem_busy.c +1 -1
index b796ebb2b..c60654b1e 100644
@@ -617,6 +617,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_caching.c +1 -1
index 7af427d7e..6a4da122b 100644
@@ -356,6 +356,6 @@ igt_main
 		intel_buf_destroy(scratch_buf);
 		intel_buf_destroy(staging_buf);
 		buf_ops_destroy(data.bops);
-		close(data.fd);
+		drm_close_driver(data.fd);
 	}
 }
tests/i915/gem_ccs.c +1 -1
index d38ab49a4..4581b6489 100644
@@ -764,6 +764,6 @@ igt_main_args("bf:pst:W:H:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_disallow_hang(i915, hang);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_close_race.c +6 -6
index 22cdc5874..cef0ff025 100644
@@ -329,7 +329,7 @@ static void multigpu_threads(int timeout, unsigned int flags, int gpu_count)
 
 		igt_waitchildren();
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_waitchildren();
@@ -348,7 +348,7 @@ static void threads(int timeout, unsigned int flags)
 	igt_waitchildren();
 
 	gem_quiescent_gpu(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -372,7 +372,7 @@ igt_main
 		gpu_count = igt_device_filter_count();
 
 		igt_fork_hang_detector(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Basic workload submission.");
@@ -384,7 +384,7 @@ igt_main
 		igt_waitchildren();
 
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Basic workload submission on multi-GPU machine.");
@@ -397,7 +397,7 @@ igt_main
 			igt_assert(fd > 0);
 			process(fd, child);
 			gem_quiescent_gpu(fd);
-			close(fd);
+			drm_close_driver(fd);
 		}
 
 		igt_waitchildren();
@@ -424,7 +424,7 @@ igt_main
 		igt_waitchildren();
 
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Share buffer handle across different drm fd's and trying to race"
tests/i915/gem_cs_tlb.c +1 -1
index 3f285f42c..2c7781d06 100644
@@ -174,5 +174,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_bad_destroy.c +1 -1
index 8c47e7c1c..65f6b5583 100644
@@ -98,5 +98,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_create.c +2 -2
index 95e219482..6d0877954 100644
@@ -206,7 +206,7 @@ static void files(int core, const intel_ctx_cfg_t *cfg,
 			gem_execbuf(fd, &execbuf);
 
 			intel_ctx_destroy(fd, ctx);
-			close(fd);
+			drm_close_driver(fd);
 			count++;
 
 			clock_gettime(CLOCK_MONOTONIC, &end);
@@ -756,6 +756,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_exec.c +1 -1
index f3939df86..4376397a2 100644
@@ -403,7 +403,7 @@ static void nohangcheck_hostile(int i915)
 	put_ahnd(ahnd);
 
 	close(dir);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 static void close_race(int i915)
tests/i915/gem_ctx_param.c +1 -1
index 7c59fe3ed..9b44c86a0 100644
@@ -636,5 +636,5 @@ igt_main
 		test_get_invalid_param(fd, I915_CONTEXT_PARAM_ENGINES);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_persistence.c +3 -3
index d2558354e..c6e2c5d77 100644
@@ -791,7 +791,7 @@ static void test_nonpersistent_file(int i915)
 	gem_context_set_persistence(i915, 0, false);
 	spin = igt_spin_new(i915, .ahnd = ahnd, .flags = IGT_SPIN_FENCE_OUT);
 
-	close(i915);
+	drm_close_driver(i915);
 	flush_delayed_fput(debugfs);
 
 	igt_assert_eq(wait_for_status(spin->out_fence, reset_timeout_ms), -EIO);
@@ -1274,7 +1274,7 @@ static void __smoker(int i915, const intel_ctx_cfg_t *cfg,
 
 	intel_ctx_destroy(fd, ctx);
 
-	close(fd);
+	drm_close_driver(fd);
 	flush_delayed_fput(i915);
 
 	igt_spin_end(spin);
@@ -1570,6 +1570,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_ctx_shared.c +1 -1
index ede6db13b..d24ae5483 100644
@@ -315,7 +315,7 @@ static void exhaust_shared_gtt(int i915, unsigned int flags)
 		igt_info("Created %lu shared contexts, before %d (%s)\n",
 			 count, err, strerror(-err));
 	}
-	close(i915);
+	drm_close_driver(i915);
 	igt_waitchildren();
 }
 
tests/i915/gem_ctx_sseu.c +1 -1
index 78748c24d..3a01944e4 100644
@@ -559,6 +559,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_switch.c +1 -1
index b0066ab27..f94a41bec 100644
@@ -805,6 +805,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(fd, heavy);
 		gem_close(fd, light);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_eio.c +8 -8
index 38fd19e89..d889d67dc 100644
@@ -656,7 +656,7 @@ static void test_banned(int fd)
 {
 	fd = reopen_device(fd);
 	__test_banned(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 #define TEST_WEDGE (1)
@@ -690,7 +690,7 @@ static void test_wait(int fd, unsigned int flags, unsigned int wait)
 	igt_require(i915_reset_control(fd, true));
 
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_suspend(int fd, int state)
@@ -708,7 +708,7 @@ static void test_suspend(int fd, int state)
 
 	igt_require(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_inflight(int fd, unsigned int wait)
@@ -772,7 +772,7 @@ static void test_inflight(int fd, unsigned int wait)
 		trigger_reset(fd);
 
 		gem_close(fd, obj[1].handle);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
 
@@ -833,7 +833,7 @@ static void test_inflight_suspend(int fd)
 
 	igt_assert(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static const intel_ctx_t *context_create_safe(int i915)
@@ -923,7 +923,7 @@ static void test_inflight_contexts(int fd, unsigned int wait)
 		for (unsigned int n = 0; n < ARRAY_SIZE(ctx); n++)
 			intel_ctx_destroy(fd, ctx[n]);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
 
@@ -979,7 +979,7 @@ static void test_inflight_external(int fd)
 	put_ahnd(ahnd);
 	igt_assert(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_inflight_internal(int fd, unsigned int wait)
@@ -1029,7 +1029,7 @@ static void test_inflight_internal(int fd, unsigned int wait)
 
 	igt_assert(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void reset_stress(int fd, uint64_t ahnd, const intel_ctx_t *ctx0,
tests/i915/gem_evict_alignment.c +1 -1
index f04f24972..4a9507a06 100644
@@ -282,6 +282,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_evict_everything.c +1 -1
index 87f854bf8..f0f356cc3 100644
@@ -351,6 +351,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_alignment.c +1 -1
index 9d965270f..10732fec5 100644
@@ -487,7 +487,7 @@ static void forked(int i915, int timeout)
 	igt_waitchildren_timeout(3 * timeout, NULL);
 
 	free(obj);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 static void single(int fd)
tests/i915/gem_exec_async.c +1 -1
index f3c2f671f..8c131d8e1 100644
@@ -227,6 +227,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_await.c +1 -1
index c78403466..53b7bac2f 100644
@@ -300,6 +300,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_basic.c +1 -1
index 623f1ee52..83f71e289 100644
@@ -113,6 +113,6 @@ igt_main
 		igt_collection_destroy(set);
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_big.c +1 -1
index 3acdb3741..9de9941d5 100644
@@ -340,5 +340,5 @@ igt_main
 		exhaustive(i915);
 
 	igt_fixture
-		close(i915);
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_capture.c +1 -1
index 453ae1af9..ab8305e4d 100644
@@ -1055,6 +1055,6 @@ igt_main
 		close(dir);
 		igt_disallow_hang(fd, hang);
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_create.c +1 -1
index 00c190115..4eb77ecbb 100644
@@ -270,6 +270,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_fair.c +1 -1
index eedcfdf80..5ad13f97a 100644
@@ -1440,6 +1440,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_fence.c +2 -2
index d6253a379..4bf29a3e4 100644
@@ -2118,7 +2118,7 @@ static void test_invalid_timeline_fence_array(int fd)
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EFAULT);
 
 	munmap(ptr, 4096);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static const char *test_syncobj_timeline_unused_fence_desc =
@@ -3701,6 +3701,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_flush.c +1 -1
index e213bda5e..3902ee957 100644
@@ -2207,6 +2207,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_gttfill.c +2 -2
index 4c32a04c0..28c251915 100644
@@ -314,7 +314,7 @@ igt_main
 			// release resources
 			igt_stop_hang_detector();
 			intel_ctx_destroy(g_fd, ctx);
-			close(g_fd);
+			drm_close_driver(g_fd);
 		}
 
 		igt_waitchildren();
@@ -322,6 +322,6 @@ igt_main
 
 	igt_fixture {
 		intel_allocator_multiprocess_stop();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_latency.c +1 -1
index 9a9e43bab..c0e607f97 100644
@@ -1001,6 +1001,6 @@ igt_main
 	igt_fixture {
 		intel_register_access_fini(&mmio_data);
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_nop.c +1 -1
index 067c92b47..6dea8b167 100644
@@ -1150,6 +1150,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(device, handle);
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_parallel.c +2 -2
index bba861185..cae1553f6 100644
@@ -230,7 +230,7 @@ static void *thread(void *data)
 		intel_ctx_destroy(fd, tmp_ctx);
 	gem_close(fd, obj[1].handle);
 	if (t->flags & FDS)
-		close(fd);
+		drm_close_driver(fd);
 
 	t->used = used;
 	return NULL;
@@ -413,6 +413,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_params.c +1 -1
index 16ae7a5a6..caaa5fee0 100644
@@ -825,6 +825,6 @@ igt_main
 	igt_fixture {
 		gem_close(fd, handle);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_reloc.c +1 -1
index c591f374d..8259ff1d9 100644
@@ -1771,5 +1771,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_exec_schedule.c +1 -1
index c9be726ab..c94988d36 100644
@@ -3755,6 +3755,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_store.c +1 -1
index d61072dfa..0ab931062 100644
@@ -480,6 +480,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_suspend.c +1 -1
index 73fbf8cf6..39d75ee03 100644
@@ -510,6 +510,6 @@ igt_main
 		igt_collection_destroy(set);
 		igt_disallow_hang(fd, hang);
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_whisper.c +3 -3
index 1379f10dc..46712c3e8 100644
@@ -457,7 +457,7 @@ static void fini_hang(struct hang *h)
 	put_offset(h->ahnd, h->obj.handle);
 	put_ahnd(h->ahnd);
 	intel_ctx_destroy(h->fd, h->ctx);
-	close(h->fd);
+	drm_close_driver(h->fd);
 }
 
 static void ctx_set_random_priority(int fd, uint32_t ctx)
@@ -829,7 +829,7 @@ static void whisper(int fd, const intel_ctx_t *ctx,
 			gem_close(fd, batches[n].handle);
 		if (flags & FDS) {
 			for (n = 0; n < 64; n++)
-				close(fds[n]);
+				drm_close_driver(fds[n]);
 		}
 	}
 
@@ -939,6 +939,6 @@ igt_main
 	igt_fixture {
 		intel_allocator_multiprocess_stop();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exercise_blt.c +1 -1
index 89f89d212..8c70c941c 100644
@@ -398,6 +398,6 @@ igt_main_args("b:pst:W:H:", NULL, help_str, opt_handler, NULL)
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_fd_exhaustion.c +1 -1
index 75485c1cb..e79d03478 100644
@@ -75,5 +75,5 @@ igt_simple_main
 
 	igt_waitchildren();
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_fence_thrash.c +1 -1
index f8ac29dd7..4cb3d842b 100644
@@ -244,7 +244,7 @@ static int run_test(int threads_per_fence, void *f, int tiling,
 		igt_assert(func(&t) == (void *)0);
 	}
 
-	close(t.fd);
+	drm_close_driver(t.fd);
 
 	return 0;
 }
tests/i915/gem_fenced_exec_thrash.c +1 -1
index f22f16f68..098f22ef4 100644
@@ -217,5 +217,5 @@ igt_main
 		run_test(fd, num_fences + 1, intel_gen(devid) >= 4 ? 0 : ENOBUFS, 0);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_flink_basic.c +2 -2
index 8a316cdae..e70cab4d1 100644
@@ -196,7 +196,7 @@ test_flink_lifetime(int fd)
 	igt_assert_eq(ret, 0);
 	igt_assert(open_struct.handle != 0);
 
-	close(fd2);
+	drm_close_driver(fd2);
 	fd2 = drm_open_driver(DRIVER_INTEL);
 
 	/* Flink name remains valid due to the second reference */
@@ -205,7 +205,7 @@ test_flink_lifetime(int fd)
 	igt_assert_eq(ret, 0);
 	igt_assert(open_struct.handle != 0);
 
-	close(fd2);
+	drm_close_driver(fd2);
 }
 
 igt_main
tests/i915/gem_flink_race.c +3 -3
index a9177ce1b..41c15f298 100644
@@ -141,7 +141,7 @@ static void test_flink_name(int timeout)
 		 igt_stats_get_max(&stats));
 	igt_stats_fini(&stats);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void *thread_fn_flink_close(void *p)
@@ -202,13 +202,13 @@ static void test_flink_close(void)
 		igt_assert(status == 0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
tests/i915/gem_gtt_cpu_tlb.c +1 -1
index 4f4af6a7b..155aa6516 100644
@@ -113,5 +113,5 @@ igt_simple_main
 	for (i = 0; i < OBJ_SIZE/4; i++)
 		igt_assert(ptr[i] == i);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_gtt_hog.c +1 -1
index 4c8158c6d..1227c7633 100644
@@ -170,7 +170,7 @@ igt_simple_main
 	int fd = drm_open_driver(DRIVER_INTEL);
 	igt_require_gem(fd);
 	gem_require_mappable_ggtt(fd);
-	close(fd);
+	drm_close_driver(fd);
 
 	data.fd = drm_open_driver(DRIVER_INTEL);
 	data.devid = intel_get_drm_devid(data.fd);
tests/i915/gem_gtt_speed.c +1 -1
index a0e37b19e..c85c359a0 100644
@@ -521,5 +521,5 @@ igt_simple_main_args("s:", NULL, help_str, opt_handler, NULL)
 	}
 
 	gem_close(fd, handle);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_huc_copy.c +1 -1
index 5a217c984..246fa0a8b 100644
@@ -150,6 +150,6 @@ igt_main
 
 	igt_fixture {
 		put_ahnd(ahnd);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/i915/gem_lmem_evict.c +2 -2
index 54277e11d..a3ca2c861 100644
@@ -103,7 +103,7 @@ igt_main
 			igt_require_fd(i915);
 			igt_require_gem(i915);
 			igt_require(gem_has_lmem(i915));
-			close(i915);
+			drm_close_driver(i915);
 		}
 
 		igt_i915_driver_unload();
@@ -142,7 +142,7 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 		igt_i915_driver_unload();
 	}
 }
tests/i915/gem_lmem_swapping.c +5 -5
index 8211edbe3..a04d0a5f8 100644
@@ -718,7 +718,7 @@ static void test_evict(int i915,
 
 		igt_waitchildren();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 		intel_allocator_multiprocess_stop();
 	} else {
 		__do_evict(i915, ctx, &region->region, &params, params.seed);
@@ -790,7 +790,7 @@ static void test_smem_oom(int i915,
 			   params.seed + child + 1);
 
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	/* smem memory hog process, respawn till the lmem process completes */
@@ -811,7 +811,7 @@ static void test_smem_oom(int i915,
 						break;
 					gem_leak(fd, alloc);
 				}
-				close(fd);
+				drm_close_driver(fd);
 			}
 			/*
 			 * Wait for grand-child processes to finish or be
@@ -903,7 +903,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 			igt_require_fd(i915);
 			igt_require_gem(i915);
 			igt_require(gem_has_lmem(i915));
-			close(i915);
+			drm_close_driver(i915);
 		}
 
 		igt_i915_driver_unload();
@@ -948,7 +948,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
 		free(regions);
-		close(i915);
+		drm_close_driver(i915);
 		igt_i915_driver_unload();
 	}
 
tests/i915/gem_madvise.c +6 -6
index 4efa359ba..765809e7f 100644
@@ -110,7 +110,7 @@ dontneed_before_mmap(void)
 					PROT_READ | PROT_WRITE,
 					t->type);
 
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -132,7 +132,7 @@ dontneed_before_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -156,7 +156,7 @@ dontneed_after_mmap(void)
 					t->type);
 
 		gem_madvise(fd, handle, I915_MADV_DONTNEED);
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -178,7 +178,7 @@ dontneed_after_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -194,7 +194,7 @@ dontneed_before_pwrite(void)
 
 	igt_assert_eq(__gem_write(fd, handle, 0, &bbe, sizeof(bbe)), -EFAULT);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -218,7 +218,7 @@ dontneed_before_exec(void)
 	execbuf.batch_len = sizeof(buf);
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EFAULT);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
tests/i915/gem_media_fill.c +1 -1
index 07e7b3ccb..a678d2f99 100644
@@ -181,6 +181,6 @@ igt_main
 	igt_fixture {
 		igt_collection_destroy(set);
 		igt_stop_hang_detector();
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/gem_mmap.c +1 -1
index 421c6f859..d4ca1eda7 100644
@@ -372,5 +372,5 @@ igt_main
 		test_huge_bo(2);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_gtt.c +3 -3
index e5d3aa079..9c06785d2 100644
@@ -869,13 +869,13 @@ test_isolation(int i915)
 	igt_info("B: {fd:%d, handle:%d, offset:%"PRIx64"}\n",
 		 B, b, offset_b);
 
-	close(B);
+	drm_close_driver(B);
 
 	ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 	igt_assert(ptr != MAP_FAILED);
 	munmap(ptr, 4096);
 
-	close(A);
+	drm_close_driver(A);
 
 	ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 	igt_assert(ptr == MAP_FAILED);
@@ -1979,5 +1979,5 @@ igt_main
 
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_offset.c +4 -4
index 2537ecdc5..bc801cd04 100644
@@ -434,13 +434,13 @@ static void isolation(int i915)
 				igt_assert_eq(errno, EACCES);
 			}
 
-			close(B);
+			drm_close_driver(B);
 
 			ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 			igt_assert(ptr != MAP_FAILED);
 			munmap(ptr, 4096);
 
-			close(A);
+			drm_close_driver(A);
 
 			ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 			igt_assert(ptr == MAP_FAILED);
@@ -735,7 +735,7 @@ static void open_flood(int i915, int timeout)
 			mmap_offset_ioctl(i915, &arg);
 		}
 
-		close(tmp);
+		drm_close_driver(tmp);
 		count++;
 	}
 
@@ -1013,6 +1013,6 @@ igt_main
 		blt_coherency(i915);
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_mmap_wc.c +1 -1
index ce1c19083..c56e8c353 100644
@@ -687,5 +687,5 @@ igt_main
 		test_set_cache_level(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_partial_pwrite_pread.c +1 -1
index 1b533ef30..659a96b6e 100644
@@ -388,6 +388,6 @@ igt_main
 		intel_buf_destroy(scratch_buf);
 		intel_buf_destroy(staging_buf);
 		buf_ops_destroy(data.bops);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/gem_pipe_control_store_loop.c +1 -1
index 986dbf673..1913b874a 100644
@@ -199,6 +199,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ppgtt.c +4 -4
index 9dc6ccfe4..b6081b1e9 100644
@@ -278,8 +278,8 @@ static void flink_and_close(void)
 	igt_assert_eq(offset, offset_new);
 
 	gem_close(fd, bo);
-	close(fd);
-	close(fd2);
+	drm_close_driver(fd);
+	drm_close_driver(fd2);
 }
 
 #define PAGE_SIZE 4096
@@ -412,7 +412,7 @@ static bool has_contexts(void)
 
 	fd = drm_open_driver(DRIVER_INTEL);
 	result = gem_has_contexts(fd);
-	close(fd);
+	drm_close_driver(fd);
 
 	return result;
 }
@@ -425,7 +425,7 @@ igt_main
 		int fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
 		gem_require_blitter(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("blt-vs-render-ctx0") {
tests/i915/gem_pread.c +1 -1
index 1dbded440..6f50785da 100644
@@ -367,6 +367,6 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 		free(src);
 		gem_close(fd, dst);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_pread_after_blit.c +1 -1
index fc6ee4408..b3e20697d 100644
@@ -281,5 +281,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_pwrite.c +1 -1
index 8471f963d..e2b48b843 100644
@@ -639,5 +639,5 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_pwrite_snooped.c +1 -1
index 7135dca57..5d9e8da20 100644
@@ -148,5 +148,5 @@ igt_simple_main
 	test(256, 256);
 
 	buf_ops_destroy(bops);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_pxp.c +1 -1
index 167877d31..4aea765fe 100644
@@ -1372,6 +1372,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_read_read_speed.c +1 -1
index 7eeba7c6a..95ef47da6 100644
@@ -275,6 +275,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_readwrite.c +1 -1
index fdc68e315..864a2d8d8 100644
@@ -158,5 +158,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_reg_read.c +1 -1
index 5f63c02f7..de6788abe 100644
@@ -181,6 +181,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_render_copy.c +1 -1
index 657509647..406c30915 100644
@@ -999,6 +999,6 @@ igt_main_args("dac", NULL, help_str, opt_handler, NULL)
 		igt_stop_hang_detector();
 		buf_ops_destroy(data.bops);
 		igt_collection_destroy(set);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/gem_render_copy_redux.c +1 -1
index 0cb2936d3..06777dd7f 100644
@@ -98,7 +98,7 @@ static void data_init(data_t *data)
 static void data_fini(data_t *data)
 {
 	buf_ops_destroy(data->bops);
-	close(data->fd);
+	drm_close_driver(data->fd);
 }
 
 static void scratch_buf_init(data_t *data, struct intel_buf *buf,
tests/i915/gem_reset_stats.c +16 -16
index 7ec9264b5..6939722c7 100644
@@ -475,7 +475,7 @@ static void test_rs(const struct intel_execution_ring *e,
 	igt_assert(igt_seconds_elapsed(&ts_injected) <= 30);
 
 	for (i = 0; i < num_fds; i++)
-		close(fd[i]);
+		drm_close_driver(fd[i]);
 }
 
 #define MAX_CTX 100
@@ -551,7 +551,7 @@ static void test_rs_ctx(const struct intel_execution_ring *e,
 
 	for (i = 0; i < num_fds; i++) {
 		assert_reset_status(i, fd[i], 0, RS_NO_ERROR);
-		close(fd[i]);
+		drm_close_driver(fd[i]);
 	}
 }
 
@@ -605,8 +605,8 @@ static void test_ban(const struct intel_execution_ring *e)
 	igt_assert_eq(gem_reset_stats(fd_good, 0, &rs_good), 0);
 	igt_assert_eq(rs_good.batch_active, 0);
 
-	close(fd_bad);
-	close(fd_good);
+	drm_close_driver(fd_bad);
+	drm_close_driver(fd_good);
 }
 
 static void test_ban_ctx(const struct intel_execution_ring *e)
@@ -664,7 +664,7 @@ static void test_ban_ctx(const struct intel_execution_ring *e)
 	igt_assert_eq(gem_reset_stats(fd, ctx_good, &rs_good), 0);
 	igt_assert_eq(rs_good.batch_active, 0);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_unrelated_ctx(const struct intel_execution_ring *e)
@@ -690,8 +690,8 @@ static void test_unrelated_ctx(const struct intel_execution_ring *e)
 	assert_reset_status(0, fd1, ctx_guilty, RS_BATCH_ACTIVE);
 	assert_reset_status(1, fd2, ctx_unrelated, RS_NO_ERROR);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static int get_reset_count(int fd, int ctx)
@@ -717,7 +717,7 @@ static void test_close_pending_ctx(const struct intel_execution_ring *e)
 	gem_context_destroy(fd, ctx);
 	igt_assert_eq(__gem_context_destroy(fd, ctx), -ENOENT);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_close_pending(const struct intel_execution_ring *e)
@@ -727,7 +727,7 @@ static void test_close_pending(const struct intel_execution_ring *e)
 	assert_reset_status(fd, fd, 0, RS_NO_ERROR);
 
 	inject_hang(fd, 0, e, 0);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void noop_on_each_ring(int fd, const bool reverse)
@@ -789,7 +789,7 @@ static void test_close_pending_fork(const struct intel_execution_ring *e,
 		 * when gpu is reset and ring lists are cleared.
 		 */
 		noop_on_each_ring(fd2, reverse);
-		close(fd2);
+		drm_close_driver(fd2);
 		pause();
 		exit(0);
 	} else {
@@ -802,7 +802,7 @@ static void test_close_pending_fork(const struct intel_execution_ring *e,
 	}
 
 	igt_post_hang_ring(fd, hang);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_reset_count(const struct intel_execution_ring *e,
@@ -842,7 +842,7 @@ static void test_reset_count(const struct intel_execution_ring *e,
 	if (create_ctx)
 		gem_context_destroy(fd, ctx);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static int _test_params(int fd, int ctx, uint32_t flags, uint32_t pad)
@@ -913,7 +913,7 @@ static void test_params_ctx(void)
 
 	fd = drm_reopen_driver(device);
 	_test_param(fd, gem_context_create(fd));
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_params(void)
@@ -922,7 +922,7 @@ static void test_params(void)
 
 	fd = drm_reopen_driver(device);
 	_test_param(fd, 0);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static const struct intel_execution_ring *
@@ -968,7 +968,7 @@ static void defer_hangcheck(const struct intel_execution_ring *engine)
 
 	igt_assert_lt(count_start, count_end);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static bool gem_has_reset_stats(int fd)
@@ -1177,6 +1177,6 @@ igt_main
 	}
 	igt_fixture {
 		igt_assert(igt_params_set(device, "reset", "%d", INT_MAX /* any reset method */));
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_ringfill.c +1 -1
index 52471948e..c718d6fe7 100644
@@ -522,6 +522,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_set_tiling_vs_blt.c +1 -1
index cee4591b8..e9d5e3c63 100644
@@ -276,6 +276,6 @@ igt_main
 
 	igt_fixture{
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_set_tiling_vs_gtt.c +1 -1
index 30b69bb8b..4a7ecdc88 100644
@@ -138,5 +138,5 @@ igt_simple_main
 
 	munmap(ptr, OBJECT_SIZE);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_set_tiling_vs_pwrite.c +1 -1
index 328682d94..ede0c58b6 100644
@@ -107,5 +107,5 @@ igt_simple_main
 
 	munmap(ptr, OBJECT_SIZE);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_shrink.c +7 -7
index 79301754b..1f16f8a78 100644
@@ -381,7 +381,7 @@ static bool has_userptr(void)
 	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr))
 		err = errno;
 
-	close(fd);
+	drm_close_driver(fd);
 
 	return err == EFAULT;
 }
@@ -430,7 +430,7 @@ static void run_test(int nchildren, uint64_t alloc,
 				int fd = drm_open_driver(DRIVER_INTEL);
 				for (int pass = 0; pass < nchildren; pass++)
 					leak(fd, alloc);
-				close(fd);
+				drm_close_driver(fd);
 			}
 		}
 	}
@@ -442,7 +442,7 @@ static void run_test(int nchildren, uint64_t alloc,
 				int fd = drm_open_driver(DRIVER_INTEL);
 				for (int pass = 0; pass < nchildren; pass++)
 					userptr(fd, alloc, 0);
-				close(fd);
+				drm_close_driver(fd);
 			}
 		}
 		nchildren = (nchildren + 1)/2;
@@ -455,7 +455,7 @@ static void run_test(int nchildren, uint64_t alloc,
 				int fd = drm_open_driver(DRIVER_INTEL);
 				for (int pass = 0; pass < nchildren; pass++)
 					userptr(fd, alloc, UDIRTY);
-				close(fd);
+				drm_close_driver(fd);
 			}
 		}
 		nchildren = (nchildren + 1)/2;
@@ -467,7 +467,7 @@ static void run_test(int nchildren, uint64_t alloc,
 			int fd = drm_open_driver(DRIVER_INTEL);
 			for (int pass = 0; pass < nchildren; pass++)
 				func(fd, alloc);
-			close(fd);
+			drm_close_driver(fd);
 		}
 	}
 	igt_waitchildren();
@@ -510,7 +510,7 @@ static void reclaim(unsigned engine, int timeout)
 
 	munmap((void *)shared, 4096);
 	close(debugfs);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -567,7 +567,7 @@ igt_main
 			 num_processes, alloc_size);
 
 		alloc_size <<= 20;
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("reclaim")
tests/i915/gem_softpin.c +2 -2
index 62478f4a3..e6cbf624e 100644
@@ -1433,7 +1433,7 @@ static void *thread(void *data)
 			  fd, ctx->id, t->engine, succeeded);
 	intel_ctx_destroy(fd, ctx);
 	gem_close(fd, obj[1].handle);
-	close(fd);
+	drm_close_driver(fd);
 
 	return (void *) from_user_pointer(ret);
 }
@@ -1747,6 +1747,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_spin_batch.c +1 -1
index cd828beb2..18873be16 100644
@@ -354,6 +354,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_streaming_writes.c +1 -1
index 2c59c08f6..fc2d3d89f 100644
@@ -448,5 +448,5 @@ igt_main
 		test_batch(fd, 2, 1);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_stress.c +1 -1
index 625b0e915..bf2e06d71 100644
@@ -933,7 +933,7 @@ igt_simple_main_args("ds:g:c:t:rbuxmo:fp:",
 	intel_bb_destroy(ibb);
 	buf_ops_destroy(bops);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 
 	igt_stop_signal_helper();
 }
tests/i915/gem_sync.c +1 -1
index 1ee5b3f3d..f98d4364c 100644
@@ -1606,6 +1606,6 @@ igt_main
 		intel_allocator_multiprocess_stop();
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_blits.c +1 -1
index 8c3951c6f..22ac3280d 100644
@@ -232,6 +232,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_fence_blits.c +1 -1
index 539601e5a..5444dcfb8 100644
@@ -335,5 +335,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_partial_pwrite_pread.c +1 -1
index a7e845e32..d4f66d51e 100644
@@ -330,6 +330,6 @@ igt_main
 		intel_buf_destroy(tiled_staging_buf);
 		buf_ops_destroy(bops);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_pread_basic.c +1 -1
index ddf9f0f56..a2253b51e 100644
@@ -230,5 +230,5 @@ igt_simple_main
 		}
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_pread_pwrite.c +1 -1
index 3331e61ad..2f0f6f547 100644
@@ -162,5 +162,5 @@ igt_simple_main
 		gem_madvise(fd, handle, I915_MADV_DONTNEED);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_swapping.c +1 -1
index fb633ecab..90ce70bdb 100644
@@ -256,5 +256,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_wb.c +1 -1
index 7f1afbc90..6a8b79ecc 100644
@@ -249,5 +249,5 @@ igt_simple_main
 		munmap(linear, last_page - first_page);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_wc.c +1 -1
index dc4e4d2d7..1994453b3 100644
@@ -250,5 +250,5 @@ igt_simple_main
 		munmap(linear, last_page - first_page);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiling_max_stride.c +1 -1
index 6001f72be..5943ed93f 100644
@@ -146,5 +146,5 @@ igt_simple_main
 
 	munmap(ptr, size);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_unfence_active_buffers.c +1 -1
index 1f25a81b1..d3bc1cee6 100644
@@ -107,5 +107,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
-	close(i915);
+	drm_close_driver(i915);
 }
tests/i915/gem_unref_active_buffers.c +1 -1
index badded1f7..47023a3a0 100644
@@ -133,5 +133,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
-	close(i915);
+	drm_close_driver(i915);
 }
tests/i915/gem_userptr_blits.c +3 -3
index e9235a689..ecbfdf94f 100644
@@ -1086,7 +1086,7 @@ static void test_nohangcheck_hostile(int i915)
 	close(fence);
 
 	close(dir);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 static size_t hugepagesize(void)
@@ -1644,9 +1644,9 @@ static int test_dmabuf(void)
 
 	/* destroy userptr object and expect SIGBUS */
 	free_userptr_bo(fd1, handle);
-	close(fd1);
+	drm_close_driver(fd1);
 
-	close(fd2);
+	drm_close_driver(fd2);
 	reset_handle_ptr();
 
 	return 0;
tests/i915/gem_vm_create.c +2 -2
index f24aefdae..8834c987f 100644
@@ -370,7 +370,7 @@ static void isolation(int i915)
 	gem_read(i915, obj[0].handle, 0, &result, sizeof(result));
 	igt_assert_eq(result, 1);
 
-	close(other);
+	drm_close_driver(other);
 
 	gem_close(i915, obj[1].handle);
 	gem_close(i915, obj[0].handle);
@@ -411,6 +411,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_wait.c +1 -1
index c1cd37e63..674deb57d 100644
@@ -336,6 +336,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_watchdog.c +1 -1
index 640a8cad8..1e4c35021 100644
@@ -597,6 +597,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_workarounds.c +1 -1
index da8cfa011..c5ca26c08 100644
@@ -305,7 +305,7 @@ static void check_workarounds(int fd, enum operation op, unsigned int flags)
 	if (flags & CONTEXT)
 		intel_ctx_destroy(fd, ctx);
 	if (flags & FD)
-		close(fd);
+		drm_close_driver(fd);
 }
 
 igt_main
tests/i915/gen7_exec_parse.c +2 -2
index 81a5bb14f..807cb1e9d 100644
@@ -476,7 +476,7 @@ static void hsw_load_register_reg(void)
 				   0xabcdabc0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -748,6 +748,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(fd, handle);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gen9_exec_parse.c +1 -1
index a927bfaca..33ff6bcb5 100644
@@ -1299,6 +1299,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(i915, handle);
 
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_fb_tiling.c +1 -1
index 586950266..14c17b030 100644
@@ -52,5 +52,5 @@ igt_simple_main
 	igt_assert_eq(ret, -EBUSY);
 
 	igt_remove_fb(drm_fd, &fb);
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
tests/i915/i915_getparams_basic.c +1 -1
index 74ccaf4d3..b22ab5d93 100644
@@ -62,7 +62,7 @@ init(void)
 static void
 deinit(void)
 {
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 
tests/i915/i915_hangman.c +2 -2
index fc46bd297..dcd34cd0e 100644
@@ -160,7 +160,7 @@ static void check_alive(void)
 	put_ahnd(ahnd);
 	intel_ctx_destroy(fd, ctx);
 	gem_quiescent_gpu(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static bool has_error_state(int dir)
@@ -643,6 +643,6 @@ igt_main
 
 		igt_disallow_hang(device, hang);
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/i915_hwmon.c +1 -1
index 279f6821b..48ed9f3b7 100644
@@ -96,6 +96,6 @@ igt_main
 
 	igt_fixture {
 		close(hwm);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_module_load.c +4 -4
index df24aee5e..9fffe93d9 100644
@@ -280,7 +280,7 @@ static void gem_sanitycheck(void)
 		store_all(i915);
 	errno = 0;
 
-	close(i915);
+	drm_close_driver(i915);
 	igt_assert_eq(err, expected);
 }
 
@@ -328,7 +328,7 @@ static void load_and_check_i915(void)
 
 	/* make sure the GPU is idle */
 	gem_quiescent_gpu(drm_fd);
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 
 	/* make sure we can do basic memory ops */
 	gem_sanitycheck();
@@ -369,7 +369,7 @@ static uint32_t  driver_load_with_lmem_bar_size(uint32_t lmem_bar_size, bool che
 		}
 	}
 
-	close(i915);
+	drm_close_driver(i915);
 
 	return lmem_bar_size;
 }
@@ -461,7 +461,7 @@ igt_main
 			igt_require_gem(i915);
 			igt_require(gem_has_lmem(i915));
 			igt_skip_on_f(igt_sysfs_get_num_gt(i915) > 1, "Skips for more than one lmem instance.\n");
-			close(i915);
+			drm_close_driver(i915);
 		}
 
 		/* Test for lmem_bar_size modparam support */
tests/i915/i915_pciid.c +1 -1
index c44be56dc..8322bd564 100644
@@ -77,5 +77,5 @@ igt_simple_main
 
 	igt_assert(has_known_intel_chipset(intel));
 
-	close(intel);
+	drm_close_driver(intel);
 }
tests/i915/i915_pm_backlight.c +1 -1
index b633387bc..3c73b054b 100644
@@ -357,6 +357,6 @@ igt_main
 
 		igt_display_fini(&display);
 		igt_pm_restore_sata_link_power_management();
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/i915/i915_pm_dc.c +1 -1
index 2bb07ba8b..5069ddcc3 100644
@@ -730,7 +730,7 @@ igt_main
 		close(data.debugfs_root_fd);
 		close(data.msr_fd);
 		display_fini(&data);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 
 	igt_exit();
tests/i915/i915_pm_freq_api.c +1 -1
index 9005cd220..7422493af 100644
@@ -150,6 +150,6 @@ igt_main
 			igt_assert(set_freq(dirfd, RPS_MAX_FREQ_MHZ, stash_max[gt]) > 0);
 			igt_assert(set_freq(dirfd, RPS_MIN_FREQ_MHZ, stash_min[gt]) > 0);
 		}
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_freq_mult.c +1 -1
index d75ec3f9e..af62bbc2c 100644
@@ -177,6 +177,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_lpsp.c +1 -1
index cb01a6d9e..291e56674 100644
@@ -223,6 +223,6 @@ igt_main
 	igt_fixture {
 		free(data.pwr_dmn_info);
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/i915_pm_rc6_residency.c +1 -1
index ce81e668a..b266680ac 100644
@@ -627,6 +627,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_rps.c +1 -1
index 238d39240..7044fcd81 100644
@@ -917,7 +917,7 @@ static void pm_rps_exit_handler(int sig)
 	if (lh.igt_proc.running)
 		load_helper_stop();
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 igt_main
tests/i915/i915_pm_sseu.c +1 -1
index 39eecb8fe..cee29a7c5 100644
@@ -323,7 +323,7 @@ gem_deinit(void)
 	case 2:
 		buf_ops_destroy(gem.bops);
 	case 1:
-		close(gem.drm_fd);
+		drm_close_driver(gem.drm_fd);
 	}
 }
 
tests/i915/i915_power.c +1 -1
index 3675b9d6d..ed7bef495 100644
@@ -86,6 +86,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_query.c +1 -1
index 194f2e91b..f97379b83 100644
@@ -1572,6 +1572,6 @@ igt_main
 		query_parse_and_validate_hwconfig_table(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_suspend.c +3 -3
index 9f0a4d2ac..851e797c2 100644
@@ -256,7 +256,7 @@ test_shrink(int fd, unsigned int mode)
 		igt_system_suspend_autoresume(mode, SUSPEND_TEST_NONE);
 
 		munmap(mem, size);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_waitchildren();
@@ -300,7 +300,7 @@ test_suspend_without_i915(int state)
 		igt_pm_get_d3cold_allowed(&card, d3cold_allowed);
 		igt_pm_set_d3cold_allowed(&card, "0\n");
 	}
-	close(fd);
+	drm_close_driver(fd);
 
 	igt_kmsg(KMSG_INFO "Unloading i915\n");
 	igt_assert_eq(igt_i915_driver_unload(),0);
@@ -383,5 +383,5 @@ igt_main
 		test_forcewake(fd, true);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/perf.c +3 -3
index 069ab8c02..3565d61cc 100644
@@ -4704,7 +4704,7 @@ gen12_test_single_ctx_render_target_writes_a_counter(const struct intel_executio
 			igt_drop_root();
 			gen12_single_ctx_helper(e);
 
-			close(drm_fd);
+			drm_close_driver(drm_fd);
 		}
 		child_ret = igt_wait_helper(&child);
 		igt_assert(WEXITSTATUS(child_ret) == EAGAIN ||
@@ -5485,7 +5485,7 @@ test_i915_ref_count(void)
 	igt_debug("ref count after opening i915 perf stream = %u\n", ref_count1);
 	igt_assert(ref_count1 > ref_count0);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 	close(sysfs);
 	drm_fd = -1;
 	sysfs = -1;
@@ -6194,6 +6194,6 @@ igt_main
 			put_engine_groups(perf_oa_groups, num_perf_oa_groups);
 
 		intel_ctx_destroy(drm_fd, ctx);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/i915/perf_pmu.c +3 -3
index 8b31df7b2..0806a8e54 100644
@@ -2424,7 +2424,7 @@ static void test_unload(unsigned int num_engines)
 		if (fd[count] != -1)
 			count++;
 
-		close(i915);
+		drm_close_driver(i915);
 
 		buf = calloc(count, sizeof(uint64_t));
 		igt_assert(buf);
@@ -2768,13 +2768,13 @@ igt_main
 
 		igt_fixture {
 			intel_ctx_destroy(render_fd, render_ctx);
-			close(render_fd);
+			drm_close_driver(render_fd);
 		}
 	}
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("module-unload") {
tests/i915/sysfs_defaults.c +1 -1
index 066532f0a..b686c19fc 100644
@@ -116,6 +116,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_heartbeat_interval.c +1 -1
index a3de43a37..22c5888c6 100644
@@ -543,6 +543,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_preempt_timeout.c +1 -1
index 3d24bf61c..964b78ae8 100644
@@ -362,6 +362,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_timeslice_duration.c +1 -1
index f1b518264..fc2b14e16 100644
@@ -587,6 +587,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
Signature · 1 line
2.40.0
Reviewed-by on v4 21/24
#33 lore raw

Re: [igt-dev] [V4 i-g-t 21/24] tests/i915: Use drm_close_driver() to close the drm fd

Hi Bhanuprakash,

Quoted 7 lines · Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

V2: - New patch for generic tests
V3: - Rebase

Quoted 2,313 lines
---
 tests/i915/api_intel_allocator.c            |  6 ++--
 tests/i915/api_intel_bb.c                   |  2 +-
 tests/i915/drm_fdinfo.c                     |  2 +-
 tests/i915/gem_bad_reloc.c                  |  2 +-
 tests/i915/gem_barrier_race.c               |  2 +-
 tests/i915/gem_basic.c                      |  2 +-
 tests/i915/gem_blits.c                      |  2 +-
 tests/i915/gem_busy.c                       |  2 +-
 tests/i915/gem_caching.c                    |  2 +-
 tests/i915/gem_ccs.c                        |  2 +-
 tests/i915/gem_close_race.c                 | 12 ++++----
 tests/i915/gem_cs_tlb.c                     |  2 +-
 tests/i915/gem_ctx_bad_destroy.c            |  2 +-
 tests/i915/gem_ctx_create.c                 |  4 +--
 tests/i915/gem_ctx_exec.c                   |  2 +-
 tests/i915/gem_ctx_param.c                  |  2 +-
 tests/i915/gem_ctx_persistence.c            |  6 ++--
 tests/i915/gem_ctx_shared.c                 |  2 +-
 tests/i915/gem_ctx_sseu.c                   |  2 +-
 tests/i915/gem_ctx_switch.c                 |  2 +-
 tests/i915/gem_eio.c                        | 16 +++++------
 tests/i915/gem_evict_alignment.c            |  2 +-
 tests/i915/gem_evict_everything.c           |  2 +-
 tests/i915/gem_exec_alignment.c             |  2 +-
 tests/i915/gem_exec_async.c                 |  2 +-
 tests/i915/gem_exec_await.c                 |  2 +-
 tests/i915/gem_exec_basic.c                 |  2 +-
 tests/i915/gem_exec_big.c                   |  2 +-
 tests/i915/gem_exec_capture.c               |  2 +-
 tests/i915/gem_exec_create.c                |  2 +-
 tests/i915/gem_exec_fair.c                  |  2 +-
 tests/i915/gem_exec_fence.c                 |  4 +--
 tests/i915/gem_exec_flush.c                 |  2 +-
 tests/i915/gem_exec_gttfill.c               |  4 +--
 tests/i915/gem_exec_latency.c               |  2 +-
 tests/i915/gem_exec_nop.c                   |  2 +-
 tests/i915/gem_exec_parallel.c              |  4 +--
 tests/i915/gem_exec_params.c                |  2 +-
 tests/i915/gem_exec_reloc.c                 |  2 +-
 tests/i915/gem_exec_schedule.c              |  2 +-
 tests/i915/gem_exec_store.c                 |  2 +-
 tests/i915/gem_exec_suspend.c               |  2 +-
 tests/i915/gem_exec_whisper.c               |  6 ++--
 tests/i915/gem_exercise_blt.c               |  2 +-
 tests/i915/gem_fd_exhaustion.c              |  2 +-
 tests/i915/gem_fence_thrash.c               |  2 +-
 tests/i915/gem_fenced_exec_thrash.c         |  2 +-
 tests/i915/gem_flink_basic.c                |  4 +--
 tests/i915/gem_flink_race.c                 |  6 ++--
 tests/i915/gem_gtt_cpu_tlb.c                |  2 +-
 tests/i915/gem_gtt_hog.c                    |  2 +-
 tests/i915/gem_gtt_speed.c                  |  2 +-
 tests/i915/gem_huc_copy.c                   |  2 +-
 tests/i915/gem_lmem_evict.c                 |  4 +--
 tests/i915/gem_lmem_swapping.c              | 10 +++----
 tests/i915/gem_madvise.c                    | 12 ++++----
 tests/i915/gem_media_fill.c                 |  2 +-
 tests/i915/gem_mmap.c                       |  2 +-
 tests/i915/gem_mmap_gtt.c                   |  6 ++--
 tests/i915/gem_mmap_offset.c                |  8 +++---
 tests/i915/gem_mmap_wc.c                    |  2 +-
 tests/i915/gem_partial_pwrite_pread.c       |  2 +-
 tests/i915/gem_pipe_control_store_loop.c    |  2 +-
 tests/i915/gem_ppgtt.c                      |  8 +++---
 tests/i915/gem_pread.c                      |  2 +-
 tests/i915/gem_pread_after_blit.c           |  2 +-
 tests/i915/gem_pwrite.c                     |  2 +-
 tests/i915/gem_pwrite_snooped.c             |  2 +-
 tests/i915/gem_pxp.c                        |  2 +-
 tests/i915/gem_read_read_speed.c            |  2 +-
 tests/i915/gem_readwrite.c                  |  2 +-
 tests/i915/gem_reg_read.c                   |  2 +-
 tests/i915/gem_render_copy.c                |  2 +-
 tests/i915/gem_render_copy_redux.c          |  2 +-
 tests/i915/gem_reset_stats.c                | 32 ++++++++++-----------
 tests/i915/gem_ringfill.c                   |  2 +-
 tests/i915/gem_set_tiling_vs_blt.c          |  2 +-
 tests/i915/gem_set_tiling_vs_gtt.c          |  2 +-
 tests/i915/gem_set_tiling_vs_pwrite.c       |  2 +-
 tests/i915/gem_shrink.c                     | 14 ++++-----
 tests/i915/gem_softpin.c                    |  4 +--
 tests/i915/gem_spin_batch.c                 |  2 +-
 tests/i915/gem_streaming_writes.c           |  2 +-
 tests/i915/gem_stress.c                     |  2 +-
 tests/i915/gem_sync.c                       |  2 +-
 tests/i915/gem_tiled_blits.c                |  2 +-
 tests/i915/gem_tiled_fence_blits.c          |  2 +-
 tests/i915/gem_tiled_partial_pwrite_pread.c |  2 +-
 tests/i915/gem_tiled_pread_basic.c          |  2 +-
 tests/i915/gem_tiled_pread_pwrite.c         |  2 +-
 tests/i915/gem_tiled_swapping.c             |  2 +-
 tests/i915/gem_tiled_wb.c                   |  2 +-
 tests/i915/gem_tiled_wc.c                   |  2 +-
 tests/i915/gem_tiling_max_stride.c          |  2 +-
 tests/i915/gem_unfence_active_buffers.c     |  2 +-
 tests/i915/gem_unref_active_buffers.c       |  2 +-
 tests/i915/gem_userptr_blits.c              |  6 ++--
 tests/i915/gem_vm_create.c                  |  4 +--
 tests/i915/gem_wait.c                       |  2 +-
 tests/i915/gem_watchdog.c                   |  2 +-
 tests/i915/gem_workarounds.c                |  2 +-
 tests/i915/gen7_exec_parse.c                |  4 +--
 tests/i915/gen9_exec_parse.c                |  2 +-
 tests/i915/i915_fb_tiling.c                 |  2 +-
 tests/i915/i915_getparams_basic.c           |  2 +-
 tests/i915/i915_hangman.c                   |  4 +--
 tests/i915/i915_hwmon.c                     |  2 +-
 tests/i915/i915_module_load.c               |  8 +++---
 tests/i915/i915_pciid.c                     |  2 +-
 tests/i915/i915_pm_backlight.c              |  2 +-
 tests/i915/i915_pm_dc.c                     |  2 +-
 tests/i915/i915_pm_freq_api.c               |  2 +-
 tests/i915/i915_pm_freq_mult.c              |  2 +-
 tests/i915/i915_pm_lpsp.c                   |  2 +-
 tests/i915/i915_pm_rc6_residency.c          |  2 +-
 tests/i915/i915_pm_rps.c                    |  2 +-
 tests/i915/i915_pm_sseu.c                   |  2 +-
 tests/i915/i915_power.c                     |  2 +-
 tests/i915/i915_query.c                     |  2 +-
 tests/i915/i915_suspend.c                   |  6 ++--
 tests/i915/perf.c                           |  6 ++--
 tests/i915/perf_pmu.c                       |  6 ++--
 tests/i915/sysfs_defaults.c                 |  2 +-
 tests/i915/sysfs_heartbeat_interval.c       |  2 +-
 tests/i915/sysfs_preempt_timeout.c          |  2 +-
 tests/i915/sysfs_timeslice_duration.c       |  2 +-
 126 files changed, 205 insertions(+), 205 deletions(-)
tests/i915/api_intel_allocator.c +3 -3
index cc6f8daa4..b7e3efb87 100644
@@ -579,7 +579,7 @@ static void reopen(int fd)
 
 	__reopen_allocs(fd, fd2, true);
 
-	close(fd2);
+	drm_close_driver(fd2);
 }
 
 #define REOPEN_TIMEOUT 3
@@ -605,7 +605,7 @@ static void reopen_fork(int fd)
 	/* Check references at the end */
 	__reopen_allocs(fd, fd2, true);
 
-	close(fd2);
+	drm_close_driver(fd2);
 
 	intel_allocator_multiprocess_stop();
 }
@@ -924,5 +924,5 @@ igt_main
 		gem_pool(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/api_intel_bb.c +1 -1
index 85ca86eed..47049ba23 100644
@@ -1908,6 +1908,6 @@ igt_main_args("dpibc:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/drm_fdinfo.c +1 -1
index d061e901f..c0e0ba190 100644
@@ -910,6 +910,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_bad_reloc.c +1 -1
index d5336b62d..b058639ea 100644
@@ -231,5 +231,5 @@ igt_main
 		negative_reloc_blt(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_barrier_race.c +1 -1
index 0ac1da3a4..591ddc222 100644
@@ -120,7 +120,7 @@ static void intel_context_first_pin_last_unpin_loop(int fd, uint64_t engine, int
 
 	} while (!READ_ONCE(*done));
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_remote_request(int fd, uint64_t engine, unsigned int timeout)
tests/i915/gem_basic.c +1 -1
index 6843bec16..3485f92c8 100644
@@ -145,7 +145,7 @@ igt_main
 			gpu_fd = __drm_open_driver_another(child, DRIVER_INTEL);
 			igt_assert_f(gpu_fd > 0, "cannot open gpu-%d, errno=%d\n", child, errno);
 			test_create_close(gpu_fd);
-			close(gpu_fd);
+			drm_close_driver(gpu_fd);
 		}
 
 		igt_waitchildren();
tests/i915/gem_blits.c +1 -1
index 681fe0466..9b268e9dc 100644
@@ -904,6 +904,6 @@ igt_main
 
 	igt_fixture {
 		put_ahnd(device.ahnd);
-		close(device.fd);
+		drm_close_driver(device.fd);
 	}
 }
tests/i915/gem_busy.c +1 -1
index b796ebb2b..c60654b1e 100644
@@ -617,6 +617,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_caching.c +1 -1
index 7af427d7e..6a4da122b 100644
@@ -356,6 +356,6 @@ igt_main
 		intel_buf_destroy(scratch_buf);
 		intel_buf_destroy(staging_buf);
 		buf_ops_destroy(data.bops);
-		close(data.fd);
+		drm_close_driver(data.fd);
 	}
 }
tests/i915/gem_ccs.c +1 -1
index d38ab49a4..4581b6489 100644
@@ -764,6 +764,6 @@ igt_main_args("bf:pst:W:H:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_disallow_hang(i915, hang);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_close_race.c +6 -6
index 22cdc5874..cef0ff025 100644
@@ -329,7 +329,7 @@ static void multigpu_threads(int timeout, unsigned int flags, int gpu_count)
 
 		igt_waitchildren();
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_waitchildren();
@@ -348,7 +348,7 @@ static void threads(int timeout, unsigned int flags)
 	igt_waitchildren();
 
 	gem_quiescent_gpu(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -372,7 +372,7 @@ igt_main
 		gpu_count = igt_device_filter_count();
 
 		igt_fork_hang_detector(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Basic workload submission.");
@@ -384,7 +384,7 @@ igt_main
 		igt_waitchildren();
 
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Basic workload submission on multi-GPU machine.");
@@ -397,7 +397,7 @@ igt_main
 			igt_assert(fd > 0);
 			process(fd, child);
 			gem_quiescent_gpu(fd);
-			close(fd);
+			drm_close_driver(fd);
 		}
 
 		igt_waitchildren();
@@ -424,7 +424,7 @@ igt_main
 		igt_waitchildren();
 
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Share buffer handle across different drm fd's and trying to race"
tests/i915/gem_cs_tlb.c +1 -1
index 3f285f42c..2c7781d06 100644
@@ -174,5 +174,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_bad_destroy.c +1 -1
index 8c47e7c1c..65f6b5583 100644
@@ -98,5 +98,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_create.c +2 -2
index 95e219482..6d0877954 100644
@@ -206,7 +206,7 @@ static void files(int core, const intel_ctx_cfg_t *cfg,
 			gem_execbuf(fd, &execbuf);
 
 			intel_ctx_destroy(fd, ctx);
-			close(fd);
+			drm_close_driver(fd);
 			count++;
 
 			clock_gettime(CLOCK_MONOTONIC, &end);
@@ -756,6 +756,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_exec.c +1 -1
index f3939df86..4376397a2 100644
@@ -403,7 +403,7 @@ static void nohangcheck_hostile(int i915)
 	put_ahnd(ahnd);
 
 	close(dir);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 static void close_race(int i915)
tests/i915/gem_ctx_param.c +1 -1
index 7c59fe3ed..9b44c86a0 100644
@@ -636,5 +636,5 @@ igt_main
 		test_get_invalid_param(fd, I915_CONTEXT_PARAM_ENGINES);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_persistence.c +3 -3
index d2558354e..c6e2c5d77 100644
@@ -791,7 +791,7 @@ static void test_nonpersistent_file(int i915)
 	gem_context_set_persistence(i915, 0, false);
 	spin = igt_spin_new(i915, .ahnd = ahnd, .flags = IGT_SPIN_FENCE_OUT);
 
-	close(i915);
+	drm_close_driver(i915);
 	flush_delayed_fput(debugfs);
 
 	igt_assert_eq(wait_for_status(spin->out_fence, reset_timeout_ms), -EIO);
@@ -1274,7 +1274,7 @@ static void __smoker(int i915, const intel_ctx_cfg_t *cfg,
 
 	intel_ctx_destroy(fd, ctx);
 
-	close(fd);
+	drm_close_driver(fd);
 	flush_delayed_fput(i915);
 
 	igt_spin_end(spin);
@@ -1570,6 +1570,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_ctx_shared.c +1 -1
index ede6db13b..d24ae5483 100644
@@ -315,7 +315,7 @@ static void exhaust_shared_gtt(int i915, unsigned int flags)
 		igt_info("Created %lu shared contexts, before %d (%s)\n",
 			 count, err, strerror(-err));
 	}
-	close(i915);
+	drm_close_driver(i915);
 	igt_waitchildren();
 }
 
tests/i915/gem_ctx_sseu.c +1 -1
index 78748c24d..3a01944e4 100644
@@ -559,6 +559,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_switch.c +1 -1
index b0066ab27..f94a41bec 100644
@@ -805,6 +805,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(fd, heavy);
 		gem_close(fd, light);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_eio.c +8 -8
index 38fd19e89..d889d67dc 100644
@@ -656,7 +656,7 @@ static void test_banned(int fd)
 {
 	fd = reopen_device(fd);
 	__test_banned(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 #define TEST_WEDGE (1)
@@ -690,7 +690,7 @@ static void test_wait(int fd, unsigned int flags, unsigned int wait)
 	igt_require(i915_reset_control(fd, true));
 
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_suspend(int fd, int state)
@@ -708,7 +708,7 @@ static void test_suspend(int fd, int state)
 
 	igt_require(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_inflight(int fd, unsigned int wait)
@@ -772,7 +772,7 @@ static void test_inflight(int fd, unsigned int wait)
 		trigger_reset(fd);
 
 		gem_close(fd, obj[1].handle);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
 
@@ -833,7 +833,7 @@ static void test_inflight_suspend(int fd)
 
 	igt_assert(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static const intel_ctx_t *context_create_safe(int i915)
@@ -923,7 +923,7 @@ static void test_inflight_contexts(int fd, unsigned int wait)
 		for (unsigned int n = 0; n < ARRAY_SIZE(ctx); n++)
 			intel_ctx_destroy(fd, ctx[n]);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
 
@@ -979,7 +979,7 @@ static void test_inflight_external(int fd)
 	put_ahnd(ahnd);
 	igt_assert(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_inflight_internal(int fd, unsigned int wait)
@@ -1029,7 +1029,7 @@ static void test_inflight_internal(int fd, unsigned int wait)
 
 	igt_assert(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void reset_stress(int fd, uint64_t ahnd, const intel_ctx_t *ctx0,
tests/i915/gem_evict_alignment.c +1 -1
index f04f24972..4a9507a06 100644
@@ -282,6 +282,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_evict_everything.c +1 -1
index 87f854bf8..f0f356cc3 100644
@@ -351,6 +351,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_alignment.c +1 -1
index 9d965270f..10732fec5 100644
@@ -487,7 +487,7 @@ static void forked(int i915, int timeout)
 	igt_waitchildren_timeout(3 * timeout, NULL);
 
 	free(obj);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 static void single(int fd)
tests/i915/gem_exec_async.c +1 -1
index f3c2f671f..8c131d8e1 100644
@@ -227,6 +227,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_await.c +1 -1
index c78403466..53b7bac2f 100644
@@ -300,6 +300,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_basic.c +1 -1
index 623f1ee52..83f71e289 100644
@@ -113,6 +113,6 @@ igt_main
 		igt_collection_destroy(set);
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_big.c +1 -1
index 3acdb3741..9de9941d5 100644
@@ -340,5 +340,5 @@ igt_main
 		exhaustive(i915);
 
 	igt_fixture
-		close(i915);
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_capture.c +1 -1
index 453ae1af9..ab8305e4d 100644
@@ -1055,6 +1055,6 @@ igt_main
 		close(dir);
 		igt_disallow_hang(fd, hang);
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_create.c +1 -1
index 00c190115..4eb77ecbb 100644
@@ -270,6 +270,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_fair.c +1 -1
index eedcfdf80..5ad13f97a 100644
@@ -1440,6 +1440,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_fence.c +2 -2
index d6253a379..4bf29a3e4 100644
@@ -2118,7 +2118,7 @@ static void test_invalid_timeline_fence_array(int fd)
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EFAULT);
 
 	munmap(ptr, 4096);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static const char *test_syncobj_timeline_unused_fence_desc =
@@ -3701,6 +3701,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_flush.c +1 -1
index e213bda5e..3902ee957 100644
@@ -2207,6 +2207,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_gttfill.c +2 -2
index 4c32a04c0..28c251915 100644
@@ -314,7 +314,7 @@ igt_main
 			// release resources
 			igt_stop_hang_detector();
 			intel_ctx_destroy(g_fd, ctx);
-			close(g_fd);
+			drm_close_driver(g_fd);
 		}
 
 		igt_waitchildren();
@@ -322,6 +322,6 @@ igt_main
 
 	igt_fixture {
 		intel_allocator_multiprocess_stop();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_latency.c +1 -1
index 9a9e43bab..c0e607f97 100644
@@ -1001,6 +1001,6 @@ igt_main
 	igt_fixture {
 		intel_register_access_fini(&mmio_data);
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_nop.c +1 -1
index 067c92b47..6dea8b167 100644
@@ -1150,6 +1150,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(device, handle);
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_parallel.c +2 -2
index bba861185..cae1553f6 100644
@@ -230,7 +230,7 @@ static void *thread(void *data)
 		intel_ctx_destroy(fd, tmp_ctx);
 	gem_close(fd, obj[1].handle);
 	if (t->flags & FDS)
-		close(fd);
+		drm_close_driver(fd);
 
 	t->used = used;
 	return NULL;
@@ -413,6 +413,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_params.c +1 -1
index 16ae7a5a6..caaa5fee0 100644
@@ -825,6 +825,6 @@ igt_main
 	igt_fixture {
 		gem_close(fd, handle);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_reloc.c +1 -1
index c591f374d..8259ff1d9 100644
@@ -1771,5 +1771,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_exec_schedule.c +1 -1
index c9be726ab..c94988d36 100644
@@ -3755,6 +3755,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_store.c +1 -1
index d61072dfa..0ab931062 100644
@@ -480,6 +480,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_suspend.c +1 -1
index 73fbf8cf6..39d75ee03 100644
@@ -510,6 +510,6 @@ igt_main
 		igt_collection_destroy(set);
 		igt_disallow_hang(fd, hang);
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_whisper.c +3 -3
index 1379f10dc..46712c3e8 100644
@@ -457,7 +457,7 @@ static void fini_hang(struct hang *h)
 	put_offset(h->ahnd, h->obj.handle);
 	put_ahnd(h->ahnd);
 	intel_ctx_destroy(h->fd, h->ctx);
-	close(h->fd);
+	drm_close_driver(h->fd);
 }
 
 static void ctx_set_random_priority(int fd, uint32_t ctx)
@@ -829,7 +829,7 @@ static void whisper(int fd, const intel_ctx_t *ctx,
 			gem_close(fd, batches[n].handle);
 		if (flags & FDS) {
 			for (n = 0; n < 64; n++)
-				close(fds[n]);
+				drm_close_driver(fds[n]);
 		}
 	}
 
@@ -939,6 +939,6 @@ igt_main
 	igt_fixture {
 		intel_allocator_multiprocess_stop();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exercise_blt.c +1 -1
index 89f89d212..8c70c941c 100644
@@ -398,6 +398,6 @@ igt_main_args("b:pst:W:H:", NULL, help_str, opt_handler, NULL)
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_fd_exhaustion.c +1 -1
index 75485c1cb..e79d03478 100644
@@ -75,5 +75,5 @@ igt_simple_main
 
 	igt_waitchildren();
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_fence_thrash.c +1 -1
index f8ac29dd7..4cb3d842b 100644
@@ -244,7 +244,7 @@ static int run_test(int threads_per_fence, void *f, int tiling,
 		igt_assert(func(&t) == (void *)0);
 	}
 
-	close(t.fd);
+	drm_close_driver(t.fd);
 
 	return 0;
 }
tests/i915/gem_fenced_exec_thrash.c +1 -1
index f22f16f68..098f22ef4 100644
@@ -217,5 +217,5 @@ igt_main
 		run_test(fd, num_fences + 1, intel_gen(devid) >= 4 ? 0 : ENOBUFS, 0);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_flink_basic.c +2 -2
index 8a316cdae..e70cab4d1 100644
@@ -196,7 +196,7 @@ test_flink_lifetime(int fd)
 	igt_assert_eq(ret, 0);
 	igt_assert(open_struct.handle != 0);
 
-	close(fd2);
+	drm_close_driver(fd2);
 	fd2 = drm_open_driver(DRIVER_INTEL);
 
 	/* Flink name remains valid due to the second reference */
@@ -205,7 +205,7 @@ test_flink_lifetime(int fd)
 	igt_assert_eq(ret, 0);
 	igt_assert(open_struct.handle != 0);
 
-	close(fd2);
+	drm_close_driver(fd2);
 }
 
 igt_main
tests/i915/gem_flink_race.c +3 -3
index a9177ce1b..41c15f298 100644
@@ -141,7 +141,7 @@ static void test_flink_name(int timeout)
 		 igt_stats_get_max(&stats));
 	igt_stats_fini(&stats);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void *thread_fn_flink_close(void *p)
@@ -202,13 +202,13 @@ static void test_flink_close(void)
 		igt_assert(status == 0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
tests/i915/gem_gtt_cpu_tlb.c +1 -1
index 4f4af6a7b..155aa6516 100644
@@ -113,5 +113,5 @@ igt_simple_main
 	for (i = 0; i < OBJ_SIZE/4; i++)
 		igt_assert(ptr[i] == i);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_gtt_hog.c +1 -1
index 4c8158c6d..1227c7633 100644
@@ -170,7 +170,7 @@ igt_simple_main
 	int fd = drm_open_driver(DRIVER_INTEL);
 	igt_require_gem(fd);
 	gem_require_mappable_ggtt(fd);
-	close(fd);
+	drm_close_driver(fd);
 
 	data.fd = drm_open_driver(DRIVER_INTEL);
 	data.devid = intel_get_drm_devid(data.fd);
tests/i915/gem_gtt_speed.c +1 -1
index a0e37b19e..c85c359a0 100644
@@ -521,5 +521,5 @@ igt_simple_main_args("s:", NULL, help_str, opt_handler, NULL)
 	}
 
 	gem_close(fd, handle);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_huc_copy.c +1 -1
index 5a217c984..246fa0a8b 100644
@@ -150,6 +150,6 @@ igt_main
 
 	igt_fixture {
 		put_ahnd(ahnd);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/i915/gem_lmem_evict.c +2 -2
index 54277e11d..a3ca2c861 100644
@@ -103,7 +103,7 @@ igt_main
 			igt_require_fd(i915);
 			igt_require_gem(i915);
 			igt_require(gem_has_lmem(i915));
-			close(i915);
+			drm_close_driver(i915);
 		}
 
 		igt_i915_driver_unload();
@@ -142,7 +142,7 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 		igt_i915_driver_unload();
 	}
 }
tests/i915/gem_lmem_swapping.c +5 -5
index 8211edbe3..a04d0a5f8 100644
@@ -718,7 +718,7 @@ static void test_evict(int i915,
 
 		igt_waitchildren();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 		intel_allocator_multiprocess_stop();
 	} else {
 		__do_evict(i915, ctx, &region->region, &params, params.seed);
@@ -790,7 +790,7 @@ static void test_smem_oom(int i915,
 			   params.seed + child + 1);
 
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	/* smem memory hog process, respawn till the lmem process completes */
@@ -811,7 +811,7 @@ static void test_smem_oom(int i915,
 						break;
 					gem_leak(fd, alloc);
 				}
-				close(fd);
+				drm_close_driver(fd);
 			}
 			/*
 			 * Wait for grand-child processes to finish or be
@@ -903,7 +903,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 			igt_require_fd(i915);
 			igt_require_gem(i915);
 			igt_require(gem_has_lmem(i915));
-			close(i915);
+			drm_close_driver(i915);
 		}
 
 		igt_i915_driver_unload();
@@ -948,7 +948,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
 		free(regions);
-		close(i915);
+		drm_close_driver(i915);
 		igt_i915_driver_unload();
 	}
 
tests/i915/gem_madvise.c +6 -6
index 4efa359ba..765809e7f 100644
@@ -110,7 +110,7 @@ dontneed_before_mmap(void)
 					PROT_READ | PROT_WRITE,
 					t->type);
 
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -132,7 +132,7 @@ dontneed_before_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -156,7 +156,7 @@ dontneed_after_mmap(void)
 					t->type);
 
 		gem_madvise(fd, handle, I915_MADV_DONTNEED);
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -178,7 +178,7 @@ dontneed_after_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -194,7 +194,7 @@ dontneed_before_pwrite(void)
 
 	igt_assert_eq(__gem_write(fd, handle, 0, &bbe, sizeof(bbe)), -EFAULT);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -218,7 +218,7 @@ dontneed_before_exec(void)
 	execbuf.batch_len = sizeof(buf);
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EFAULT);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
tests/i915/gem_media_fill.c +1 -1
index 07e7b3ccb..a678d2f99 100644
@@ -181,6 +181,6 @@ igt_main
 	igt_fixture {
 		igt_collection_destroy(set);
 		igt_stop_hang_detector();
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/gem_mmap.c +1 -1
index 421c6f859..d4ca1eda7 100644
@@ -372,5 +372,5 @@ igt_main
 		test_huge_bo(2);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_gtt.c +3 -3
index e5d3aa079..9c06785d2 100644
@@ -869,13 +869,13 @@ test_isolation(int i915)
 	igt_info("B: {fd:%d, handle:%d, offset:%"PRIx64"}\n",
 		 B, b, offset_b);
 
-	close(B);
+	drm_close_driver(B);
 
 	ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 	igt_assert(ptr != MAP_FAILED);
 	munmap(ptr, 4096);
 
-	close(A);
+	drm_close_driver(A);
 
 	ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 	igt_assert(ptr == MAP_FAILED);
@@ -1979,5 +1979,5 @@ igt_main
 
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_offset.c +4 -4
index 2537ecdc5..bc801cd04 100644
@@ -434,13 +434,13 @@ static void isolation(int i915)
 				igt_assert_eq(errno, EACCES);
 			}
 
-			close(B);
+			drm_close_driver(B);
 
 			ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 			igt_assert(ptr != MAP_FAILED);
 			munmap(ptr, 4096);
 
-			close(A);
+			drm_close_driver(A);
 
 			ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 			igt_assert(ptr == MAP_FAILED);
@@ -735,7 +735,7 @@ static void open_flood(int i915, int timeout)
 			mmap_offset_ioctl(i915, &arg);
 		}
 
-		close(tmp);
+		drm_close_driver(tmp);
 		count++;
 	}
 
@@ -1013,6 +1013,6 @@ igt_main
 		blt_coherency(i915);
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_mmap_wc.c +1 -1
index ce1c19083..c56e8c353 100644
@@ -687,5 +687,5 @@ igt_main
 		test_set_cache_level(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_partial_pwrite_pread.c +1 -1
index 1b533ef30..659a96b6e 100644
@@ -388,6 +388,6 @@ igt_main
 		intel_buf_destroy(scratch_buf);
 		intel_buf_destroy(staging_buf);
 		buf_ops_destroy(data.bops);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/gem_pipe_control_store_loop.c +1 -1
index 986dbf673..1913b874a 100644
@@ -199,6 +199,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ppgtt.c +4 -4
index 9dc6ccfe4..b6081b1e9 100644
@@ -278,8 +278,8 @@ static void flink_and_close(void)
 	igt_assert_eq(offset, offset_new);
 
 	gem_close(fd, bo);
-	close(fd);
-	close(fd2);
+	drm_close_driver(fd);
+	drm_close_driver(fd2);
 }
 
 #define PAGE_SIZE 4096
@@ -412,7 +412,7 @@ static bool has_contexts(void)
 
 	fd = drm_open_driver(DRIVER_INTEL);
 	result = gem_has_contexts(fd);
-	close(fd);
+	drm_close_driver(fd);
 
 	return result;
 }
@@ -425,7 +425,7 @@ igt_main
 		int fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
 		gem_require_blitter(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("blt-vs-render-ctx0") {
tests/i915/gem_pread.c +1 -1
index 1dbded440..6f50785da 100644
@@ -367,6 +367,6 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 		free(src);
 		gem_close(fd, dst);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_pread_after_blit.c +1 -1
index fc6ee4408..b3e20697d 100644
@@ -281,5 +281,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_pwrite.c +1 -1
index 8471f963d..e2b48b843 100644
@@ -639,5 +639,5 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_pwrite_snooped.c +1 -1
index 7135dca57..5d9e8da20 100644
@@ -148,5 +148,5 @@ igt_simple_main
 	test(256, 256);
 
 	buf_ops_destroy(bops);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_pxp.c +1 -1
index 167877d31..4aea765fe 100644
@@ -1372,6 +1372,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_read_read_speed.c +1 -1
index 7eeba7c6a..95ef47da6 100644
@@ -275,6 +275,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_readwrite.c +1 -1
index fdc68e315..864a2d8d8 100644
@@ -158,5 +158,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_reg_read.c +1 -1
index 5f63c02f7..de6788abe 100644
@@ -181,6 +181,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_render_copy.c +1 -1
index 657509647..406c30915 100644
@@ -999,6 +999,6 @@ igt_main_args("dac", NULL, help_str, opt_handler, NULL)
 		igt_stop_hang_detector();
 		buf_ops_destroy(data.bops);
 		igt_collection_destroy(set);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/gem_render_copy_redux.c +1 -1
index 0cb2936d3..06777dd7f 100644
@@ -98,7 +98,7 @@ static void data_init(data_t *data)
 static void data_fini(data_t *data)
 {
 	buf_ops_destroy(data->bops);
-	close(data->fd);
+	drm_close_driver(data->fd);
 }
 
 static void scratch_buf_init(data_t *data, struct intel_buf *buf,
tests/i915/gem_reset_stats.c +16 -16
index 7ec9264b5..6939722c7 100644
@@ -475,7 +475,7 @@ static void test_rs(const struct intel_execution_ring *e,
 	igt_assert(igt_seconds_elapsed(&ts_injected) <= 30);
 
 	for (i = 0; i < num_fds; i++)
-		close(fd[i]);
+		drm_close_driver(fd[i]);
 }
 
 #define MAX_CTX 100
@@ -551,7 +551,7 @@ static void test_rs_ctx(const struct intel_execution_ring *e,
 
 	for (i = 0; i < num_fds; i++) {
 		assert_reset_status(i, fd[i], 0, RS_NO_ERROR);
-		close(fd[i]);
+		drm_close_driver(fd[i]);
 	}
 }
 
@@ -605,8 +605,8 @@ static void test_ban(const struct intel_execution_ring *e)
 	igt_assert_eq(gem_reset_stats(fd_good, 0, &rs_good), 0);
 	igt_assert_eq(rs_good.batch_active, 0);
 
-	close(fd_bad);
-	close(fd_good);
+	drm_close_driver(fd_bad);
+	drm_close_driver(fd_good);
 }
 
 static void test_ban_ctx(const struct intel_execution_ring *e)
@@ -664,7 +664,7 @@ static void test_ban_ctx(const struct intel_execution_ring *e)
 	igt_assert_eq(gem_reset_stats(fd, ctx_good, &rs_good), 0);
 	igt_assert_eq(rs_good.batch_active, 0);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_unrelated_ctx(const struct intel_execution_ring *e)
@@ -690,8 +690,8 @@ static void test_unrelated_ctx(const struct intel_execution_ring *e)
 	assert_reset_status(0, fd1, ctx_guilty, RS_BATCH_ACTIVE);
 	assert_reset_status(1, fd2, ctx_unrelated, RS_NO_ERROR);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static int get_reset_count(int fd, int ctx)
@@ -717,7 +717,7 @@ static void test_close_pending_ctx(const struct intel_execution_ring *e)
 	gem_context_destroy(fd, ctx);
 	igt_assert_eq(__gem_context_destroy(fd, ctx), -ENOENT);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_close_pending(const struct intel_execution_ring *e)
@@ -727,7 +727,7 @@ static void test_close_pending(const struct intel_execution_ring *e)
 	assert_reset_status(fd, fd, 0, RS_NO_ERROR);
 
 	inject_hang(fd, 0, e, 0);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void noop_on_each_ring(int fd, const bool reverse)
@@ -789,7 +789,7 @@ static void test_close_pending_fork(const struct intel_execution_ring *e,
 		 * when gpu is reset and ring lists are cleared.
 		 */
 		noop_on_each_ring(fd2, reverse);
-		close(fd2);
+		drm_close_driver(fd2);
 		pause();
 		exit(0);
 	} else {
@@ -802,7 +802,7 @@ static void test_close_pending_fork(const struct intel_execution_ring *e,
 	}
 
 	igt_post_hang_ring(fd, hang);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_reset_count(const struct intel_execution_ring *e,
@@ -842,7 +842,7 @@ static void test_reset_count(const struct intel_execution_ring *e,
 	if (create_ctx)
 		gem_context_destroy(fd, ctx);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static int _test_params(int fd, int ctx, uint32_t flags, uint32_t pad)
@@ -913,7 +913,7 @@ static void test_params_ctx(void)
 
 	fd = drm_reopen_driver(device);
 	_test_param(fd, gem_context_create(fd));
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_params(void)
@@ -922,7 +922,7 @@ static void test_params(void)
 
 	fd = drm_reopen_driver(device);
 	_test_param(fd, 0);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static const struct intel_execution_ring *
@@ -968,7 +968,7 @@ static void defer_hangcheck(const struct intel_execution_ring *engine)
 
 	igt_assert_lt(count_start, count_end);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static bool gem_has_reset_stats(int fd)
@@ -1177,6 +1177,6 @@ igt_main
 	}
 	igt_fixture {
 		igt_assert(igt_params_set(device, "reset", "%d", INT_MAX /* any reset method */));
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_ringfill.c +1 -1
index 52471948e..c718d6fe7 100644
@@ -522,6 +522,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_set_tiling_vs_blt.c +1 -1
index cee4591b8..e9d5e3c63 100644
@@ -276,6 +276,6 @@ igt_main
 
 	igt_fixture{
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_set_tiling_vs_gtt.c +1 -1
index 30b69bb8b..4a7ecdc88 100644
@@ -138,5 +138,5 @@ igt_simple_main
 
 	munmap(ptr, OBJECT_SIZE);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_set_tiling_vs_pwrite.c +1 -1
index 328682d94..ede0c58b6 100644
@@ -107,5 +107,5 @@ igt_simple_main
 
 	munmap(ptr, OBJECT_SIZE);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_shrink.c +7 -7
index 79301754b..1f16f8a78 100644
@@ -381,7 +381,7 @@ static bool has_userptr(void)
 	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr))
 		err = errno;
 
-	close(fd);
+	drm_close_driver(fd);
 
 	return err == EFAULT;
 }
@@ -430,7 +430,7 @@ static void run_test(int nchildren, uint64_t alloc,
 				int fd = drm_open_driver(DRIVER_INTEL);
 				for (int pass = 0; pass < nchildren; pass++)
 					leak(fd, alloc);
-				close(fd);
+				drm_close_driver(fd);
 			}
 		}
 	}
@@ -442,7 +442,7 @@ static void run_test(int nchildren, uint64_t alloc,
 				int fd = drm_open_driver(DRIVER_INTEL);
 				for (int pass = 0; pass < nchildren; pass++)
 					userptr(fd, alloc, 0);
-				close(fd);
+				drm_close_driver(fd);
 			}
 		}
 		nchildren = (nchildren + 1)/2;
@@ -455,7 +455,7 @@ static void run_test(int nchildren, uint64_t alloc,
 				int fd = drm_open_driver(DRIVER_INTEL);
 				for (int pass = 0; pass < nchildren; pass++)
 					userptr(fd, alloc, UDIRTY);
-				close(fd);
+				drm_close_driver(fd);
 			}
 		}
 		nchildren = (nchildren + 1)/2;
@@ -467,7 +467,7 @@ static void run_test(int nchildren, uint64_t alloc,
 			int fd = drm_open_driver(DRIVER_INTEL);
 			for (int pass = 0; pass < nchildren; pass++)
 				func(fd, alloc);
-			close(fd);
+			drm_close_driver(fd);
 		}
 	}
 	igt_waitchildren();
@@ -510,7 +510,7 @@ static void reclaim(unsigned engine, int timeout)
 
 	munmap((void *)shared, 4096);
 	close(debugfs);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -567,7 +567,7 @@ igt_main
 			 num_processes, alloc_size);
 
 		alloc_size <<= 20;
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("reclaim")
tests/i915/gem_softpin.c +2 -2
index 62478f4a3..e6cbf624e 100644
@@ -1433,7 +1433,7 @@ static void *thread(void *data)
 			  fd, ctx->id, t->engine, succeeded);
 	intel_ctx_destroy(fd, ctx);
 	gem_close(fd, obj[1].handle);
-	close(fd);
+	drm_close_driver(fd);
 
 	return (void *) from_user_pointer(ret);
 }
@@ -1747,6 +1747,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_spin_batch.c +1 -1
index cd828beb2..18873be16 100644
@@ -354,6 +354,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_streaming_writes.c +1 -1
index 2c59c08f6..fc2d3d89f 100644
@@ -448,5 +448,5 @@ igt_main
 		test_batch(fd, 2, 1);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_stress.c +1 -1
index 625b0e915..bf2e06d71 100644
@@ -933,7 +933,7 @@ igt_simple_main_args("ds:g:c:t:rbuxmo:fp:",
 	intel_bb_destroy(ibb);
 	buf_ops_destroy(bops);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 
 	igt_stop_signal_helper();
 }
tests/i915/gem_sync.c +1 -1
index 1ee5b3f3d..f98d4364c 100644
@@ -1606,6 +1606,6 @@ igt_main
 		intel_allocator_multiprocess_stop();
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_blits.c +1 -1
index 8c3951c6f..22ac3280d 100644
@@ -232,6 +232,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_fence_blits.c +1 -1
index 539601e5a..5444dcfb8 100644
@@ -335,5 +335,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_partial_pwrite_pread.c +1 -1
index a7e845e32..d4f66d51e 100644
@@ -330,6 +330,6 @@ igt_main
 		intel_buf_destroy(tiled_staging_buf);
 		buf_ops_destroy(bops);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_pread_basic.c +1 -1
index ddf9f0f56..a2253b51e 100644
@@ -230,5 +230,5 @@ igt_simple_main
 		}
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_pread_pwrite.c +1 -1
index 3331e61ad..2f0f6f547 100644
@@ -162,5 +162,5 @@ igt_simple_main
 		gem_madvise(fd, handle, I915_MADV_DONTNEED);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_swapping.c +1 -1
index fb633ecab..90ce70bdb 100644
@@ -256,5 +256,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_wb.c +1 -1
index 7f1afbc90..6a8b79ecc 100644
@@ -249,5 +249,5 @@ igt_simple_main
 		munmap(linear, last_page - first_page);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_wc.c +1 -1
index dc4e4d2d7..1994453b3 100644
@@ -250,5 +250,5 @@ igt_simple_main
 		munmap(linear, last_page - first_page);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiling_max_stride.c +1 -1
index 6001f72be..5943ed93f 100644
@@ -146,5 +146,5 @@ igt_simple_main
 
 	munmap(ptr, size);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_unfence_active_buffers.c +1 -1
index 1f25a81b1..d3bc1cee6 100644
@@ -107,5 +107,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
-	close(i915);
+	drm_close_driver(i915);
 }
tests/i915/gem_unref_active_buffers.c +1 -1
index badded1f7..47023a3a0 100644
@@ -133,5 +133,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
-	close(i915);
+	drm_close_driver(i915);
 }
tests/i915/gem_userptr_blits.c +3 -3
index e9235a689..ecbfdf94f 100644
@@ -1086,7 +1086,7 @@ static void test_nohangcheck_hostile(int i915)
 	close(fence);
 
 	close(dir);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 static size_t hugepagesize(void)
@@ -1644,9 +1644,9 @@ static int test_dmabuf(void)
 
 	/* destroy userptr object and expect SIGBUS */
 	free_userptr_bo(fd1, handle);
-	close(fd1);
+	drm_close_driver(fd1);
 
-	close(fd2);
+	drm_close_driver(fd2);
 	reset_handle_ptr();
 
 	return 0;
tests/i915/gem_vm_create.c +2 -2
index f24aefdae..8834c987f 100644
@@ -370,7 +370,7 @@ static void isolation(int i915)
 	gem_read(i915, obj[0].handle, 0, &result, sizeof(result));
 	igt_assert_eq(result, 1);
 
-	close(other);
+	drm_close_driver(other);
 
 	gem_close(i915, obj[1].handle);
 	gem_close(i915, obj[0].handle);
@@ -411,6 +411,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_wait.c +1 -1
index c1cd37e63..674deb57d 100644
@@ -336,6 +336,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_watchdog.c +1 -1
index 640a8cad8..1e4c35021 100644
@@ -597,6 +597,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_workarounds.c +1 -1
index da8cfa011..c5ca26c08 100644
@@ -305,7 +305,7 @@ static void check_workarounds(int fd, enum operation op, unsigned int flags)
 	if (flags & CONTEXT)
 		intel_ctx_destroy(fd, ctx);
 	if (flags & FD)
-		close(fd);
+		drm_close_driver(fd);
 }
 
 igt_main
tests/i915/gen7_exec_parse.c +2 -2
index 81a5bb14f..807cb1e9d 100644
@@ -476,7 +476,7 @@ static void hsw_load_register_reg(void)
 				   0xabcdabc0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -748,6 +748,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(fd, handle);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gen9_exec_parse.c +1 -1
index a927bfaca..33ff6bcb5 100644
@@ -1299,6 +1299,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(i915, handle);
 
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_fb_tiling.c +1 -1
index 586950266..14c17b030 100644
@@ -52,5 +52,5 @@ igt_simple_main
 	igt_assert_eq(ret, -EBUSY);
 
 	igt_remove_fb(drm_fd, &fb);
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
tests/i915/i915_getparams_basic.c +1 -1
index 74ccaf4d3..b22ab5d93 100644
@@ -62,7 +62,7 @@ init(void)
 static void
 deinit(void)
 {
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 
tests/i915/i915_hangman.c +2 -2
index fc46bd297..dcd34cd0e 100644
@@ -160,7 +160,7 @@ static void check_alive(void)
 	put_ahnd(ahnd);
 	intel_ctx_destroy(fd, ctx);
 	gem_quiescent_gpu(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static bool has_error_state(int dir)
@@ -643,6 +643,6 @@ igt_main
 
 		igt_disallow_hang(device, hang);
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/i915_hwmon.c +1 -1
index 279f6821b..48ed9f3b7 100644
@@ -96,6 +96,6 @@ igt_main
 
 	igt_fixture {
 		close(hwm);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_module_load.c +4 -4
index df24aee5e..9fffe93d9 100644
@@ -280,7 +280,7 @@ static void gem_sanitycheck(void)
 		store_all(i915);
 	errno = 0;
 
-	close(i915);
+	drm_close_driver(i915);
 	igt_assert_eq(err, expected);
 }
 
@@ -328,7 +328,7 @@ static void load_and_check_i915(void)
 
 	/* make sure the GPU is idle */
 	gem_quiescent_gpu(drm_fd);
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 
 	/* make sure we can do basic memory ops */
 	gem_sanitycheck();
@@ -369,7 +369,7 @@ static uint32_t  driver_load_with_lmem_bar_size(uint32_t lmem_bar_size, bool che
 		}
 	}
 
-	close(i915);
+	drm_close_driver(i915);
 
 	return lmem_bar_size;
 }
@@ -461,7 +461,7 @@ igt_main
 			igt_require_gem(i915);
 			igt_require(gem_has_lmem(i915));
 			igt_skip_on_f(igt_sysfs_get_num_gt(i915) > 1, "Skips for more than one lmem instance.\n");
-			close(i915);
+			drm_close_driver(i915);
 		}
 
 		/* Test for lmem_bar_size modparam support */
tests/i915/i915_pciid.c +1 -1
index c44be56dc..8322bd564 100644
@@ -77,5 +77,5 @@ igt_simple_main
 
 	igt_assert(has_known_intel_chipset(intel));
 
-	close(intel);
+	drm_close_driver(intel);
 }
tests/i915/i915_pm_backlight.c +1 -1
index b633387bc..3c73b054b 100644
@@ -357,6 +357,6 @@ igt_main
 
 		igt_display_fini(&display);
 		igt_pm_restore_sata_link_power_management();
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/i915/i915_pm_dc.c +1 -1
index 2bb07ba8b..5069ddcc3 100644
@@ -730,7 +730,7 @@ igt_main
 		close(data.debugfs_root_fd);
 		close(data.msr_fd);
 		display_fini(&data);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 
 	igt_exit();
tests/i915/i915_pm_freq_api.c +1 -1
index 9005cd220..7422493af 100644
@@ -150,6 +150,6 @@ igt_main
 			igt_assert(set_freq(dirfd, RPS_MAX_FREQ_MHZ, stash_max[gt]) > 0);
 			igt_assert(set_freq(dirfd, RPS_MIN_FREQ_MHZ, stash_min[gt]) > 0);
 		}
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_freq_mult.c +1 -1
index d75ec3f9e..af62bbc2c 100644
@@ -177,6 +177,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_lpsp.c +1 -1
index cb01a6d9e..291e56674 100644
@@ -223,6 +223,6 @@ igt_main
 	igt_fixture {
 		free(data.pwr_dmn_info);
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/i915_pm_rc6_residency.c +1 -1
index ce81e668a..b266680ac 100644
@@ -627,6 +627,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_rps.c +1 -1
index 238d39240..7044fcd81 100644
@@ -917,7 +917,7 @@ static void pm_rps_exit_handler(int sig)
 	if (lh.igt_proc.running)
 		load_helper_stop();
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 igt_main
tests/i915/i915_pm_sseu.c +1 -1
index 39eecb8fe..cee29a7c5 100644
@@ -323,7 +323,7 @@ gem_deinit(void)
 	case 2:
 		buf_ops_destroy(gem.bops);
 	case 1:
-		close(gem.drm_fd);
+		drm_close_driver(gem.drm_fd);
 	}
 }
 
tests/i915/i915_power.c +1 -1
index 3675b9d6d..ed7bef495 100644
@@ -86,6 +86,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_query.c +1 -1
index 194f2e91b..f97379b83 100644
@@ -1572,6 +1572,6 @@ igt_main
 		query_parse_and_validate_hwconfig_table(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_suspend.c +3 -3
index 9f0a4d2ac..851e797c2 100644
@@ -256,7 +256,7 @@ test_shrink(int fd, unsigned int mode)
 		igt_system_suspend_autoresume(mode, SUSPEND_TEST_NONE);
 
 		munmap(mem, size);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_waitchildren();
@@ -300,7 +300,7 @@ test_suspend_without_i915(int state)
 		igt_pm_get_d3cold_allowed(&card, d3cold_allowed);
 		igt_pm_set_d3cold_allowed(&card, "0\n");
 	}
-	close(fd);
+	drm_close_driver(fd);
 
 	igt_kmsg(KMSG_INFO "Unloading i915\n");
 	igt_assert_eq(igt_i915_driver_unload(),0);
@@ -383,5 +383,5 @@ igt_main
 		test_forcewake(fd, true);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/perf.c +3 -3
index 069ab8c02..3565d61cc 100644
@@ -4704,7 +4704,7 @@ gen12_test_single_ctx_render_target_writes_a_counter(const struct intel_executio
 			igt_drop_root();
 			gen12_single_ctx_helper(e);
 
-			close(drm_fd);
+			drm_close_driver(drm_fd);
 		}
 		child_ret = igt_wait_helper(&child);
 		igt_assert(WEXITSTATUS(child_ret) == EAGAIN ||
@@ -5485,7 +5485,7 @@ test_i915_ref_count(void)
 	igt_debug("ref count after opening i915 perf stream = %u\n", ref_count1);
 	igt_assert(ref_count1 > ref_count0);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 	close(sysfs);
 	drm_fd = -1;
 	sysfs = -1;
@@ -6194,6 +6194,6 @@ igt_main
 			put_engine_groups(perf_oa_groups, num_perf_oa_groups);
 
 		intel_ctx_destroy(drm_fd, ctx);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/i915/perf_pmu.c +3 -3
index 8b31df7b2..0806a8e54 100644
@@ -2424,7 +2424,7 @@ static void test_unload(unsigned int num_engines)
 		if (fd[count] != -1)
 			count++;
 
-		close(i915);
+		drm_close_driver(i915);
 
 		buf = calloc(count, sizeof(uint64_t));
 		igt_assert(buf);
@@ -2768,13 +2768,13 @@ igt_main
 
 		igt_fixture {
 			intel_ctx_destroy(render_fd, render_ctx);
-			close(render_fd);
+			drm_close_driver(render_fd);
 		}
 	}
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("module-unload") {
tests/i915/sysfs_defaults.c +1 -1
index 066532f0a..b686c19fc 100644
@@ -116,6 +116,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_heartbeat_interval.c +1 -1
index a3de43a37..22c5888c6 100644
@@ -543,6 +543,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_preempt_timeout.c +1 -1
index 3d24bf61c..964b78ae8 100644
@@ -362,6 +362,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_timeslice_duration.c +1 -1
index f1b518264..fc2b14e16 100644
@@ -587,6 +587,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
Signature · 1 line
2.40.0
#34 lore raw

PATCH v4 21/24 tests/i915: Use drm_close_driver() to close the drm fd

In reply to Bhanuprakash Modem

To close the drm file descriptor, use igt helper drm_close_driver() instead of using close().

V2: - New patch for generic tests
V3, V4: - Rebase

---
 tests/i915/api_intel_allocator.c            |  6 ++--
 tests/i915/api_intel_bb.c                   |  2 +-
 tests/i915/drm_fdinfo.c                     |  2 +-
 tests/i915/gem_bad_reloc.c                  |  2 +-
 tests/i915/gem_barrier_race.c               |  2 +-
 tests/i915/gem_basic.c                      |  2 +-
 tests/i915/gem_blits.c                      |  2 +-
 tests/i915/gem_busy.c                       |  2 +-
 tests/i915/gem_caching.c                    |  2 +-
 tests/i915/gem_ccs.c                        |  2 +-
 tests/i915/gem_close_race.c                 | 12 ++++----
 tests/i915/gem_cs_tlb.c                     |  2 +-
 tests/i915/gem_ctx_bad_destroy.c            |  2 +-
 tests/i915/gem_ctx_create.c                 |  4 +--
 tests/i915/gem_ctx_exec.c                   |  2 +-
 tests/i915/gem_ctx_param.c                  |  2 +-
 tests/i915/gem_ctx_persistence.c            |  6 ++--
 tests/i915/gem_ctx_shared.c                 |  2 +-
 tests/i915/gem_ctx_sseu.c                   |  2 +-
 tests/i915/gem_ctx_switch.c                 |  2 +-
 tests/i915/gem_eio.c                        | 16 +++++------
 tests/i915/gem_evict_alignment.c            |  2 +-
 tests/i915/gem_evict_everything.c           |  2 +-
 tests/i915/gem_exec_alignment.c             |  2 +-
 tests/i915/gem_exec_async.c                 |  2 +-
 tests/i915/gem_exec_await.c                 |  2 +-
 tests/i915/gem_exec_basic.c                 |  2 +-
 tests/i915/gem_exec_big.c                   |  2 +-
 tests/i915/gem_exec_capture.c               |  2 +-
 tests/i915/gem_exec_create.c                |  2 +-
 tests/i915/gem_exec_fair.c                  |  2 +-
 tests/i915/gem_exec_fence.c                 |  4 +--
 tests/i915/gem_exec_flush.c                 |  2 +-
 tests/i915/gem_exec_gttfill.c               |  4 +--
 tests/i915/gem_exec_latency.c               |  2 +-
 tests/i915/gem_exec_nop.c                   |  2 +-
 tests/i915/gem_exec_parallel.c              |  4 +--
 tests/i915/gem_exec_params.c                |  2 +-
 tests/i915/gem_exec_reloc.c                 |  2 +-
 tests/i915/gem_exec_schedule.c              |  2 +-
 tests/i915/gem_exec_store.c                 |  2 +-
 tests/i915/gem_exec_suspend.c               |  2 +-
 tests/i915/gem_exec_whisper.c               |  6 ++--
 tests/i915/gem_exercise_blt.c               |  2 +-
 tests/i915/gem_fd_exhaustion.c              |  2 +-
 tests/i915/gem_fence_thrash.c               |  2 +-
 tests/i915/gem_fenced_exec_thrash.c         |  2 +-
 tests/i915/gem_flink_basic.c                |  4 +--
 tests/i915/gem_flink_race.c                 |  6 ++--
 tests/i915/gem_gtt_cpu_tlb.c                |  2 +-
 tests/i915/gem_gtt_hog.c                    |  2 +-
 tests/i915/gem_gtt_speed.c                  |  2 +-
 tests/i915/gem_huc_copy.c                   |  2 +-
 tests/i915/gem_lmem_evict.c                 |  4 +--
 tests/i915/gem_lmem_swapping.c              | 10 +++----
 tests/i915/gem_madvise.c                    | 12 ++++----
 tests/i915/gem_media_fill.c                 |  2 +-
 tests/i915/gem_mmap.c                       |  2 +-
 tests/i915/gem_mmap_gtt.c                   |  6 ++--
 tests/i915/gem_mmap_offset.c                |  8 +++---
 tests/i915/gem_mmap_wc.c                    |  2 +-
 tests/i915/gem_partial_pwrite_pread.c       |  2 +-
 tests/i915/gem_pipe_control_store_loop.c    |  2 +-
 tests/i915/gem_ppgtt.c                      |  8 +++---
 tests/i915/gem_pread.c                      |  2 +-
 tests/i915/gem_pread_after_blit.c           |  2 +-
 tests/i915/gem_pwrite.c                     |  2 +-
 tests/i915/gem_pwrite_snooped.c             |  2 +-
 tests/i915/gem_pxp.c                        |  2 +-
 tests/i915/gem_read_read_speed.c            |  2 +-
 tests/i915/gem_readwrite.c                  |  2 +-
 tests/i915/gem_reg_read.c                   |  2 +-
 tests/i915/gem_render_copy.c                |  2 +-
 tests/i915/gem_render_copy_redux.c          |  2 +-
 tests/i915/gem_reset_stats.c                | 32 ++++++++++-----------
 tests/i915/gem_ringfill.c                   |  2 +-
 tests/i915/gem_set_tiling_vs_blt.c          |  2 +-
 tests/i915/gem_set_tiling_vs_gtt.c          |  2 +-
 tests/i915/gem_set_tiling_vs_pwrite.c       |  2 +-
 tests/i915/gem_shrink.c                     | 14 ++++-----
 tests/i915/gem_softpin.c                    |  4 +--
 tests/i915/gem_spin_batch.c                 |  2 +-
 tests/i915/gem_streaming_writes.c           |  2 +-
 tests/i915/gem_stress.c                     |  2 +-
 tests/i915/gem_sync.c                       |  2 +-
 tests/i915/gem_tiled_blits.c                |  2 +-
 tests/i915/gem_tiled_fence_blits.c          |  2 +-
 tests/i915/gem_tiled_partial_pwrite_pread.c |  2 +-
 tests/i915/gem_tiled_pread_basic.c          |  2 +-
 tests/i915/gem_tiled_pread_pwrite.c         |  2 +-
 tests/i915/gem_tiled_swapping.c             |  2 +-
 tests/i915/gem_tiled_wb.c                   |  2 +-
 tests/i915/gem_tiled_wc.c                   |  2 +-
 tests/i915/gem_tiling_max_stride.c          |  2 +-
 tests/i915/gem_unfence_active_buffers.c     |  2 +-
 tests/i915/gem_unref_active_buffers.c       |  2 +-
 tests/i915/gem_userptr_blits.c              |  6 ++--
 tests/i915/gem_vm_create.c                  |  4 +--
 tests/i915/gem_wait.c                       |  2 +-
 tests/i915/gem_watchdog.c                   |  2 +-
 tests/i915/gem_workarounds.c                |  2 +-
 tests/i915/gen7_exec_parse.c                |  4 +--
 tests/i915/gen9_exec_parse.c                |  2 +-
 tests/i915/i915_fb_tiling.c                 |  2 +-
 tests/i915/i915_getparams_basic.c           |  2 +-
 tests/i915/i915_hangman.c                   |  4 +--
 tests/i915/i915_hwmon.c                     |  2 +-
 tests/i915/i915_module_load.c               |  8 +++---
 tests/i915/i915_pciid.c                     |  2 +-
 tests/i915/i915_pm_backlight.c              |  2 +-
 tests/i915/i915_pm_dc.c                     |  2 +-
 tests/i915/i915_pm_freq_api.c               |  2 +-
 tests/i915/i915_pm_freq_mult.c              |  2 +-
 tests/i915/i915_pm_lpsp.c                   |  2 +-
 tests/i915/i915_pm_rc6_residency.c          |  2 +-
 tests/i915/i915_pm_rps.c                    |  2 +-
 tests/i915/i915_pm_sseu.c                   |  2 +-
 tests/i915/i915_power.c                     |  2 +-
 tests/i915/i915_query.c                     |  2 +-
 tests/i915/i915_suspend.c                   |  6 ++--
 tests/i915/perf.c                           |  6 ++--
 tests/i915/perf_pmu.c                       |  6 ++--
 tests/i915/sysfs_defaults.c                 |  2 +-
 tests/i915/sysfs_heartbeat_interval.c       |  2 +-
 tests/i915/sysfs_preempt_timeout.c          |  2 +-
 tests/i915/sysfs_timeslice_duration.c       |  2 +-
 126 files changed, 205 insertions(+), 205 deletions(-)
tests/i915/api_intel_allocator.c +3 -3
index cc6f8daa4..b7e3efb87 100644
@@ -579,7 +579,7 @@ static void reopen(int fd)
 
 	__reopen_allocs(fd, fd2, true);
 
-	close(fd2);
+	drm_close_driver(fd2);
 }
 
 #define REOPEN_TIMEOUT 3
@@ -605,7 +605,7 @@ static void reopen_fork(int fd)
 	/* Check references at the end */
 	__reopen_allocs(fd, fd2, true);
 
-	close(fd2);
+	drm_close_driver(fd2);
 
 	intel_allocator_multiprocess_stop();
 }
@@ -924,5 +924,5 @@ igt_main
 		gem_pool(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/api_intel_bb.c +1 -1
index fefb5d996..59ed244f0 100644
@@ -1908,6 +1908,6 @@ igt_main_args("dpibc:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/drm_fdinfo.c +1 -1
index d061e901f..c0e0ba190 100644
@@ -910,6 +910,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_bad_reloc.c +1 -1
index d5336b62d..b058639ea 100644
@@ -231,5 +231,5 @@ igt_main
 		negative_reloc_blt(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_barrier_race.c +1 -1
index 0ac1da3a4..591ddc222 100644
@@ -120,7 +120,7 @@ static void intel_context_first_pin_last_unpin_loop(int fd, uint64_t engine, int
 
 	} while (!READ_ONCE(*done));
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_remote_request(int fd, uint64_t engine, unsigned int timeout)
tests/i915/gem_basic.c +1 -1
index 6843bec16..3485f92c8 100644
@@ -145,7 +145,7 @@ igt_main
 			gpu_fd = __drm_open_driver_another(child, DRIVER_INTEL);
 			igt_assert_f(gpu_fd > 0, "cannot open gpu-%d, errno=%d\n", child, errno);
 			test_create_close(gpu_fd);
-			close(gpu_fd);
+			drm_close_driver(gpu_fd);
 		}
 
 		igt_waitchildren();
tests/i915/gem_blits.c +1 -1
index f058644ba..e567cdf33 100644
@@ -904,6 +904,6 @@ igt_main
 
 	igt_fixture {
 		put_ahnd(device.ahnd);
-		close(device.fd);
+		drm_close_driver(device.fd);
 	}
 }
tests/i915/gem_busy.c +1 -1
index b796ebb2b..c60654b1e 100644
@@ -617,6 +617,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_caching.c +1 -1
index 55e466a3e..4a8f69e97 100644
@@ -356,6 +356,6 @@ igt_main
 		intel_buf_destroy(scratch_buf);
 		intel_buf_destroy(staging_buf);
 		buf_ops_destroy(data.bops);
-		close(data.fd);
+		drm_close_driver(data.fd);
 	}
 }
tests/i915/gem_ccs.c +1 -1
index 1b2311f69..f9ad9267d 100644
@@ -764,6 +764,6 @@ igt_main_args("bf:pst:W:H:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_disallow_hang(i915, hang);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_close_race.c +6 -6
index 22cdc5874..cef0ff025 100644
@@ -329,7 +329,7 @@ static void multigpu_threads(int timeout, unsigned int flags, int gpu_count)
 
 		igt_waitchildren();
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_waitchildren();
@@ -348,7 +348,7 @@ static void threads(int timeout, unsigned int flags)
 	igt_waitchildren();
 
 	gem_quiescent_gpu(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -372,7 +372,7 @@ igt_main
 		gpu_count = igt_device_filter_count();
 
 		igt_fork_hang_detector(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Basic workload submission.");
@@ -384,7 +384,7 @@ igt_main
 		igt_waitchildren();
 
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Basic workload submission on multi-GPU machine.");
@@ -397,7 +397,7 @@ igt_main
 			igt_assert(fd > 0);
 			process(fd, child);
 			gem_quiescent_gpu(fd);
-			close(fd);
+			drm_close_driver(fd);
 		}
 
 		igt_waitchildren();
@@ -424,7 +424,7 @@ igt_main
 		igt_waitchildren();
 
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Share buffer handle across different drm fd's and trying to race"
tests/i915/gem_cs_tlb.c +1 -1
index 3f285f42c..2c7781d06 100644
@@ -174,5 +174,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_bad_destroy.c +1 -1
index 8c47e7c1c..65f6b5583 100644
@@ -98,5 +98,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_create.c +2 -2
index 95e219482..6d0877954 100644
@@ -206,7 +206,7 @@ static void files(int core, const intel_ctx_cfg_t *cfg,
 			gem_execbuf(fd, &execbuf);
 
 			intel_ctx_destroy(fd, ctx);
-			close(fd);
+			drm_close_driver(fd);
 			count++;
 
 			clock_gettime(CLOCK_MONOTONIC, &end);
@@ -756,6 +756,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_exec.c +1 -1
index f3939df86..4376397a2 100644
@@ -403,7 +403,7 @@ static void nohangcheck_hostile(int i915)
 	put_ahnd(ahnd);
 
 	close(dir);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 static void close_race(int i915)
tests/i915/gem_ctx_param.c +1 -1
index 7c59fe3ed..9b44c86a0 100644
@@ -636,5 +636,5 @@ igt_main
 		test_get_invalid_param(fd, I915_CONTEXT_PARAM_ENGINES);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_persistence.c +3 -3
index d2558354e..c6e2c5d77 100644
@@ -791,7 +791,7 @@ static void test_nonpersistent_file(int i915)
 	gem_context_set_persistence(i915, 0, false);
 	spin = igt_spin_new(i915, .ahnd = ahnd, .flags = IGT_SPIN_FENCE_OUT);
 
-	close(i915);
+	drm_close_driver(i915);
 	flush_delayed_fput(debugfs);
 
 	igt_assert_eq(wait_for_status(spin->out_fence, reset_timeout_ms), -EIO);
@@ -1274,7 +1274,7 @@ static void __smoker(int i915, const intel_ctx_cfg_t *cfg,
 
 	intel_ctx_destroy(fd, ctx);
 
-	close(fd);
+	drm_close_driver(fd);
 	flush_delayed_fput(i915);
 
 	igt_spin_end(spin);
@@ -1570,6 +1570,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_ctx_shared.c +1 -1
index ede6db13b..d24ae5483 100644
@@ -315,7 +315,7 @@ static void exhaust_shared_gtt(int i915, unsigned int flags)
 		igt_info("Created %lu shared contexts, before %d (%s)\n",
 			 count, err, strerror(-err));
 	}
-	close(i915);
+	drm_close_driver(i915);
 	igt_waitchildren();
 }
 
tests/i915/gem_ctx_sseu.c +1 -1
index 78748c24d..3a01944e4 100644
@@ -559,6 +559,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_switch.c +1 -1
index b0066ab27..f94a41bec 100644
@@ -805,6 +805,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(fd, heavy);
 		gem_close(fd, light);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_eio.c +8 -8
index 38fd19e89..d889d67dc 100644
@@ -656,7 +656,7 @@ static void test_banned(int fd)
 {
 	fd = reopen_device(fd);
 	__test_banned(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 #define TEST_WEDGE (1)
@@ -690,7 +690,7 @@ static void test_wait(int fd, unsigned int flags, unsigned int wait)
 	igt_require(i915_reset_control(fd, true));
 
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_suspend(int fd, int state)
@@ -708,7 +708,7 @@ static void test_suspend(int fd, int state)
 
 	igt_require(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_inflight(int fd, unsigned int wait)
@@ -772,7 +772,7 @@ static void test_inflight(int fd, unsigned int wait)
 		trigger_reset(fd);
 
 		gem_close(fd, obj[1].handle);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
 
@@ -833,7 +833,7 @@ static void test_inflight_suspend(int fd)
 
 	igt_assert(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static const intel_ctx_t *context_create_safe(int i915)
@@ -923,7 +923,7 @@ static void test_inflight_contexts(int fd, unsigned int wait)
 		for (unsigned int n = 0; n < ARRAY_SIZE(ctx); n++)
 			intel_ctx_destroy(fd, ctx[n]);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
 
@@ -979,7 +979,7 @@ static void test_inflight_external(int fd)
 	put_ahnd(ahnd);
 	igt_assert(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_inflight_internal(int fd, unsigned int wait)
@@ -1029,7 +1029,7 @@ static void test_inflight_internal(int fd, unsigned int wait)
 
 	igt_assert(i915_reset_control(fd, true));
 	trigger_reset(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void reset_stress(int fd, uint64_t ahnd, const intel_ctx_t *ctx0,
tests/i915/gem_evict_alignment.c +1 -1
index f04f24972..4a9507a06 100644
@@ -282,6 +282,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_evict_everything.c +1 -1
index 87f854bf8..f0f356cc3 100644
@@ -351,6 +351,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_alignment.c +1 -1
index 9d965270f..10732fec5 100644
@@ -487,7 +487,7 @@ static void forked(int i915, int timeout)
 	igt_waitchildren_timeout(3 * timeout, NULL);
 
 	free(obj);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 static void single(int fd)
tests/i915/gem_exec_async.c +1 -1
index f3c2f671f..8c131d8e1 100644
@@ -227,6 +227,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_await.c +1 -1
index c78403466..53b7bac2f 100644
@@ -300,6 +300,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_basic.c +1 -1
index 623f1ee52..83f71e289 100644
@@ -113,6 +113,6 @@ igt_main
 		igt_collection_destroy(set);
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_big.c +1 -1
index 3acdb3741..9de9941d5 100644
@@ -340,5 +340,5 @@ igt_main
 		exhaustive(i915);
 
 	igt_fixture
-		close(i915);
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_capture.c +1 -1
index 453ae1af9..ab8305e4d 100644
@@ -1055,6 +1055,6 @@ igt_main
 		close(dir);
 		igt_disallow_hang(fd, hang);
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_create.c +1 -1
index 00c190115..4eb77ecbb 100644
@@ -270,6 +270,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_fair.c +1 -1
index eedcfdf80..5ad13f97a 100644
@@ -1440,6 +1440,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_fence.c +2 -2
index d6253a379..4bf29a3e4 100644
@@ -2118,7 +2118,7 @@ static void test_invalid_timeline_fence_array(int fd)
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EFAULT);
 
 	munmap(ptr, 4096);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static const char *test_syncobj_timeline_unused_fence_desc =
@@ -3701,6 +3701,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_flush.c +1 -1
index e213bda5e..3902ee957 100644
@@ -2207,6 +2207,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_gttfill.c +2 -2
index 4c32a04c0..28c251915 100644
@@ -314,7 +314,7 @@ igt_main
 			// release resources
 			igt_stop_hang_detector();
 			intel_ctx_destroy(g_fd, ctx);
-			close(g_fd);
+			drm_close_driver(g_fd);
 		}
 
 		igt_waitchildren();
@@ -322,6 +322,6 @@ igt_main
 
 	igt_fixture {
 		intel_allocator_multiprocess_stop();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_latency.c +1 -1
index 9a9e43bab..c0e607f97 100644
@@ -1001,6 +1001,6 @@ igt_main
 	igt_fixture {
 		intel_register_access_fini(&mmio_data);
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_nop.c +1 -1
index 067c92b47..6dea8b167 100644
@@ -1150,6 +1150,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(device, handle);
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_parallel.c +2 -2
index bba861185..cae1553f6 100644
@@ -230,7 +230,7 @@ static void *thread(void *data)
 		intel_ctx_destroy(fd, tmp_ctx);
 	gem_close(fd, obj[1].handle);
 	if (t->flags & FDS)
-		close(fd);
+		drm_close_driver(fd);
 
 	t->used = used;
 	return NULL;
@@ -413,6 +413,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_params.c +1 -1
index 16ae7a5a6..caaa5fee0 100644
@@ -825,6 +825,6 @@ igt_main
 	igt_fixture {
 		gem_close(fd, handle);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_reloc.c +1 -1
index c591f374d..8259ff1d9 100644
@@ -1771,5 +1771,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_exec_schedule.c +1 -1
index c9be726ab..c94988d36 100644
@@ -3755,6 +3755,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_store.c +1 -1
index d61072dfa..0ab931062 100644
@@ -480,6 +480,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_suspend.c +1 -1
index 73fbf8cf6..39d75ee03 100644
@@ -510,6 +510,6 @@ igt_main
 		igt_collection_destroy(set);
 		igt_disallow_hang(fd, hang);
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_whisper.c +3 -3
index 1379f10dc..46712c3e8 100644
@@ -457,7 +457,7 @@ static void fini_hang(struct hang *h)
 	put_offset(h->ahnd, h->obj.handle);
 	put_ahnd(h->ahnd);
 	intel_ctx_destroy(h->fd, h->ctx);
-	close(h->fd);
+	drm_close_driver(h->fd);
 }
 
 static void ctx_set_random_priority(int fd, uint32_t ctx)
@@ -829,7 +829,7 @@ static void whisper(int fd, const intel_ctx_t *ctx,
 			gem_close(fd, batches[n].handle);
 		if (flags & FDS) {
 			for (n = 0; n < 64; n++)
-				close(fds[n]);
+				drm_close_driver(fds[n]);
 		}
 	}
 
@@ -939,6 +939,6 @@ igt_main
 	igt_fixture {
 		intel_allocator_multiprocess_stop();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exercise_blt.c +1 -1
index 3ec02c22e..0cd182043 100644
@@ -398,6 +398,6 @@ igt_main_args("b:pst:W:H:", NULL, help_str, opt_handler, NULL)
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_fd_exhaustion.c +1 -1
index 75485c1cb..e79d03478 100644
@@ -75,5 +75,5 @@ igt_simple_main
 
 	igt_waitchildren();
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_fence_thrash.c +1 -1
index f8ac29dd7..4cb3d842b 100644
@@ -244,7 +244,7 @@ static int run_test(int threads_per_fence, void *f, int tiling,
 		igt_assert(func(&t) == (void *)0);
 	}
 
-	close(t.fd);
+	drm_close_driver(t.fd);
 
 	return 0;
 }
tests/i915/gem_fenced_exec_thrash.c +1 -1
index f22f16f68..098f22ef4 100644
@@ -217,5 +217,5 @@ igt_main
 		run_test(fd, num_fences + 1, intel_gen(devid) >= 4 ? 0 : ENOBUFS, 0);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_flink_basic.c +2 -2
index 8a316cdae..e70cab4d1 100644
@@ -196,7 +196,7 @@ test_flink_lifetime(int fd)
 	igt_assert_eq(ret, 0);
 	igt_assert(open_struct.handle != 0);
 
-	close(fd2);
+	drm_close_driver(fd2);
 	fd2 = drm_open_driver(DRIVER_INTEL);
 
 	/* Flink name remains valid due to the second reference */
@@ -205,7 +205,7 @@ test_flink_lifetime(int fd)
 	igt_assert_eq(ret, 0);
 	igt_assert(open_struct.handle != 0);
 
-	close(fd2);
+	drm_close_driver(fd2);
 }
 
 igt_main
tests/i915/gem_flink_race.c +3 -3
index a9177ce1b..41c15f298 100644
@@ -141,7 +141,7 @@ static void test_flink_name(int timeout)
 		 igt_stats_get_max(&stats));
 	igt_stats_fini(&stats);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void *thread_fn_flink_close(void *p)
@@ -202,13 +202,13 @@ static void test_flink_close(void)
 		igt_assert(status == 0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 
 	obj_count = igt_get_stable_obj_count(fake) - obj_count;
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	close(fake);
+	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
 }
tests/i915/gem_gtt_cpu_tlb.c +1 -1
index 4f4af6a7b..155aa6516 100644
@@ -113,5 +113,5 @@ igt_simple_main
 	for (i = 0; i < OBJ_SIZE/4; i++)
 		igt_assert(ptr[i] == i);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_gtt_hog.c +1 -1
index 4c8158c6d..1227c7633 100644
@@ -170,7 +170,7 @@ igt_simple_main
 	int fd = drm_open_driver(DRIVER_INTEL);
 	igt_require_gem(fd);
 	gem_require_mappable_ggtt(fd);
-	close(fd);
+	drm_close_driver(fd);
 
 	data.fd = drm_open_driver(DRIVER_INTEL);
 	data.devid = intel_get_drm_devid(data.fd);
tests/i915/gem_gtt_speed.c +1 -1
index a0e37b19e..c85c359a0 100644
@@ -521,5 +521,5 @@ igt_simple_main_args("s:", NULL, help_str, opt_handler, NULL)
 	}
 
 	gem_close(fd, handle);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_huc_copy.c +1 -1
index 5a217c984..246fa0a8b 100644
@@ -150,6 +150,6 @@ igt_main
 
 	igt_fixture {
 		put_ahnd(ahnd);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/i915/gem_lmem_evict.c +2 -2
index 54277e11d..a3ca2c861 100644
@@ -103,7 +103,7 @@ igt_main
 			igt_require_fd(i915);
 			igt_require_gem(i915);
 			igt_require(gem_has_lmem(i915));
-			close(i915);
+			drm_close_driver(i915);
 		}
 
 		igt_i915_driver_unload();
@@ -142,7 +142,7 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 		igt_i915_driver_unload();
 	}
 }
tests/i915/gem_lmem_swapping.c +5 -5
index 0ef1ceb13..83dbebec8 100644
@@ -718,7 +718,7 @@ static void test_evict(int i915,
 
 		igt_waitchildren();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 		intel_allocator_multiprocess_stop();
 	} else {
 		__do_evict(i915, ctx, &region->region, &params, params.seed);
@@ -790,7 +790,7 @@ static void test_smem_oom(int i915,
 			   params.seed + child + 1);
 
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	/* smem memory hog process, respawn till the lmem process completes */
@@ -811,7 +811,7 @@ static void test_smem_oom(int i915,
 						break;
 					gem_leak(fd, alloc);
 				}
-				close(fd);
+				drm_close_driver(fd);
 			}
 			/*
 			 * Wait for grand-child processes to finish or be
@@ -903,7 +903,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 			igt_require_fd(i915);
 			igt_require_gem(i915);
 			igt_require(gem_has_lmem(i915));
-			close(i915);
+			drm_close_driver(i915);
 		}
 
 		igt_i915_driver_unload();
@@ -948,7 +948,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
 		free(regions);
-		close(i915);
+		drm_close_driver(i915);
 		igt_i915_driver_unload();
 	}
 
tests/i915/gem_madvise.c +6 -6
index 4efa359ba..765809e7f 100644
@@ -110,7 +110,7 @@ dontneed_before_mmap(void)
 					PROT_READ | PROT_WRITE,
 					t->type);
 
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -132,7 +132,7 @@ dontneed_before_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -156,7 +156,7 @@ dontneed_after_mmap(void)
 					t->type);
 
 		gem_madvise(fd, handle, I915_MADV_DONTNEED);
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -178,7 +178,7 @@ dontneed_after_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -194,7 +194,7 @@ dontneed_before_pwrite(void)
 
 	igt_assert_eq(__gem_write(fd, handle, 0, &bbe, sizeof(bbe)), -EFAULT);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -218,7 +218,7 @@ dontneed_before_exec(void)
 	execbuf.batch_len = sizeof(buf);
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EFAULT);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
tests/i915/gem_media_fill.c +1 -1
index 07e7b3ccb..a678d2f99 100644
@@ -181,6 +181,6 @@ igt_main
 	igt_fixture {
 		igt_collection_destroy(set);
 		igt_stop_hang_detector();
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/gem_mmap.c +1 -1
index 421c6f859..d4ca1eda7 100644
@@ -372,5 +372,5 @@ igt_main
 		test_huge_bo(2);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_gtt.c +3 -3
index e5d3aa079..9c06785d2 100644
@@ -869,13 +869,13 @@ test_isolation(int i915)
 	igt_info("B: {fd:%d, handle:%d, offset:%"PRIx64"}\n",
 		 B, b, offset_b);
 
-	close(B);
+	drm_close_driver(B);
 
 	ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 	igt_assert(ptr != MAP_FAILED);
 	munmap(ptr, 4096);
 
-	close(A);
+	drm_close_driver(A);
 
 	ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 	igt_assert(ptr == MAP_FAILED);
@@ -1979,5 +1979,5 @@ igt_main
 
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_offset.c +4 -4
index 2537ecdc5..bc801cd04 100644
@@ -434,13 +434,13 @@ static void isolation(int i915)
 				igt_assert_eq(errno, EACCES);
 			}
 
-			close(B);
+			drm_close_driver(B);
 
 			ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 			igt_assert(ptr != MAP_FAILED);
 			munmap(ptr, 4096);
 
-			close(A);
+			drm_close_driver(A);
 
 			ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 			igt_assert(ptr == MAP_FAILED);
@@ -735,7 +735,7 @@ static void open_flood(int i915, int timeout)
 			mmap_offset_ioctl(i915, &arg);
 		}
 
-		close(tmp);
+		drm_close_driver(tmp);
 		count++;
 	}
 
@@ -1013,6 +1013,6 @@ igt_main
 		blt_coherency(i915);
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_mmap_wc.c +1 -1
index ce1c19083..c56e8c353 100644
@@ -687,5 +687,5 @@ igt_main
 		test_set_cache_level(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_partial_pwrite_pread.c +1 -1
index 1b533ef30..659a96b6e 100644
@@ -388,6 +388,6 @@ igt_main
 		intel_buf_destroy(scratch_buf);
 		intel_buf_destroy(staging_buf);
 		buf_ops_destroy(data.bops);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/gem_pipe_control_store_loop.c +1 -1
index 986dbf673..1913b874a 100644
@@ -199,6 +199,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ppgtt.c +4 -4
index 9dc6ccfe4..b6081b1e9 100644
@@ -278,8 +278,8 @@ static void flink_and_close(void)
 	igt_assert_eq(offset, offset_new);
 
 	gem_close(fd, bo);
-	close(fd);
-	close(fd2);
+	drm_close_driver(fd);
+	drm_close_driver(fd2);
 }
 
 #define PAGE_SIZE 4096
@@ -412,7 +412,7 @@ static bool has_contexts(void)
 
 	fd = drm_open_driver(DRIVER_INTEL);
 	result = gem_has_contexts(fd);
-	close(fd);
+	drm_close_driver(fd);
 
 	return result;
 }
@@ -425,7 +425,7 @@ igt_main
 		int fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
 		gem_require_blitter(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("blt-vs-render-ctx0") {
tests/i915/gem_pread.c +1 -1
index 1dbded440..6f50785da 100644
@@ -367,6 +367,6 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 		free(src);
 		gem_close(fd, dst);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_pread_after_blit.c +1 -1
index fc6ee4408..b3e20697d 100644
@@ -281,5 +281,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_pwrite.c +1 -1
index 8471f963d..e2b48b843 100644
@@ -639,5 +639,5 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_pwrite_snooped.c +1 -1
index 7135dca57..5d9e8da20 100644
@@ -148,5 +148,5 @@ igt_simple_main
 	test(256, 256);
 
 	buf_ops_destroy(bops);
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_pxp.c +1 -1
index 167877d31..4aea765fe 100644
@@ -1372,6 +1372,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_read_read_speed.c +1 -1
index 7eeba7c6a..95ef47da6 100644
@@ -275,6 +275,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_readwrite.c +1 -1
index fdc68e315..864a2d8d8 100644
@@ -158,5 +158,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_reg_read.c +1 -1
index 5f63c02f7..de6788abe 100644
@@ -181,6 +181,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_render_copy.c +1 -1
index 657509647..406c30915 100644
@@ -999,6 +999,6 @@ igt_main_args("dac", NULL, help_str, opt_handler, NULL)
 		igt_stop_hang_detector();
 		buf_ops_destroy(data.bops);
 		igt_collection_destroy(set);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/gem_render_copy_redux.c +1 -1
index 0cb2936d3..06777dd7f 100644
@@ -98,7 +98,7 @@ static void data_init(data_t *data)
 static void data_fini(data_t *data)
 {
 	buf_ops_destroy(data->bops);
-	close(data->fd);
+	drm_close_driver(data->fd);
 }
 
 static void scratch_buf_init(data_t *data, struct intel_buf *buf,
tests/i915/gem_reset_stats.c +16 -16
index 7ec9264b5..6939722c7 100644
@@ -475,7 +475,7 @@ static void test_rs(const struct intel_execution_ring *e,
 	igt_assert(igt_seconds_elapsed(&ts_injected) <= 30);
 
 	for (i = 0; i < num_fds; i++)
-		close(fd[i]);
+		drm_close_driver(fd[i]);
 }
 
 #define MAX_CTX 100
@@ -551,7 +551,7 @@ static void test_rs_ctx(const struct intel_execution_ring *e,
 
 	for (i = 0; i < num_fds; i++) {
 		assert_reset_status(i, fd[i], 0, RS_NO_ERROR);
-		close(fd[i]);
+		drm_close_driver(fd[i]);
 	}
 }
 
@@ -605,8 +605,8 @@ static void test_ban(const struct intel_execution_ring *e)
 	igt_assert_eq(gem_reset_stats(fd_good, 0, &rs_good), 0);
 	igt_assert_eq(rs_good.batch_active, 0);
 
-	close(fd_bad);
-	close(fd_good);
+	drm_close_driver(fd_bad);
+	drm_close_driver(fd_good);
 }
 
 static void test_ban_ctx(const struct intel_execution_ring *e)
@@ -664,7 +664,7 @@ static void test_ban_ctx(const struct intel_execution_ring *e)
 	igt_assert_eq(gem_reset_stats(fd, ctx_good, &rs_good), 0);
 	igt_assert_eq(rs_good.batch_active, 0);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_unrelated_ctx(const struct intel_execution_ring *e)
@@ -690,8 +690,8 @@ static void test_unrelated_ctx(const struct intel_execution_ring *e)
 	assert_reset_status(0, fd1, ctx_guilty, RS_BATCH_ACTIVE);
 	assert_reset_status(1, fd2, ctx_unrelated, RS_NO_ERROR);
 
-	close(fd1);
-	close(fd2);
+	drm_close_driver(fd1);
+	drm_close_driver(fd2);
 }
 
 static int get_reset_count(int fd, int ctx)
@@ -717,7 +717,7 @@ static void test_close_pending_ctx(const struct intel_execution_ring *e)
 	gem_context_destroy(fd, ctx);
 	igt_assert_eq(__gem_context_destroy(fd, ctx), -ENOENT);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_close_pending(const struct intel_execution_ring *e)
@@ -727,7 +727,7 @@ static void test_close_pending(const struct intel_execution_ring *e)
 	assert_reset_status(fd, fd, 0, RS_NO_ERROR);
 
 	inject_hang(fd, 0, e, 0);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void noop_on_each_ring(int fd, const bool reverse)
@@ -789,7 +789,7 @@ static void test_close_pending_fork(const struct intel_execution_ring *e,
 		 * when gpu is reset and ring lists are cleared.
 		 */
 		noop_on_each_ring(fd2, reverse);
-		close(fd2);
+		drm_close_driver(fd2);
 		pause();
 		exit(0);
 	} else {
@@ -802,7 +802,7 @@ static void test_close_pending_fork(const struct intel_execution_ring *e,
 	}
 
 	igt_post_hang_ring(fd, hang);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_reset_count(const struct intel_execution_ring *e,
@@ -842,7 +842,7 @@ static void test_reset_count(const struct intel_execution_ring *e,
 	if (create_ctx)
 		gem_context_destroy(fd, ctx);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static int _test_params(int fd, int ctx, uint32_t flags, uint32_t pad)
@@ -913,7 +913,7 @@ static void test_params_ctx(void)
 
 	fd = drm_reopen_driver(device);
 	_test_param(fd, gem_context_create(fd));
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_params(void)
@@ -922,7 +922,7 @@ static void test_params(void)
 
 	fd = drm_reopen_driver(device);
 	_test_param(fd, 0);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static const struct intel_execution_ring *
@@ -968,7 +968,7 @@ static void defer_hangcheck(const struct intel_execution_ring *engine)
 
 	igt_assert_lt(count_start, count_end);
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static bool gem_has_reset_stats(int fd)
@@ -1177,6 +1177,6 @@ igt_main
 	}
 	igt_fixture {
 		igt_assert(igt_params_set(device, "reset", "%d", INT_MAX /* any reset method */));
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_ringfill.c +1 -1
index 52471948e..c718d6fe7 100644
@@ -522,6 +522,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_set_tiling_vs_blt.c +1 -1
index cee4591b8..e9d5e3c63 100644
@@ -276,6 +276,6 @@ igt_main
 
 	igt_fixture{
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_set_tiling_vs_gtt.c +1 -1
index 30b69bb8b..4a7ecdc88 100644
@@ -138,5 +138,5 @@ igt_simple_main
 
 	munmap(ptr, OBJECT_SIZE);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_set_tiling_vs_pwrite.c +1 -1
index 328682d94..ede0c58b6 100644
@@ -107,5 +107,5 @@ igt_simple_main
 
 	munmap(ptr, OBJECT_SIZE);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_shrink.c +7 -7
index 79301754b..1f16f8a78 100644
@@ -381,7 +381,7 @@ static bool has_userptr(void)
 	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr))
 		err = errno;
 
-	close(fd);
+	drm_close_driver(fd);
 
 	return err == EFAULT;
 }
@@ -430,7 +430,7 @@ static void run_test(int nchildren, uint64_t alloc,
 				int fd = drm_open_driver(DRIVER_INTEL);
 				for (int pass = 0; pass < nchildren; pass++)
 					leak(fd, alloc);
-				close(fd);
+				drm_close_driver(fd);
 			}
 		}
 	}
@@ -442,7 +442,7 @@ static void run_test(int nchildren, uint64_t alloc,
 				int fd = drm_open_driver(DRIVER_INTEL);
 				for (int pass = 0; pass < nchildren; pass++)
 					userptr(fd, alloc, 0);
-				close(fd);
+				drm_close_driver(fd);
 			}
 		}
 		nchildren = (nchildren + 1)/2;
@@ -455,7 +455,7 @@ static void run_test(int nchildren, uint64_t alloc,
 				int fd = drm_open_driver(DRIVER_INTEL);
 				for (int pass = 0; pass < nchildren; pass++)
 					userptr(fd, alloc, UDIRTY);
-				close(fd);
+				drm_close_driver(fd);
 			}
 		}
 		nchildren = (nchildren + 1)/2;
@@ -467,7 +467,7 @@ static void run_test(int nchildren, uint64_t alloc,
 			int fd = drm_open_driver(DRIVER_INTEL);
 			for (int pass = 0; pass < nchildren; pass++)
 				func(fd, alloc);
-			close(fd);
+			drm_close_driver(fd);
 		}
 	}
 	igt_waitchildren();
@@ -510,7 +510,7 @@ static void reclaim(unsigned engine, int timeout)
 
 	munmap((void *)shared, 4096);
 	close(debugfs);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -567,7 +567,7 @@ igt_main
 			 num_processes, alloc_size);
 
 		alloc_size <<= 20;
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("reclaim")
tests/i915/gem_softpin.c +2 -2
index 62478f4a3..e6cbf624e 100644
@@ -1433,7 +1433,7 @@ static void *thread(void *data)
 			  fd, ctx->id, t->engine, succeeded);
 	intel_ctx_destroy(fd, ctx);
 	gem_close(fd, obj[1].handle);
-	close(fd);
+	drm_close_driver(fd);
 
 	return (void *) from_user_pointer(ret);
 }
@@ -1747,6 +1747,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_spin_batch.c +1 -1
index cd828beb2..18873be16 100644
@@ -354,6 +354,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_streaming_writes.c +1 -1
index 2c59c08f6..fc2d3d89f 100644
@@ -448,5 +448,5 @@ igt_main
 		test_batch(fd, 2, 1);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_stress.c +1 -1
index 625b0e915..bf2e06d71 100644
@@ -933,7 +933,7 @@ igt_simple_main_args("ds:g:c:t:rbuxmo:fp:",
 	intel_bb_destroy(ibb);
 	buf_ops_destroy(bops);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 
 	igt_stop_signal_helper();
 }
tests/i915/gem_sync.c +1 -1
index 1ee5b3f3d..f98d4364c 100644
@@ -1606,6 +1606,6 @@ igt_main
 		intel_allocator_multiprocess_stop();
 		igt_stop_hang_detector();
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_blits.c +1 -1
index 8c3951c6f..22ac3280d 100644
@@ -232,6 +232,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_fence_blits.c +1 -1
index 539601e5a..5444dcfb8 100644
@@ -335,5 +335,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_partial_pwrite_pread.c +1 -1
index a7e845e32..d4f66d51e 100644
@@ -330,6 +330,6 @@ igt_main
 		intel_buf_destroy(tiled_staging_buf);
 		buf_ops_destroy(bops);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_pread_basic.c +1 -1
index ddf9f0f56..a2253b51e 100644
@@ -230,5 +230,5 @@ igt_simple_main
 		}
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_pread_pwrite.c +1 -1
index 3331e61ad..2f0f6f547 100644
@@ -162,5 +162,5 @@ igt_simple_main
 		gem_madvise(fd, handle, I915_MADV_DONTNEED);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_swapping.c +1 -1
index fb633ecab..90ce70bdb 100644
@@ -256,5 +256,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_wb.c +1 -1
index 7f1afbc90..6a8b79ecc 100644
@@ -249,5 +249,5 @@ igt_simple_main
 		munmap(linear, last_page - first_page);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_wc.c +1 -1
index dc4e4d2d7..1994453b3 100644
@@ -250,5 +250,5 @@ igt_simple_main
 		munmap(linear, last_page - first_page);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiling_max_stride.c +1 -1
index 6001f72be..5943ed93f 100644
@@ -146,5 +146,5 @@ igt_simple_main
 
 	munmap(ptr, size);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_unfence_active_buffers.c +1 -1
index 1f25a81b1..d3bc1cee6 100644
@@ -107,5 +107,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
-	close(i915);
+	drm_close_driver(i915);
 }
tests/i915/gem_unref_active_buffers.c +1 -1
index badded1f7..47023a3a0 100644
@@ -133,5 +133,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
-	close(i915);
+	drm_close_driver(i915);
 }
tests/i915/gem_userptr_blits.c +3 -3
index 4f9b854cc..14f833232 100644
@@ -1086,7 +1086,7 @@ static void test_nohangcheck_hostile(int i915)
 	close(fence);
 
 	close(dir);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 static size_t hugepagesize(void)
@@ -1644,9 +1644,9 @@ static int test_dmabuf(void)
 
 	/* destroy userptr object and expect SIGBUS */
 	free_userptr_bo(fd1, handle);
-	close(fd1);
+	drm_close_driver(fd1);
 
-	close(fd2);
+	drm_close_driver(fd2);
 	reset_handle_ptr();
 
 	return 0;
tests/i915/gem_vm_create.c +2 -2
index f24aefdae..8834c987f 100644
@@ -370,7 +370,7 @@ static void isolation(int i915)
 	gem_read(i915, obj[0].handle, 0, &result, sizeof(result));
 	igt_assert_eq(result, 1);
 
-	close(other);
+	drm_close_driver(other);
 
 	gem_close(i915, obj[1].handle);
 	gem_close(i915, obj[0].handle);
@@ -411,6 +411,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_wait.c +1 -1
index c1cd37e63..674deb57d 100644
@@ -336,6 +336,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_watchdog.c +1 -1
index 640a8cad8..1e4c35021 100644
@@ -597,6 +597,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_workarounds.c +1 -1
index da8cfa011..c5ca26c08 100644
@@ -305,7 +305,7 @@ static void check_workarounds(int fd, enum operation op, unsigned int flags)
 	if (flags & CONTEXT)
 		intel_ctx_destroy(fd, ctx);
 	if (flags & FD)
-		close(fd);
+		drm_close_driver(fd);
 }
 
 igt_main
tests/i915/gen7_exec_parse.c +2 -2
index 81a5bb14f..807cb1e9d 100644
@@ -476,7 +476,7 @@ static void hsw_load_register_reg(void)
 				   0xabcdabc0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -748,6 +748,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(fd, handle);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gen9_exec_parse.c +1 -1
index a927bfaca..33ff6bcb5 100644
@@ -1299,6 +1299,6 @@ igt_main
 		igt_stop_hang_detector();
 		gem_close(i915, handle);
 
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_fb_tiling.c +1 -1
index 586950266..14c17b030 100644
@@ -52,5 +52,5 @@ igt_simple_main
 	igt_assert_eq(ret, -EBUSY);
 
 	igt_remove_fb(drm_fd, &fb);
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
tests/i915/i915_getparams_basic.c +1 -1
index 74ccaf4d3..b22ab5d93 100644
@@ -62,7 +62,7 @@ init(void)
 static void
 deinit(void)
 {
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 
tests/i915/i915_hangman.c +2 -2
index fc46bd297..dcd34cd0e 100644
@@ -160,7 +160,7 @@ static void check_alive(void)
 	put_ahnd(ahnd);
 	intel_ctx_destroy(fd, ctx);
 	gem_quiescent_gpu(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static bool has_error_state(int dir)
@@ -643,6 +643,6 @@ igt_main
 
 		igt_disallow_hang(device, hang);
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/i915_hwmon.c +1 -1
index 279f6821b..48ed9f3b7 100644
@@ -96,6 +96,6 @@ igt_main
 
 	igt_fixture {
 		close(hwm);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_module_load.c +4 -4
index df24aee5e..9fffe93d9 100644
@@ -280,7 +280,7 @@ static void gem_sanitycheck(void)
 		store_all(i915);
 	errno = 0;
 
-	close(i915);
+	drm_close_driver(i915);
 	igt_assert_eq(err, expected);
 }
 
@@ -328,7 +328,7 @@ static void load_and_check_i915(void)
 
 	/* make sure the GPU is idle */
 	gem_quiescent_gpu(drm_fd);
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 
 	/* make sure we can do basic memory ops */
 	gem_sanitycheck();
@@ -369,7 +369,7 @@ static uint32_t  driver_load_with_lmem_bar_size(uint32_t lmem_bar_size, bool che
 		}
 	}
 
-	close(i915);
+	drm_close_driver(i915);
 
 	return lmem_bar_size;
 }
@@ -461,7 +461,7 @@ igt_main
 			igt_require_gem(i915);
 			igt_require(gem_has_lmem(i915));
 			igt_skip_on_f(igt_sysfs_get_num_gt(i915) > 1, "Skips for more than one lmem instance.\n");
-			close(i915);
+			drm_close_driver(i915);
 		}
 
 		/* Test for lmem_bar_size modparam support */
tests/i915/i915_pciid.c +1 -1
index c44be56dc..8322bd564 100644
@@ -77,5 +77,5 @@ igt_simple_main
 
 	igt_assert(has_known_intel_chipset(intel));
 
-	close(intel);
+	drm_close_driver(intel);
 }
tests/i915/i915_pm_backlight.c +1 -1
index b633387bc..3c73b054b 100644
@@ -357,6 +357,6 @@ igt_main
 
 		igt_display_fini(&display);
 		igt_pm_restore_sata_link_power_management();
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/i915/i915_pm_dc.c +1 -1
index 2bb07ba8b..5069ddcc3 100644
@@ -730,7 +730,7 @@ igt_main
 		close(data.debugfs_root_fd);
 		close(data.msr_fd);
 		display_fini(&data);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 
 	igt_exit();
tests/i915/i915_pm_freq_api.c +1 -1
index 522abee35..f6076e531 100644
@@ -139,7 +139,7 @@ static void restore_sysfs_freq(int sig)
 	}
 	free(stash_min);
 	free(stash_max);
-	close(i915);
+	drm_close_driver(i915);
 }
 
 igt_main
tests/i915/i915_pm_freq_mult.c +1 -1
index d75ec3f9e..af62bbc2c 100644
@@ -177,6 +177,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_lpsp.c +1 -1
index cb01a6d9e..291e56674 100644
@@ -223,6 +223,6 @@ igt_main
 	igt_fixture {
 		free(data.pwr_dmn_info);
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/i915/i915_pm_rc6_residency.c +1 -1
index ce81e668a..b266680ac 100644
@@ -627,6 +627,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_rps.c +1 -1
index 238d39240..7044fcd81 100644
@@ -917,7 +917,7 @@ static void pm_rps_exit_handler(int sig)
 	if (lh.igt_proc.running)
 		load_helper_stop();
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 igt_main
tests/i915/i915_pm_sseu.c +1 -1
index 39eecb8fe..cee29a7c5 100644
@@ -323,7 +323,7 @@ gem_deinit(void)
 	case 2:
 		buf_ops_destroy(gem.bops);
 	case 1:
-		close(gem.drm_fd);
+		drm_close_driver(gem.drm_fd);
 	}
 }
 
tests/i915/i915_power.c +1 -1
index 3675b9d6d..ed7bef495 100644
@@ -86,6 +86,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_query.c +1 -1
index 194f2e91b..f97379b83 100644
@@ -1572,6 +1572,6 @@ igt_main
 		query_parse_and_validate_hwconfig_table(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_suspend.c +3 -3
index 9f0a4d2ac..851e797c2 100644
@@ -256,7 +256,7 @@ test_shrink(int fd, unsigned int mode)
 		igt_system_suspend_autoresume(mode, SUSPEND_TEST_NONE);
 
 		munmap(mem, size);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_waitchildren();
@@ -300,7 +300,7 @@ test_suspend_without_i915(int state)
 		igt_pm_get_d3cold_allowed(&card, d3cold_allowed);
 		igt_pm_set_d3cold_allowed(&card, "0\n");
 	}
-	close(fd);
+	drm_close_driver(fd);
 
 	igt_kmsg(KMSG_INFO "Unloading i915\n");
 	igt_assert_eq(igt_i915_driver_unload(),0);
@@ -383,5 +383,5 @@ igt_main
 		test_forcewake(fd, true);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/perf.c +3 -3
index 069ab8c02..3565d61cc 100644
@@ -4704,7 +4704,7 @@ gen12_test_single_ctx_render_target_writes_a_counter(const struct intel_executio
 			igt_drop_root();
 			gen12_single_ctx_helper(e);
 
-			close(drm_fd);
+			drm_close_driver(drm_fd);
 		}
 		child_ret = igt_wait_helper(&child);
 		igt_assert(WEXITSTATUS(child_ret) == EAGAIN ||
@@ -5485,7 +5485,7 @@ test_i915_ref_count(void)
 	igt_debug("ref count after opening i915 perf stream = %u\n", ref_count1);
 	igt_assert(ref_count1 > ref_count0);
 
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 	close(sysfs);
 	drm_fd = -1;
 	sysfs = -1;
@@ -6194,6 +6194,6 @@ igt_main
 			put_engine_groups(perf_oa_groups, num_perf_oa_groups);
 
 		intel_ctx_destroy(drm_fd, ctx);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 	}
 }
tests/i915/perf_pmu.c +3 -3
index 8b31df7b2..0806a8e54 100644
@@ -2424,7 +2424,7 @@ static void test_unload(unsigned int num_engines)
 		if (fd[count] != -1)
 			count++;
 
-		close(i915);
+		drm_close_driver(i915);
 
 		buf = calloc(count, sizeof(uint64_t));
 		igt_assert(buf);
@@ -2768,13 +2768,13 @@ igt_main
 
 		igt_fixture {
 			intel_ctx_destroy(render_fd, render_ctx);
-			close(render_fd);
+			drm_close_driver(render_fd);
 		}
 	}
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("module-unload") {
tests/i915/sysfs_defaults.c +1 -1
index 066532f0a..b686c19fc 100644
@@ -116,6 +116,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_heartbeat_interval.c +1 -1
index a3de43a37..22c5888c6 100644
@@ -543,6 +543,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_preempt_timeout.c +1 -1
index 3d24bf61c..964b78ae8 100644
@@ -362,6 +362,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_timeslice_duration.c +1 -1
index f1b518264..fc2b14e16 100644
@@ -587,6 +587,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
Signature · 1 line
2.40.0
#35 lore raw

PATCH v4 22/24 tests/xe/xe_debugfs: Use xe_config() helper to get the config

In reply to Bhanuprakash Modem

Use xe_config() helper to get the config.

---
 tests/xe/xe_debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/xe/xe_debugfs.c +1 -1
index c404da258..bbd821f8c 100644
@@ -253,7 +253,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 	}
 
 	igt_subtest("base") {
-		test_base(fd, xe_dev->config);
+		test_base(fd, xe_config(fd));
 	}
 
 
Signature · 1 line
2.40.0
Reviewed-by on v4 22/24
#36 lore raw

Re: [igt-dev] [V4 i-g-t 22/24] tests/xe/xe_debugfs: Use xe_config() helper to get the config

Hi Bhanuprakash,

could you move it up in series just after 3/24? [i-g-t 03/24] lib/xe/xe_query: Add xe_config() interface

with that:

Regards,
Kamil

Quoted 23 lines · Bhanuprakash Modem

Use xe_config() helper to get the config.

---
 tests/xe/xe_debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/xe/xe_debugfs.c +1 -1
index c404da258..bbd821f8c 100644
@@ -253,7 +253,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 	}
 
 	igt_subtest("base") {
-		test_base(fd, xe_dev->config);
+		test_base(fd, xe_config(fd));
 	}
 
 
Signature · 1 line
2.40.0
#37 lore raw

PATCH v4 23/24 tests: Drop xe_device get/put from test level

In reply to Bhanuprakash Modem

As xe_device get/put is already handled at driver open/close level, drop these checks from tests.

V2: - New patch for xe_config()
V3: - Fix xe_spin_batch.c

---
 tests/kms_3d.c                  |  6 ------
 tests/kms_addfb_basic.c         |  9 +--------
 tests/kms_flip.c                |  9 +--------
 tests/kms_flip_event_leak.c     |  4 ----
 tests/kms_getfb.c               | 15 +--------------
 tests/kms_hdmi_inject.c         |  7 -------
 tests/kms_setmode.c             |  7 -------
 tests/xe/xe_compute.c           |  8 ++------
 tests/xe/xe_create.c            |  9 ++-------
 tests/xe/xe_debugfs.c           |  6 +-----
 tests/xe/xe_dma_buf_sync.c      | 11 ++---------
 tests/xe/xe_evict.c             |  5 -----
 tests/xe/xe_exec_balancer.c     |  8 ++------
 tests/xe/xe_exec_basic.c        |  8 ++------
 tests/xe/xe_exec_compute_mode.c |  8 ++------
 tests/xe/xe_exec_fault_mode.c   |  5 +----
 tests/xe/xe_exec_reset.c        | 23 +++++------------------
 tests/xe/xe_exec_threads.c      | 20 ++++----------------
 tests/xe/xe_gpgpu_fill.c        |  3 ---
 tests/xe/xe_guc_pc.c            |  2 --
 tests/xe/xe_huc_copy.c          |  8 ++------
 tests/xe/xe_intel_bb.c          |  2 --
 tests/xe/xe_mmap.c              |  8 ++------
 tests/xe/xe_mmio.c              |  8 ++------
 tests/xe/xe_noexec_ping_pong.c  |  2 --
 tests/xe/xe_pm.c                |  3 ---
 tests/xe/xe_prime_self_import.c | 31 +------------------------------
 tests/xe/xe_query.c             |  8 ++------
 tests/xe/xe_spin_batch.c        |  8 ++------
 tests/xe/xe_vm.c                |  5 +----
 tests/xe/xe_waitfence.c         |  8 ++------
 31 files changed, 40 insertions(+), 224 deletions(-)
tests/kms_3d.c +0 -6
index 55e1d8058..c7a9d42d2 100644
@@ -37,9 +37,6 @@ igt_simple_main
 
 	drm_fd = drm_open_driver_master(DRIVER_ANY);
 
-	if (is_xe_device(drm_fd))
-		xe_device_get(drm_fd);
-
 	res = drmModeGetResources(drm_fd);
 	igt_require(res);
 
@@ -116,8 +113,5 @@ igt_simple_main
 
 	drmModeFreeConnector(connector);
 
-	if (is_xe_device(drm_fd))
-		xe_device_put(drm_fd);
-
 	drm_close_driver(drm_fd);
 }
tests/kms_addfb_basic.c +1 -8
index 53a6a007a..065f21975 100644
@@ -974,9 +974,6 @@ igt_main
 	igt_fixture {
 		fd = drm_open_driver_master(DRIVER_ANY);
 		igt_require(has_addfb2_iface(fd));
-
-		if (is_xe_device(fd))
-			xe_device_get(fd);
 	}
 
 	invalid_tests(fd);
@@ -1008,10 +1005,6 @@ igt_main
 			igt_display_fini(&display);
 	}
 
-	igt_fixture {
-		if (is_xe_device(fd))
-			xe_device_put(fd);
-
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/kms_flip.c +1 -8
index efff06e1c..d57990240 100755
@@ -1858,9 +1858,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 		igt_install_exit_handler(kms_flip_exit_handler);
 		get_timestamp_format();
 
-		if (is_xe_device(drm_fd))
-			xe_device_get(drm_fd);
-
 		if (is_i915_device(drm_fd)) {
 			bops = buf_ops_create(drm_fd);
 		}
@@ -1926,10 +1923,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 	}
 	igt_stop_signal_helper();
 
-	igt_fixture {
-		if (is_xe_device(drm_fd))
-			xe_device_put(drm_fd);
-
+	igt_fixture
 		drm_close_driver(drm_fd);
-	}
 }
tests/kms_flip_event_leak.c +0 -4
index 7e46f5ec0..423ce40df 100644
@@ -65,8 +65,6 @@ static void test(data_t *data, enum pipe pipe, igt_output_t *output)
 	igt_device_drop_master(data->drm_fd);
 
 	igt_device_set_master(fd);
-	if (is_xe_device(fd))
-		xe_device_get(fd);
 
 	igt_create_fb(fd, mode->hdisplay, mode->vdisplay,
 		      DRM_FORMAT_XRGB8888,
@@ -77,8 +75,6 @@ static void test(data_t *data, enum pipe pipe, igt_output_t *output)
 			      data);
 	igt_assert_eq(ret, 0);
 
-	if (is_xe_device(fd))
-		xe_device_put(fd);
 	ret = drm_close_driver(fd);
 	igt_assert_eq(ret, 0);
 
tests/kms_getfb.c +1 -14
index 46cad39bd..afcf07fe8 100644
@@ -404,9 +404,6 @@ static void test_handle_protection(void) {
 	igt_fixture {
 		non_master_fd = drm_open_driver(DRIVER_ANY);
 
-		if (is_xe_device(non_master_fd))
-			xe_device_get(non_master_fd);
-
 		non_master_add.width = 1024;
 		non_master_add.height = 1024;
 		non_master_add.pixel_format = DRM_FORMAT_XRGB8888;
@@ -454,9 +451,6 @@ static void test_handle_protection(void) {
 		do_ioctl(non_master_fd, DRM_IOCTL_MODE_RMFB, &non_master_add.fb_id);
 		gem_close(non_master_fd, non_master_add.handles[0]);
 
-		if (is_xe_device(non_master_fd))
-			xe_device_get(non_master_fd);
-
 		drm_close_driver(non_master_fd);
 	}
 }
@@ -468,9 +462,6 @@ igt_main
 	igt_fixture {
 		fd = drm_open_driver_master(DRIVER_ANY);
 		igt_require(has_getfb_iface(fd));
-
-		if (is_xe_device(fd))
-			xe_device_get(fd);
 	}
 
 	igt_subtest_group
@@ -485,10 +476,6 @@ igt_main
 	igt_subtest_group
 		test_handle_protection();
 
-	igt_fixture {
-		if (is_xe_device(fd))
-			xe_device_put(fd);
-
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/kms_hdmi_inject.c +0 -7
index e3db34502..9aa5c59fc 100644
@@ -206,9 +206,6 @@ igt_main
 		igt_require(connector);
 
 		kmstest_unset_all_crtcs(drm_fd, res);
-
-		if (is_xe_device(drm_fd))
-			xe_device_get(drm_fd);
 	}
 
 	igt_describe("Make sure that 4K modes exposed by DRM match the "
@@ -223,10 +220,6 @@ igt_main
 
 	igt_fixture {
 		drmModeFreeConnector(connector);
-
-		if (is_xe_device(drm_fd))
-			xe_device_put(drm_fd);
-
 		drm_close_driver(drm_fd);
 	}
 }
tests/kms_setmode.c +0 -7
index a85f4eaf2..035bbd0b0 100644
@@ -955,9 +955,6 @@ igt_main_args("det:", NULL, help_str, opt_handler, NULL)
 
 		drm_resources = drmModeGetResources(drm_fd);
 		igt_require(drm_resources);
-
-		if (is_xe_device(drm_fd))
-			xe_device_get(drm_fd);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
@@ -974,10 +971,6 @@ igt_main_args("det:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		drmModeFreeResources(drm_resources);
-
-		if (is_xe_device(drm_fd))
-			xe_device_put(drm_fd);
-
 		drm_close_driver(drm_fd);
 	}
 }
tests/xe/xe_compute.c +2 -6
index 1bb4e9821..2cf536701 100644
@@ -36,16 +36,12 @@ igt_main
 {
 	int xe;
 
-	igt_fixture {
+	igt_fixture
 		xe = drm_open_driver(DRIVER_XE);
-		xe_device_get(xe);
-	}
 
 	igt_subtest("compute-square")
 		test_compute_square(xe);
 
-	igt_fixture {
-		xe_device_put(xe);
+	igt_fixture
 		drm_close_driver(xe);
-	}
 }
tests/xe/xe_create.c +2 -7
index 744f2c799..f893381d9 100644
@@ -209,10 +209,8 @@ igt_main
 {
 	int xe;
 
-	igt_fixture {
+	igt_fixture
 		xe = drm_open_driver(DRIVER_XE);
-		xe_device_get(xe);
-	}
 
 	igt_subtest("create-invalid-size") {
 		create_invalid_size(xe);
@@ -228,9 +226,6 @@ igt_main
 		create_massive_size(xe);
 	}
 
-
-	igt_fixture {
-		xe_device_put(xe);
+	igt_fixture
 		drm_close_driver(xe);
-	}
 }
tests/xe/xe_debugfs.c +1 -5
index bbd821f8c..5e16a71a0 100644
@@ -241,14 +241,12 @@ static int opt_handler(int option, int option_index, void *input)
 
 igt_main_args("", long_options, help_str, opt_handler, NULL)
 {
-	struct xe_device *xe_dev;
 	char devnode[PATH_MAX];
 	int fd;
 	int gt;
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_dev = xe_device_get(fd);
 		__igt_debugfs_dump(fd, "info", IGT_LOG_INFO);
 	}
 
@@ -269,8 +267,6 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 		test_forcewake(fd);
 	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_dma_buf_sync.c +2 -9
index d6342746a..c08f8ac18 100644
@@ -112,7 +112,6 @@ test_export_dma_buf(struct drm_xe_engine_class_instance *hwe0,
 
 	for (i = 0; i < N_FD; ++i) {
 		fd[i] = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd[0]);
 		vm[i] = xe_vm_create(fd[i], 0, 0);
 		engine[i] = xe_engine_create(fd[i], vm[i], !i ? hwe0 : hwe1, 0);
 	}
@@ -217,11 +216,8 @@ test_export_dma_buf(struct drm_xe_engine_class_instance *hwe0,
 		close(dma_buf_fd[i]);
 	}
 
-	for (i = 0; i < N_FD; ++i) {
-		xe_device_put(fd[i]);
+	for (i = 0; i < N_FD; ++i)
 		drm_close_driver(fd[i]);
-	}
-
 }
 
 igt_main
@@ -231,7 +227,6 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 
 		xe_for_each_hw_engine(fd, hwe)
 			if (hwe0 == NULL) {
@@ -254,8 +249,6 @@ igt_main
 	igt_subtest("export-dma-buf-many-read-sync")
 		test_export_dma_buf(hwe0, hwe1, 16, READ_SYNC);
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_evict.c +0 -5
index 21cf27dc0..1a596766b 100644
@@ -62,7 +62,6 @@ test_evict(int fd, struct drm_xe_engine_class_instance *eci,
 	igt_assert(bo);
 
 	fd = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd);
 
 	vm = xe_vm_create(fd, DRM_XE_VM_CREATE_ASYNC_BIND_OPS, 0);
 	if (flags & BIND_ENGINE)
@@ -200,7 +199,6 @@ test_evict(int fd, struct drm_xe_engine_class_instance *eci,
 		xe_vm_destroy(fd, vm2);
 		xe_vm_destroy(fd, vm3);
 	}
-	xe_device_put(fd);
 	drm_close_driver(fd);
 }
 
@@ -239,7 +237,6 @@ test_evict_cm(int fd, struct drm_xe_engine_class_instance *eci,
 	igt_assert(bo);
 
 	fd = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd);
 
 	vm = xe_vm_create(fd, DRM_XE_VM_CREATE_ASYNC_BIND_OPS |
 			  DRM_XE_VM_CREATE_COMPUTE_MODE, 0);
@@ -368,7 +365,6 @@ test_evict_cm(int fd, struct drm_xe_engine_class_instance *eci,
 	xe_vm_destroy(fd, vm);
 	if (flags & MULTI_VM)
 		xe_vm_destroy(fd, vm2);
-	xe_device_put(fd);
 	drm_close_driver(fd);
 }
 
@@ -667,7 +663,6 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 		igt_require(xe_has_vram(fd));
 		vram_size = xe_vram_size(fd, 0);
 		igt_assert(vram_size);
tests/xe/xe_exec_balancer.c +2 -6
index e5fe1ea2a..928a26297 100644
@@ -619,10 +619,8 @@ igt_main
 	int class;
 	int fd;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	igt_subtest("virtual-all-active")
 		xe_for_each_gt(fd, gt)
@@ -699,8 +697,6 @@ igt_main
 					test_cm(fd, gt, class, 1, 0, s->flags);
 	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_exec_basic.c +2 -6
index 9aeb861aa..af581c327 100644
@@ -308,10 +308,8 @@ igt_main
 	};
 	int fd;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	for (const struct section *s = sections; s->name; s++) {
 		igt_subtest_f("once-%s", s->name)
@@ -348,8 +346,6 @@ igt_main
 				test_exec(fd, hwe, 1, 0, 1, s->flags);
 	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_exec_compute_mode.c +2 -6
index 966aae566..4edcc4abe 100644
@@ -332,10 +332,8 @@ igt_main
 	};
 	int fd;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	for (const struct section *s = sections; s->name; s++) {
 		igt_subtest_f("once-%s", s->name)
@@ -364,8 +362,6 @@ igt_main
 					  s->flags);
 	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_exec_fault_mode.c +1 -4
index 566a5981f..9b43c6d1b 100644
@@ -516,7 +516,6 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 		igt_require(xe_supports_faults(fd));
 	}
 
@@ -560,8 +559,6 @@ igt_main
 		xe_for_each_hw_engine(fd, hwe)
 			test_atomic(fd, hwe, 8, WAIT_ATOMIC);
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_exec_reset.c +5 -18
index 8699ad26b..75c1c4487 100644
@@ -170,10 +170,8 @@ test_balancer(int fd, int gt, int class, int n_engines, int n_execs,
 
 	igt_assert(n_engines <= MAX_N_ENGINES);
 
-	if (flags & CLOSE_FD) {
+	if (flags & CLOSE_FD)
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	xe_for_each_hw_engine(fd, hwe) {
 		if (hwe->engine_class != class || hwe->gt_id != gt)
@@ -285,7 +283,6 @@ test_balancer(int fd, int gt, int class, int n_engines, int n_execs,
 			for (i = 0; i < n_engines; i++)
 				xe_engine_destroy(fd, engines[i]);
 		}
-		xe_device_put(fd);
 		drm_close_driver(fd);
 		/* FIXME: wait for idle */
 		usleep(150000);
@@ -374,10 +371,8 @@ test_legacy_mode(int fd, struct drm_xe_engine_class_instance *eci,
 
 	igt_assert(n_engines <= MAX_N_ENGINES);
 
-	if (flags & CLOSE_FD) {
+	if (flags & CLOSE_FD)
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	vm = xe_vm_create(fd, DRM_XE_VM_CREATE_ASYNC_BIND_OPS, 0);
 	bo_size = sizeof(*data) * n_execs;
@@ -460,7 +455,6 @@ test_legacy_mode(int fd, struct drm_xe_engine_class_instance *eci,
 			for (i = 0; i < n_engines; i++)
 				xe_engine_destroy(fd, engines[i]);
 		}
-		xe_device_put(fd);
 		drm_close_driver(fd);
 		/* FIXME: wait for idle */
 		usleep(150000);
@@ -547,10 +541,8 @@ test_compute_mode(int fd, struct drm_xe_engine_class_instance *eci,
 
 	igt_assert(n_engines <= MAX_N_ENGINES);
 
-	if (flags & CLOSE_FD) {
+	if (flags & CLOSE_FD)
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	vm = xe_vm_create(fd, DRM_XE_VM_CREATE_ASYNC_BIND_OPS |
 			  DRM_XE_VM_CREATE_COMPUTE_MODE, 0);
@@ -635,7 +627,6 @@ test_compute_mode(int fd, struct drm_xe_engine_class_instance *eci,
 			for (i = 0; i < n_engines; i++)
 				xe_engine_destroy(fd, engines[i]);
 		}
-		xe_device_put(fd);
 		drm_close_driver(fd);
 		/* FIXME: wait for idle */
 		usleep(150000);
@@ -812,10 +803,8 @@ igt_main
 	int class;
 	int fd;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	igt_subtest("spin")
 		xe_for_each_hw_engine(fd, hwe)
@@ -925,8 +914,6 @@ igt_main
 	igt_subtest("gt-reset-stress")
 		gt_reset(fd, 4, 1);
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_exec_threads.c +4 -16
index f34f33b94..2d6b67f6d 100644
@@ -73,7 +73,6 @@ test_balancer(int fd, int gt, uint32_t vm, uint64_t addr, uint64_t userptr,
 
 	if (!fd) {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 		owns_fd = true;
 	}
 
@@ -243,10 +242,8 @@ test_balancer(int fd, int gt, uint32_t vm, uint64_t addr, uint64_t userptr,
 	}
 	if (owns_vm)
 		xe_vm_destroy(fd, vm);
-	if (owns_fd) {
-		xe_device_put(fd);
+	if (owns_fd)
 		drm_close_driver(fd);
-	}
 }
 
 static void
@@ -283,7 +280,6 @@ test_compute_mode(int fd, uint32_t vm, uint64_t addr, uint64_t userptr,
 
 	if (!fd) {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 		owns_fd = true;
 	}
 
@@ -458,7 +454,6 @@ test_compute_mode(int fd, uint32_t vm, uint64_t addr, uint64_t userptr,
 	if (owns_vm)
 		xe_vm_destroy(fd, vm);
 	if (owns_fd) {
-		xe_device_put(fd);
 		drm_close_driver(fd);
 	}
 }
@@ -496,7 +491,6 @@ test_legacy_mode(int fd, uint32_t vm, uint64_t addr, uint64_t userptr,
 
 	if (!fd) {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 		owns_fd = true;
 	}
 
@@ -701,10 +695,8 @@ test_legacy_mode(int fd, uint32_t vm, uint64_t addr, uint64_t userptr,
 	}
 	if (owns_vm)
 		xe_vm_destroy(fd, vm);
-	if (owns_fd) {
-		xe_device_put(fd);
+	if (owns_fd)
 		drm_close_driver(fd);
-	}
 }
 
 struct thread_data {
@@ -1395,18 +1387,14 @@ igt_main
 	};
 	int fd;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	for (const struct section *s = sections; s->name; s++) {
 		igt_subtest_f("threads-%s", s->name)
 			threads(fd, s->flags);
 	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_gpgpu_fill.c +0 -3
index 12bf7c5fc..4da01ee8c 100644
@@ -120,8 +120,6 @@ igt_main
 
 		fill_fn = igt_get_gpgpu_fillfunc(data.devid);
 		igt_require_f(fill_fn, "no gpgpu-fill function\n");
-
-		xe_device_get(data.drm_fd);
 	}
 
 	igt_subtest("basic") {
@@ -129,7 +127,6 @@ igt_main
 	}
 
 	igt_fixture {
-		xe_device_put(data.drm_fd);
 		buf_ops_destroy(data.bops);
 		drm_close_driver(data.drm_fd);
 	}
tests/xe/xe_guc_pc.c +0 -2
index 3e2e44d99..827693eb4 100644
@@ -381,7 +381,6 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 
 		sysfs = igt_sysfs_open(fd);
 		igt_assert(sysfs != -1);
@@ -489,7 +488,6 @@ igt_main
 			set_freq(sysfs, gt, "max", stash_max);
 		}
 		close(sysfs);
-		xe_device_put(fd);
 		drm_close_driver(fd);
 	}
 }
tests/xe/xe_huc_copy.c +2 -6
index ccdfe8622..d4377f9a1 100644
@@ -176,10 +176,8 @@ igt_main
 {
 	int xe;
 
-	igt_fixture {
+	igt_fixture
 		xe = drm_open_driver(DRIVER_XE);
-		xe_device_get(xe);
-	}
 
 	igt_subtest("huc_copy") {
 		/*
@@ -190,8 +188,6 @@ igt_main
 		test_huc_copy(xe);
 	}
 
-	igt_fixture {
-		xe_device_put(xe);
+	igt_fixture
 		drm_close_driver(xe);
-	}
 }
tests/xe/xe_intel_bb.c +0 -2
index 5b22b967b..539f44a0f 100644
@@ -1069,7 +1069,6 @@ igt_main_args("dpib", NULL, help_str, opt_handler, NULL)
 	igt_fixture {
 		xe = drm_open_driver(DRIVER_XE);
 		bops = buf_ops_create(xe);
-		xe_device_get(xe);
 	}
 
 	igt_describe("Ensure reset is possible on fresh bb");
@@ -1141,7 +1140,6 @@ igt_main_args("dpib", NULL, help_str, opt_handler, NULL)
 	}
 
 	igt_fixture {
-		xe_device_put(xe);
 		buf_ops_destroy(bops);
 		drm_close_driver(xe);
 	}
tests/xe/xe_mmap.c +2 -6
index 1cc55cf3c..664ed54fc 100644
@@ -115,10 +115,8 @@ igt_main
 {
 	int fd;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	igt_subtest("system")
 		test_mmap(fd, system_memory(fd));
@@ -138,8 +136,6 @@ igt_main
 	igt_subtest("bad-object")
 		test_bad_object(fd);
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_mmio.c +2 -6
index b8f0596ce..02e79d7e4 100644
@@ -78,18 +78,14 @@ igt_main
 {
 	int fd;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	igt_subtest("mmio-timestamp")
 		test_xe_mmio_timestamp(fd);
 	igt_subtest("mmio-invalid")
 		test_xe_mmio_invalid(fd);
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_noexec_ping_pong.c +0 -2
index ee0e33e6b..49cf11fa6 100644
@@ -99,10 +99,8 @@ igt_simple_main
 {
 
 	fd = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd);
 
 	test_ping_pong(fd, xe_hw_engine(fd, 0));
 
-	xe_device_put(fd);
 	drm_close_driver(fd);
 }
tests/xe/xe_pm.c +0 -3
index 289337cd3..a7f73c4e6 100644
@@ -374,8 +374,6 @@ igt_main
 		device.pci_xe = igt_device_get_pci_device(device.fd_xe);
 		device.pci_root = igt_device_get_pci_root_port(device.fd_xe);
 
-		xe_device_get(device.fd_xe);
-
 		/* Always perform initial once-basic exec checking for health */
 		xe_for_each_hw_engine(device.fd_xe, hwe)
 			test_exec(device, hwe, 1, 1, NO_SUSPEND, NO_RPM);
@@ -444,7 +442,6 @@ igt_main
 	igt_fixture {
 		set_d3cold_allowed(device.pci_xe, d3cold_allowed);
 		igt_restore_runtime_pm();
-		xe_device_put(device.fd_xe);
 		drm_close_driver(device.fd_xe);
 	}
 }
tests/xe/xe_prime_self_import.c +1 -30
index c1065b2e8..0fd79f704 100644
@@ -105,9 +105,7 @@ static void test_with_fd_dup(void)
 	counter = 0;
 
 	fd1 = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd1);
 	fd2 = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd2);
 
 	handle = xe_bo_create(fd1, 0, 0, BO_SIZE);
 
@@ -122,9 +120,7 @@ static void test_with_fd_dup(void)
 	close(dma_buf_fd2);
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	xe_device_put(fd1);
 	drm_close_driver(fd1);
-	xe_device_put(fd2);
 	drm_close_driver(fd2);
 }
 
@@ -143,9 +139,7 @@ static void test_with_two_bos(void)
 	counter = 0;
 
 	fd1 = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd1);
 	fd2 = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd2);
 
 	handle1 = xe_bo_create(fd1, 0, 0, BO_SIZE);
 	handle2 = xe_bo_create(fd1, 0, 0, BO_SIZE);
@@ -165,9 +159,7 @@ static void test_with_two_bos(void)
 
 	check_bo(fd2, handle_import, fd2, handle_import);
 
-	xe_device_put(fd1);
 	drm_close_driver(fd1);
-	xe_device_put(fd2);
 	drm_close_driver(fd2);
 }
 
@@ -184,9 +176,7 @@ static void test_with_one_bo_two_files(void)
 	int dma_buf_fd1, dma_buf_fd2;
 
 	fd1 = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd1);
 	fd2 = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd2);
 
 	handle_orig = xe_bo_create(fd1, 0, 0, BO_SIZE);
 	dma_buf_fd1 = prime_handle_to_fd(fd1, handle_orig);
@@ -200,9 +190,7 @@ static void test_with_one_bo_two_files(void)
 	/* dma-buf self importing an flink bo should give the same handle */
 	igt_assert_eq_u32(handle_import, handle_open);
 
-	xe_device_put(fd1);
 	drm_close_driver(fd1);
-	xe_device_put(fd2);
 	drm_close_driver(fd2);
 	close(dma_buf_fd1);
 	close(dma_buf_fd2);
@@ -221,9 +209,7 @@ static void test_with_one_bo(void)
 	int dma_buf_fd;
 
 	fd1 = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd1);
 	fd2 = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd2);
 
 	handle = xe_bo_create(fd1, 0, 0, BO_SIZE);
 
@@ -257,10 +243,8 @@ static void test_with_one_bo(void)
 	check_bo(fd1, handle, fd2, handle_import1);
 
 	/* Completely rip out exporting fd. */
-	xe_device_put(fd1);
 	drm_close_driver(fd1);
 	check_bo(fd2, handle_import1, fd2, handle_import1);
-	xe_device_put(fd2);
 	drm_close_driver(fd2);
 }
 
@@ -313,7 +297,6 @@ static void *thread_fn_reimport_vs_close(void *p)
 	threads = calloc(num_threads, sizeof(pthread_t));
 
 	fds[0] = drm_open_driver(DRIVER_XE);
-	xe_device_get(fds[0]);
 
 	handle = xe_bo_create(fds[0], 0, 0, BO_SIZE);
 
@@ -333,7 +316,6 @@ static void *thread_fn_reimport_vs_close(void *p)
 	}
 
 	pthread_barrier_destroy(&g_barrier);
-	xe_device_put(fds[0]);
 	drm_close_driver(fds[0]);
 	close(fds[1]);
 
@@ -405,13 +387,11 @@ static void test_export_close_race(void)
 	/* Allocate exit handler fds in here so that we dont screw
 	 * up the counts */
 	fake = drm_open_driver(DRIVER_XE);
-	xe_device_get(fake);
 
 	/* TODO: Read object count */
 	obj_count = 0;
 
 	fd = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd);
 	pthread_barrier_init(&g_barrier, NULL, num_threads);
 
 	for (i = 0; i < num_threads; i++) {
@@ -427,7 +407,6 @@ static void test_export_close_race(void)
 	}
 
 	pthread_barrier_destroy(&g_barrier);
-	xe_device_put(fd);
 	drm_close_driver(fd);
 
 	/* TODO: Read object count */
@@ -435,7 +414,6 @@ static void test_export_close_race(void)
 
 	igt_info("leaked %i objects\n", obj_count);
 
-	xe_device_put(fake);
 	drm_close_driver(fake);
 
 	igt_assert_eq(obj_count, 0);
@@ -456,7 +434,6 @@ static void test_llseek_size(void)
 	counter = 0;
 
 	fd = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd);
 
 	for (i = 0; i < 10; i++) {
 		int bufsz = xe_get_default_alignment(fd) << i;
@@ -471,7 +448,6 @@ static void test_llseek_size(void)
 		close(dma_buf_fd);
 	}
 
-	xe_device_put(fd);
 	drm_close_driver(fd);
 }
 
@@ -490,7 +466,6 @@ static void test_llseek_bad(void)
 	counter = 0;
 
 	fd = drm_open_driver(DRIVER_XE);
-	xe_device_get(fd);
 
 	handle = xe_bo_create(fd, 0, 0, BO_SIZE);
 	dma_buf_fd = prime_handle_to_fd(fd, handle);
@@ -507,7 +482,6 @@ static void test_llseek_bad(void)
 
 	close(dma_buf_fd);
 
-	xe_device_put(fd);
 	drm_close_driver(fd);
 }
 
@@ -531,7 +505,6 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
@@ -539,8 +512,6 @@ igt_main
 			tests[i].fn();
 	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_query.c +2 -6
index 22eeb2b43..beee12ef9 100644
@@ -458,10 +458,8 @@ igt_main
 {
 	int xe;
 
-	igt_fixture {
+	igt_fixture
 		xe = drm_open_driver(DRIVER_XE);
-		xe_device_get(xe);
-	}
 
 	igt_subtest("query-engines")
 		test_query_engines(xe);
@@ -490,8 +488,6 @@ igt_main
 	igt_subtest("query-invalid-extension")
 		test_query_invalid_extension(xe);
 
-	igt_fixture {
-		xe_device_put(xe);
+	igt_fixture
 		drm_close_driver(xe);
-	}
 }
tests/xe/xe_spin_batch.c +2 -6
index 1503b30a9..56581f760 100644
@@ -144,10 +144,8 @@ igt_main
 	int fd;
 	int gt, class;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	igt_subtest("spin-basic")
 		spin_basic(fd);
@@ -165,8 +163,6 @@ igt_main
 				spin_all(fd, gt, class);
 	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_vm.c +1 -4
index 28269c604..ca46531c0 100644
@@ -1638,7 +1638,6 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 
 		xe_for_each_hw_engine(fd, hwe)
 			if (hwe->engine_class != DRM_XE_ENGINE_CLASS_COPY) {
@@ -1854,8 +1853,6 @@ igt_main
 		}
 	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_waitfence.c +2 -6
index d2e422f83..28b218352 100644
@@ -119,10 +119,8 @@ igt_main
 {
 	int fd;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	igt_subtest("reltime")
 		waitfence(fd, RELTIME);
@@ -130,8 +128,6 @@ igt_main
 	igt_subtest("abstime")
 		waitfence(fd, ABSTIME);
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
Signature · 1 line
2.40.0
#38 lore raw

PATCH v4 24/24 Revert "lib/igt_kms: Cache xe_device info for kms tests"

In reply to Bhanuprakash Modem

As this logic is moved to driver open/close level, this is redundant, hence revert this logic.

This reverts commit 3e049d7c5048c8e4d0b0cfc22afca18e9e897e9a.

---
 lib/igt_kms.c | 8 --------
 1 file changed, 8 deletions(-)
lib/igt_kms.c +0 -8
index 5341c6373..f2b0eed57 100644
@@ -59,7 +59,6 @@
 #include "igt_device.h"
 #include "igt_sysfs.h"
 #include "sw_sync.h"
-#include "xe/xe_query.h"
 #ifdef HAVE_CHAMELIUM
 #include "igt_chamelium.h"
 #endif
@@ -2657,9 +2656,6 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 	}
 #endif
 
-	if (is_xe_device(drm_fd))
-		xe_device_get(drm_fd);
-
 	display->n_pipes = IGT_MAX_PIPES;
 	display->pipes = calloc(sizeof(igt_pipe_t), display->n_pipes);
 	igt_assert_f(display->pipes, "Failed to allocate memory for %d pipes\n", display->n_pipes);
@@ -2996,10 +2992,6 @@ static void igt_output_fini(igt_output_t *output)
 void igt_display_fini(igt_display_t *display)
 {
 	int i;
-	int drm_fd = display->drm_fd;
-
-	if (is_xe_device(drm_fd))
-		xe_device_put(drm_fd);
 
 	for (i = 0; i < display->n_planes; ++i) {
 		igt_plane_t *plane = &display->planes[i];
Signature · 1 line
2.40.0