Skip to contentSkip to conversation

XE test cleanup to handle xe_device

PATCH In review Bhanuprakash Modem 4 participants 29 messages May 4, 2023 – May 18, 2023 Library code Page 1 of 2

lore
Share & tools
lore
#0 lore raw

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().

Bhanuprakash Modem (6):
lib: Interface to close the drm fd
lib: Cache xe_device at driver open/close level lib/xe/xe_query: Add xe_config() interface Revert "lib/igt_kms: Cache xe_device info for kms tests"
tests: Use drm_close_driver() to close the drm fd
tests: Drop xe_device get/put from test level

 lib/drmtest.c                               | 26 +++++++++
 lib/drmtest.h                               |  1 +
 lib/igt_kms.c                               |  8 ---
 lib/igt_msm.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                      |  4 +-
 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/drm_read.c                            |  3 +
 tests/dumb_buffer.c                         |  2 +-
 tests/eviction_common.c                     |  2 +-
 tests/fbdev.c                               |  2 +-
 tests/i915/api_intel_allocator.c            |  2 +-
 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               |  3 +
 tests/i915/gem_basic.c                      |  5 +-
 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_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                 |  2 +-
 tests/i915/gem_ctx_engines.c                |  4 +-
 tests/i915/gem_ctx_exec.c                   |  3 +
 tests/i915/gem_ctx_freq.c                   |  3 +
 tests/i915/gem_ctx_param.c                  |  2 +-
 tests/i915/gem_ctx_persistence.c            |  2 +-
 tests/i915/gem_ctx_shared.c                 |  3 +
 tests/i915/gem_ctx_sseu.c                   |  2 +-
 tests/i915/gem_ctx_switch.c                 |  2 +-
 tests/i915/gem_eio.c                        |  3 +
 tests/i915/gem_evict_alignment.c            |  2 +-
 tests/i915/gem_evict_everything.c           |  2 +-
 tests/i915/gem_exec_alignment.c             |  3 +
 tests/i915/gem_exec_async.c                 |  2 +-
 tests/i915/gem_exec_await.c                 |  2 +-
 tests/i915/gem_exec_balancer.c              |  3 +
 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_endless.c               |  3 +
 tests/i915/gem_exec_fair.c                  |  2 +-
 tests/i915/gem_exec_fence.c                 |  2 +-
 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              |  2 +-
 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               |  2 +-
 tests/i915/gem_exercise_blt.c               |  2 +-
 tests/i915/gem_fd_exhaustion.c              |  2 +-
 tests/i915/gem_fence_thrash.c               |  3 +-
 tests/i915/gem_fenced_exec_thrash.c         |  2 +-
 tests/i915/gem_flink_basic.c                |  7 ++-
 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              |  4 +-
 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                   |  2 +-
 tests/i915/gem_mmap_offset.c                |  2 +-
 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                |  2 +-
 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                    |  2 +-
 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              |  7 ++-
 tests/i915/gem_vm_create.c                  |  2 +-
 tests/i915/gem_wait.c                       |  2 +-
 tests/i915/gem_watchdog.c                   |  2 +-
 tests/i915/gem_workarounds.c                |  3 +
 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_rpm.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                   |  4 +-
 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                           |  4 +-
 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_dp_tiled_display.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_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                        | 10 +---
 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                    |  6 +-
 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_vm.c                            |  7 +--
 tests/xe/xe_waitfence.c                     | 10 +---
 294 files changed, 512 insertions(+), 603 deletions(-)

--
2.40.0

#1 lore raw

PATCH 1/6 lib: Interface to close the drm fd

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

---
 lib/drmtest.c | 17 +++++++++++++++++
 lib/drmtest.h |  1 +
 2 files changed, 18 insertions(+)
lib/drmtest.c +17 -0
index c91a91425..03b5239b2 100644
@@ -604,6 +604,23 @@ int drm_open_driver(int chipset)
 	return fd;
 }
 
+/**
+ * drm_close_driver:
+ * @fd: a drm file descriptor
+ *
+ * Close the drm file descriptor @fd.
+ *
+ * Returns: 0 on success or -1 on error.
+ */
+int drm_close_driver(int fd)
+{
+	/* Avoid closing standard file descriptors (0, 1, and 2). */
+	if (fd < 3)
+		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 3c88b85c6..2b7ffc765 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);
 
 void igt_require_amdgpu(int fd);
 void igt_require_intel(int fd);
Signature · 1 line
2.40.0
#2 lore raw

Re: [igt-dev] [i-g-t 1/6] lib: Interface to close the drm fd

Quoted 4 lines · Bhanuprakash Modem

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

Cc Janga Rahul Kumar <[email protected]>
Quoted 45 lines
---
  lib/drmtest.c | 17 +++++++++++++++++
  lib/drmtest.h |  1 +
  2 files changed, 18 insertions(+)
lib/drmtest.c +17 -0
index c91a91425..03b5239b2 100644
@@ -604,6 +604,23 @@ int drm_open_driver(int chipset)
  	return fd;
  }
 
+/**
+ * drm_close_driver:
+ * @fd: a drm file descriptor
+ *
+ * Close the drm file descriptor @fd.
+ *
+ * Returns: 0 on success or -1 on error.
+ */
+int drm_close_driver(int fd)
+{
+	/* Avoid closing standard file descriptors (0, 1, and 2). */
+	if (fd < 3)
+		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 3c88b85c6..2b7ffc765 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);
 
  void igt_require_amdgpu(int fd);
  void igt_require_intel(int fd);
#3 lore raw

Re: [igt-dev] [i-g-t 1/6] lib: Interface to close the drm fd

In reply to Bhanuprakash Modem

Hi Bhanuprakash,

Quoted 1 line · Bhanuprakash Modem

Add new helper drm_close_driver() to close the drm fd. So that

-------------------------------------------------------- ^^^^^^^ s/So that/Now/

Quoted 18 lines

every user could call drm_close_driver() instead of close().

---
 lib/drmtest.c | 17 +++++++++++++++++
 lib/drmtest.h |  1 +
 2 files changed, 18 insertions(+)
lib/drmtest.c +2 -0
index c91a91425..03b5239b2 100644
@@ -604,6 +604,23 @@ int drm_open_driver(int chipset)
 	return fd;
 }
 
+/**
+ * drm_close_driver:

lib/drmtest.c int drm_open_driver(int chipset) · line 618

Quoted 10 lines
lib/drmtest.c +10 -0
+ * @fd: a drm file descriptor
+ *
+ * Close the drm file descriptor @fd.
+ *
+ * Returns: 0 on success or -1 on error.
+ */
+int drm_close_driver(int fd)
+{
+	/* Avoid closing standard file descriptors (0, 1, and 2). */
+	if (fd < 3)

-1 is ok here, if you are concerned about 0...2 imho print debug message here for these.

Quoted 13 lines
lib/drmtest.c +5 -0
+		return -1;
+
+	return close(fd);
+}
+
 /**
  * drm_open_driver_master:
  * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
lib/drmtest.h +0 -0
index 3c88b85c6..2b7ffc765 100644

lib/drmtest.h int drm_open_driver_render(int chipset); · line 108

Quoted 4 lines
lib/drmtest.h +1 -0
@@ -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);

imho this may be __drm_close_driver(int fd) and drm_close_driver could be macro with setting fd to -1 after succesfull close ?

Regards,
Kamil

Quoted 6 lines
lib/drmtest.h +0 -0
 void igt_require_amdgpu(int fd);
 void igt_require_intel(int fd);
Signature · 1 line
2.40.0
#4 lore raw

Re: [igt-dev] [i-g-t 1/6] lib: Interface to close the drm fd

Hi Kamil,

Quoted 23 lines · Kamil Konieczny

Hi Bhanuprakash,

Quoted 1 line · Bhanuprakash Modem

Add new helper drm_close_driver() to close the drm fd. So that

-------------------------------------------------------- ^^^^^^^ s/So that/Now/

Quoted 16 lines

every user could call drm_close_driver() instead of close().

---
  lib/drmtest.c | 17 +++++++++++++++++
  lib/drmtest.h |  1 +
  2 files changed, 18 insertions(+)
lib/drmtest.c +0 -0
index c91a91425..03b5239b2 100644
@@ -604,6 +604,23 @@ int drm_open_driver(int chipset)
  	return fd;
  }
 
Quoted 15 lines

lib/drmtest.c int drm_open_driver(int chipset) · line 618

Quoted 12 lines
lib/drmtest.c +12 -0
+/**
+ * drm_close_driver:
+ * @fd: a drm file descriptor
+ *
+ * Close the drm file descriptor @fd.
+ *
+ * Returns: 0 on success or -1 on error.
+ */
+int drm_close_driver(int fd)
+{
+	/* Avoid closing standard file descriptors (0, 1, and 2). */
+	if (fd < 3)

-1 is ok here, if you are concerned about 0...2 imho print debug message here for these.

Sure, will fix this in next rev.

Quoted 13 lines
Quoted 13 lines
lib/drmtest.c +5 -0
+		return -1;
+
+	return close(fd);
+}
+
  /**
   * drm_open_driver_master:
   * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
lib/drmtest.h +0 -0
index 3c88b85c6..2b7ffc765 100644
Quoted 8 lines

lib/drmtest.h int drm_open_driver_render(int chipset); · line 108

Quoted 5 lines
lib/drmtest.h +1 -0
@@ -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);

imho this may be __drm_close_driver(int fd) and drm_close_driver could be macro with setting fd to -1 after succesfull close ?

Not understood, why do we need to set fd = -1 ?

- Bhanu

Quoted 10 lines

Regards,
Kamil

Quoted 6 lines
lib/drmtest.h +0 -0
  void igt_require_amdgpu(int fd);
  void igt_require_intel(int fd);
Signature · 1 line
2.40.0
#5 lore raw

Re: [igt-dev] [i-g-t 1/6] lib: Interface to close the drm fd

In reply to Bhanuprakash Modem
Quoted 23 lines · Bhanuprakash Modem

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

---
 lib/drmtest.c | 17 +++++++++++++++++
 lib/drmtest.h |  1 +
 2 files changed, 18 insertions(+)
lib/drmtest.c +6 -0
index c91a91425..03b5239b2 100644
@@ -604,6 +604,23 @@ int drm_open_driver(int chipset)
 	return fd;
 }
 
+/**
+ * drm_close_driver:
+ * @fd: a drm file descriptor
+ *
+ * Close the drm file descriptor @fd.
+ *

lib/drmtest.c int drm_open_driver(int chipset) · line 622

Quoted 10 lines
lib/drmtest.c +10 -0
+ * Returns: 0 on success or -1 on error.
+ */
+int drm_close_driver(int fd)
+{
+	/* Avoid closing standard file descriptors (0, 1, and 2). */
+	if (fd < 3)
+		return -1;
+
+	return close(fd);
+}

Drm fd also can be 0-2 if one of it was previously closed so I'm not sure you should check this way. Maybe readlink() or sth else?

--
Zbigniew

Quoted 19 lines
lib/drmtest.c +1 -0
+
 /**
  * drm_open_driver_master:
  * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
lib/drmtest.h +1 -0
index 3c88b85c6..2b7ffc765 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);
 
 void igt_require_amdgpu(int fd);
 void igt_require_intel(int fd);
Signature · 1 line
2.40.0
#6 lore raw

PATCH 2/6 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.

---
 lib/drmtest.c | 9 +++++++++
 1 file changed, 9 insertions(+)
lib/drmtest.c +9 -0
index 03b5239b2..f6cd8e500 100644
@@ -63,6 +63,7 @@
 #include "intel_reg.h"
 #include "ioctl_wrappers.h"
 #include "igt_dummyload.h"
+#include "xe/xe_query.h"
 
 /**
  * SECTION:drmtest
@@ -601,6 +602,10 @@ int drm_open_driver(int chipset)
 		}
 	}
 
+	/* Cache xe_device struct. */
+	if (is_xe_device(fd))
+		xe_device_get(fd);
+
 	return fd;
 }
 
@@ -618,6 +623,10 @@ int drm_close_driver(int fd)
 	if (fd < 3)
 		return -1;
 
+	/* Remove xe_device from cache. */
+	if (is_xe_device(fd))
+		xe_device_put(fd);
+
 	return close(fd);
 }
 
Signature · 1 line
2.40.0
#7 lore raw

Re: [igt-dev] [i-g-t 2/6] lib: Cache xe_device at driver open/close level

Quoted 5 lines · 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.

Cc Janga Rahul Kumar <[email protected]>
Quoted 38 lines
---
  lib/drmtest.c | 9 +++++++++
  1 file changed, 9 insertions(+)
lib/drmtest.c +9 -0
index 03b5239b2..f6cd8e500 100644
@@ -63,6 +63,7 @@
  #include "intel_reg.h"
  #include "ioctl_wrappers.h"
  #include "igt_dummyload.h"
+#include "xe/xe_query.h"
 
  /**
   * SECTION:drmtest
@@ -601,6 +602,10 @@ int drm_open_driver(int chipset)
  		}
  	}
 
+	/* Cache xe_device struct. */
+	if (is_xe_device(fd))
+		xe_device_get(fd);
+
  	return fd;
  }
 
@@ -618,6 +623,10 @@ int drm_close_driver(int fd)
  	if (fd < 3)
  		return -1;
 
+	/* Remove xe_device from cache. */
+	if (is_xe_device(fd))
+		xe_device_put(fd);
+
  	return close(fd);
  }
 
Reviewed-by on v1 2/6
#8 lore raw

Re: [igt-dev] [i-g-t 2/6] lib: Cache xe_device at driver open/close level

In reply to Bhanuprakash Modem
Quoted 5 lines · 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.

Quoted 41 lines
---
 lib/drmtest.c | 9 +++++++++
 1 file changed, 9 insertions(+)
lib/drmtest.c +9 -0
index 03b5239b2..f6cd8e500 100644
@@ -63,6 +63,7 @@
 #include "intel_reg.h"
 #include "ioctl_wrappers.h"
 #include "igt_dummyload.h"
+#include "xe/xe_query.h"
 
 /**
  * SECTION:drmtest
@@ -601,6 +602,10 @@ int drm_open_driver(int chipset)
 		}
 	}
 
+	/* Cache xe_device struct. */
+	if (is_xe_device(fd))
+		xe_device_get(fd);
+
 	return fd;
 }
 
@@ -618,6 +623,10 @@ int drm_close_driver(int fd)
 	if (fd < 3)
 		return -1;
 
+	/* Remove xe_device from cache. */
+	if (is_xe_device(fd))
+		xe_device_put(fd);
+
 	return close(fd);
 }
 
Signature · 1 line
2.40.0
#9 lore raw

Re: [igt-dev] [i-g-t 2/6] lib: Cache xe_device at driver open/close level

In reply to Bhanuprakash Modem
Quoted 22 lines · 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.

---
 lib/drmtest.c | 9 +++++++++
 1 file changed, 9 insertions(+)
lib/drmtest.c +1 -0
index 03b5239b2..f6cd8e500 100644
@@ -63,6 +63,7 @@
 #include "intel_reg.h"
 #include "ioctl_wrappers.h"
 #include "igt_dummyload.h"
+#include "xe/xe_query.h"
 
 /**
  * SECTION:drmtest

lib/drmtest.c int drm_open_driver(int chipset) · line 611

Quoted 10 lines
lib/drmtest.c +4 -0
@@ -601,6 +602,10 @@ int drm_open_driver(int chipset)
 		}
 	}
 
+	/* Cache xe_device struct. */
+	if (is_xe_device(fd))
+		xe_device_get(fd);
+
 	return fd;
 }
 

Imo this should land to __drm_open_driver_another() and __drm_open_driver_render().

gem_reopen_driver() still requires explicit device get for xe.

--
Zbigniew

Quoted 14 lines
lib/drmtest.c +4 -0
@@ -618,6 +623,10 @@ int drm_close_driver(int fd)
 	if (fd < 3)
 		return -1;
 
+	/* Remove xe_device from cache. */
+	if (is_xe_device(fd))
+		xe_device_put(fd);
+
 	return close(fd);
 }
 
Signature · 1 line
2.40.0
#10 lore raw

Re: [igt-dev] [i-g-t 2/6] lib: Cache xe_device at driver open/close level

Hi Zbigniew,

Quoted 26 lines · Zbigniew Kempczyński
Quoted 25 lines · 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.

---
  lib/drmtest.c | 9 +++++++++
  1 file changed, 9 insertions(+)
lib/drmtest.c +1 -0
index 03b5239b2..f6cd8e500 100644
@@ -63,6 +63,7 @@
  #include "intel_reg.h"
  #include "ioctl_wrappers.h"
  #include "igt_dummyload.h"
+#include "xe/xe_query.h"
 
  /**
   * SECTION:drmtest
@@ -601,6 +602,10 @@ int drm_open_driver(int chipset)
  		}
  	}
 
Quoted 10 lines

lib/drmtest.c int drm_open_driver(int chipset) · line 611

Quoted 7 lines
lib/drmtest.c +4 -0
+	/* Cache xe_device struct. */
+	if (is_xe_device(fd))
+		xe_device_get(fd);
+
  	return fd;
  }
 

Imo this should land to __drm_open_driver_another() and __drm_open_driver_render().

Agreed, will float a new rev with these changes.

Quoted 2 lines

gem_reopen_driver() still requires explicit device get for xe.

This fix is already landed in IGT:
https://cgit.freedesktop.org/drm/igt-gpu-tools/commit/?id=a48277948

- Bhanu

Quoted 19 lines

--
Zbigniew

Quoted 14 lines
lib/drmtest.c +4 -0
@@ -618,6 +623,10 @@ int drm_close_driver(int fd)
  	if (fd < 3)
  		return -1;
 
+	/* Remove xe_device from cache. */
+	if (is_xe_device(fd))
+		xe_device_put(fd);
+
  	return close(fd);
  }
 
Signature · 1 line
2.40.0
#11 lore raw

PATCH 3/6 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 bd5eb1d18..d254a23cb 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 cc6e7cefd..63f32ca92 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
#12 lore raw

Re: [igt-dev] [i-g-t 3/6] lib/xe/xe_query: Add xe_config() interface

Quoted 3 lines · Bhanuprakash Modem

Add support to get XE configuration from xe_device.

Cc Janga Rahul Kumar <[email protected]>
Quoted 36 lines
---
  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 bd5eb1d18..d254a23cb 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 cc6e7cefd..63f32ca92 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);
Reviewed-by on v1 3/6
#13 lore raw

Re: [igt-dev] [i-g-t 3/6] lib/xe/xe_query: Add xe_config() interface

In reply to Bhanuprakash Modem

Hi,

Quoted 3 lines · Bhanuprakash Modem

Add support to get XE configuration from xe_device.

Regards,
Kamil

Quoted 39 lines
---
 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 bd5eb1d18..d254a23cb 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 cc6e7cefd..63f32ca92 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
#14 lore raw

PATCH 4/6 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 e085e234a..9125a8ccb 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
@@ -2639,9 +2638,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);
@@ -2978,10 +2974,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
#15 lore raw

Re: [igt-dev] [i-g-t 4/6] Revert "lib/igt_kms: Cache xe_device info for kms tests"

Quoted 6 lines · Bhanuprakash Modem

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

This reverts commit 3e049d7c5048c8e4d0b0cfc22afca18e9e897e9a.

Cc Janga Rahul Kumar <[email protected]>
Quoted 37 lines
---
  lib/igt_kms.c | 8 --------
  1 file changed, 8 deletions(-)
lib/igt_kms.c +0 -8
index e085e234a..9125a8ccb 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
@@ -2639,9 +2638,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);
@@ -2978,10 +2974,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];
#16 lore raw

Re: [igt-dev] [i-g-t 4/6] Revert "lib/igt_kms: Cache xe_device info for kms tests"

In reply to Bhanuprakash Modem

Hi,

Quoted 2 lines · Bhanuprakash Modem

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

------------------------- ^^^^^^^^^^
s/this logic/it/

Quoted 4 lines

This reverts commit 3e049d7c5048c8e4d0b0cfc22afca18e9e897e9a.

Please make it last patch in this series.

Regards,
Kamil

Quoted 40 lines
---
 lib/igt_kms.c | 8 --------
 1 file changed, 8 deletions(-)
lib/igt_kms.c +0 -8
index e085e234a..9125a8ccb 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
@@ -2639,9 +2638,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);
@@ -2978,10 +2974,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
#17 lore raw

PATCH 5/6 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().

---
 lib/igt_msm.c                               |  2 +-
 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                      |  4 +--
 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/drm_read.c                            |  3 +++
 tests/dumb_buffer.c                         |  2 +-
 tests/eviction_common.c                     |  2 +-
 tests/fbdev.c                               |  2 +-
 tests/i915/api_intel_allocator.c            |  2 +-
 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               |  3 +++
 tests/i915/gem_basic.c                      |  5 +++-
 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_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                 |  2 +-
 tests/i915/gem_ctx_engines.c                |  4 ++-
 tests/i915/gem_ctx_exec.c                   |  3 +++
 tests/i915/gem_ctx_freq.c                   |  3 +++
 tests/i915/gem_ctx_param.c                  |  2 +-
 tests/i915/gem_ctx_persistence.c            |  2 +-
 tests/i915/gem_ctx_shared.c                 |  3 +++
 tests/i915/gem_ctx_sseu.c                   |  2 +-
 tests/i915/gem_ctx_switch.c                 |  2 +-
 tests/i915/gem_eio.c                        |  3 +++
 tests/i915/gem_evict_alignment.c            |  2 +-
 tests/i915/gem_evict_everything.c           |  2 +-
 tests/i915/gem_exec_alignment.c             |  3 +++
 tests/i915/gem_exec_async.c                 |  2 +-
 tests/i915/gem_exec_await.c                 |  2 +-
 tests/i915/gem_exec_balancer.c              |  3 +++
 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_endless.c               |  3 +++
 tests/i915/gem_exec_fair.c                  |  2 +-
 tests/i915/gem_exec_fence.c                 |  2 +-
 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              |  2 +-
 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               |  2 +-
 tests/i915/gem_exercise_blt.c               |  2 +-
 tests/i915/gem_fd_exhaustion.c              |  2 +-
 tests/i915/gem_fence_thrash.c               |  3 ++-
 tests/i915/gem_fenced_exec_thrash.c         |  2 +-
 tests/i915/gem_flink_basic.c                |  7 +++--
 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              |  4 +--
 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                   |  2 +-
 tests/i915/gem_mmap_offset.c                |  2 +-
 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                |  2 +-
 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                    |  2 +-
 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              |  7 +++--
 tests/i915/gem_vm_create.c                  |  2 +-
 tests/i915/gem_wait.c                       |  2 +-
 tests/i915/gem_watchdog.c                   |  2 +-
 tests/i915/gem_workarounds.c                |  3 +++
 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_rpm.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                   |  4 +--
 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                           |  4 +--
 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                              |  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_dp_tiled_display.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_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                       |  2 +-
 tests/xe/xe_create.c                        |  2 +-
 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_vm.c                            |  2 +-
 tests/xe/xe_waitfence.c                     |  2 +-
 288 files changed, 436 insertions(+), 375 deletions(-)
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);
 }
 
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_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_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_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_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_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);
 	}
 }
tests/amdgpu/amd_psr.c +2 -2
index 966a0dccf..bca3c6449 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]);
@@ -761,7 +761,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 			igt_require_f(igt_amd_set_visual_confirm(data.fd, VISUAL_CONFIRM_DISABLE),
 				      "reset PSR visual confirm option failed\n");
 		}
-		close(data.debugfs_fd);
 		igt_display_fini(&data.display);
+		drm_close_driver(data.debugfs_fd);
 	}
 }
tests/amdgpu/amd_vrr_range.c +1 -0
index 2f27296dd..cacd668cd 100644
@@ -338,5 +338,6 @@ igt_main
 	igt_fixture
 	{
 		igt_display_fini(&data.display);
+		drm_close_driver(data.fd);
 	}
 }
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 7e7262ed3..a650efe16 100644
@@ -558,6 +558,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 008bc34b6..56c985b1a 100644
@@ -1080,6 +1080,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 2b17ce29d..f700673b3 100644
@@ -525,6 +525,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/core_auth.c +5 -5
index 257f12482..110163b00 100644
@@ -189,7 +189,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
@@ -201,7 +201,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.");
@@ -211,11 +211,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 */
@@ -224,7 +224,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 40a1c194d..9e53c46f9 100644
@@ -58,5 +58,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 fde27cdc6..c68b6b559 100644
@@ -52,5 +52,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 f6953b313..0c2949f18 100644
@@ -46,5 +46,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 470f9441d..30348dd62 100644
@@ -85,7 +85,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)
@@ -206,10 +206,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 0b4b8613c..da4662e0a 100644
@@ -66,7 +66,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 8c775158f..b45646d70 100644
@@ -213,6 +213,6 @@ igt_main
 	igt_fixture {
 		close(sysfs);
 		close(debugfs);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
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/drm_read.c +3 -0
index 36dc623ed..e989e7bfb 100644
@@ -311,4 +311,7 @@ igt_main
 
 	igt_subtest("short-buffer-wakeup")
 		test_short_buffer_wakeup(fd, pipe);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/dumb_buffer.c +1 -1
index ded6b809c..8aa320a59 100644
@@ -394,6 +394,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/i915/api_intel_allocator.c +1 -1
index e9039a214..83acc306f 100644
@@ -847,5 +847,5 @@ igt_main
 		gem_pool(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/api_intel_bb.c +1 -1
index 46633b038..da74e1ed3 100644
@@ -1701,6 +1701,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 1b1247553..c8437dc0b 100644
@@ -855,6 +855,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 478e78a66..fc1c6a574 100644
@@ -212,5 +212,5 @@ igt_main
 		negative_reloc_blt(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_barrier_race.c +3 -0
index f446aab62..52f4eef39 100644
@@ -153,4 +153,7 @@ igt_main
 			break;
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_basic.c +4 -1
index 3dd790c6c..edcc6d443 100644
@@ -108,7 +108,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();
@@ -117,4 +117,7 @@ igt_main
 	igt_describe("Verify that closing drm driver is possible with opened gem object.");
 	igt_subtest("create-fd-close")
 		test_create_fd_close(fd);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_blits.c +1 -1
index 5fbb384db..5ac0bfdc3 100644
@@ -893,6 +893,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 08a500a9e..70ba1999f 100644
@@ -562,6 +562,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_caching.c +1 -1
index 6e944f0ac..16c594aa6 100644
@@ -340,6 +340,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 d25e00fc8..4a1ae094d 100644
@@ -731,6 +731,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 9c646f426..c1cbf0f90 100644
@@ -274,7 +274,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();
@@ -293,7 +293,7 @@ static void threads(int timeout, unsigned int flags)
 	igt_waitchildren();
 
 	gem_quiescent_gpu(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -317,7 +317,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.");
@@ -329,7 +329,7 @@ igt_main
 		igt_waitchildren();
 
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Basic workload submission on multi-GPU machine.");
@@ -342,7 +342,7 @@ igt_main
 			igt_assert(fd > 0);
 			process(fd, child);
 			gem_quiescent_gpu(fd);
-			close(fd);
+			drm_close_driver(fd);
 		}
 
 		igt_waitchildren();
@@ -369,7 +369,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_concurrent_all.c +5 -0
index 25b7daf86..e1351c368 100644
@@ -2015,4 +2015,9 @@ igt_main
 			}
 		}
 	}
+
+	igt_fixture {
+		drm_close_driver(fd);
+		drm_close_driver(vgem_drv);
+	}
 }
tests/i915/gem_cs_tlb.c +1 -1
index 2117b41e4..ff96e63ed 100644
@@ -162,5 +162,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_bad_destroy.c +1 -1
index 50bb9aa07..5dc6d040d 100644
@@ -80,5 +80,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_create.c +1 -1
index 39f070af9..f0ef447e3 100644
@@ -667,6 +667,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_engines.c +3 -1
index b87a21fa4..3daed16a0 100644
@@ -633,6 +633,8 @@ igt_main
 			independent_all(i915, ctx);
 	}
 
-	igt_fixture
+	igt_fixture {
 		igt_stop_hang_detector();
+		drm_close_driver(i915);
+	}
 }
tests/i915/gem_ctx_exec.c +3 -0
index 3d94f01db..ec36f0040 100644
@@ -546,4 +546,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 18e736c73..ce4c0ba55 100644
@@ -213,4 +213,7 @@ igt_main
 
 	igt_subtest_f("sysfs")
 		sysfs_range(i915);
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_ctx_param.c +1 -1
index d119ea74e..6fa2e6161 100644
@@ -473,5 +473,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 +1 -1
index 9fb528186..fabb41e66 100644
@@ -1383,6 +1383,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_ctx_shared.c +3 -0
index 3d73db581..e7006f55f 100644
@@ -1088,4 +1088,7 @@ igt_main
 			igt_stop_hang_detector();
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_ctx_sseu.c +1 -1
index 7685511f0..dcc38ae17 100644
@@ -545,6 +545,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_switch.c +1 -1
index 4e46b7634..f675570ec 100644
@@ -440,6 +440,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 +3 -0
index 8dbaa7a75..80eca558f 100644
@@ -1126,4 +1126,7 @@ igt_main
 			intel_allocator_multiprocess_stop();
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_evict_alignment.c +1 -1
index 0b560ab03..7a40b0128 100644
@@ -265,6 +265,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_evict_everything.c +1 -1
index 120f89072..d5d464889 100644
@@ -290,6 +290,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_alignment.c +3 -0
index a9fcd2a74..3084da5fc 100644
@@ -546,4 +546,7 @@ igt_main
 		prio_inversion(fd, SHARED);
 	igt_subtest("pi-isolated")
 		prio_inversion(fd, ISOLATED);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_exec_async.c +1 -1
index 173bc4648..6895b9c6c 100644
@@ -213,6 +213,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 4935cf395..0fd8cbf67 100644
@@ -287,6 +287,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_balancer.c +3 -0
index 1c655e583..df16f8bec 100644
@@ -3482,4 +3482,7 @@ igt_main
 		igt_subtest("nohangcheck")
 			nohangcheck(i915);
 	}
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_basic.c +1 -1
index ca4fc7b96..c018d4089 100644
@@ -98,6 +98,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 4619bda81..5a8df7264 100644
@@ -326,5 +326,5 @@ igt_main
 		exhaustive(i915);
 
 	igt_fixture
-		close(i915);
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_capture.c +1 -1
index 9c391192d..56f5c6ba8 100644
@@ -1013,6 +1013,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 449aa5b2e..8ca564b09 100644
@@ -225,6 +225,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_endless.c +3 -0
index 77719de83..f895c6783 100644
@@ -367,4 +367,7 @@ igt_main
 			intel_register_access_fini(&mmio);
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_fair.c +1 -1
index 8208ab404..916686b55 100644
@@ -1348,6 +1348,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_fence.c +1 -1
index c2d874f84..799995865 100644
@@ -3351,6 +3351,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_flush.c +1 -1
index 42ddbc529..6a156c5c5 100644
@@ -711,6 +711,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_gttfill.c +2 -2
index d6c8f2192..320b47001 100644
@@ -279,7 +279,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();
@@ -287,6 +287,6 @@ igt_main
 
 	igt_fixture {
 		intel_allocator_multiprocess_stop();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_latency.c +1 -1
index 4838a7082..d344db05e 100644
@@ -971,6 +971,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 497f57f08..77c3aea54 100644
@@ -1083,6 +1083,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 +1 -1
index 705b22cb9..8c82abdd7 100644
@@ -364,6 +364,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 d0805d330..80024fb3d 100644
@@ -646,6 +646,6 @@ igt_main
 	igt_fixture {
 		gem_close(fd, handle);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_reloc.c +1 -1
index 3ce89ca64..bcaffd1d9 100644
@@ -1178,5 +1178,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_exec_schedule.c +1 -1
index ab1dd7749..a12db4df2 100644
@@ -3369,6 +3369,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 7d23bcd5b..6bf392bd2 100644
@@ -455,6 +455,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 8d56093fa..2295ed04c 100644
@@ -411,6 +411,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 +1 -1
index 29d96cdca..08cc7f78a 100644
@@ -660,6 +660,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 fb11fb925..365b9b005 100644
@@ -381,6 +381,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 a6463685e..717422951 100644
@@ -69,5 +69,5 @@ igt_simple_main
 
 	igt_waitchildren();
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_fence_thrash.c +2 -1
index 89a5ae29d..348100476 100644
@@ -225,7 +225,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;
 }
@@ -252,4 +252,5 @@ igt_main
 
 	igt_subtest("bo-copy")
 		igt_assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0);
+
 }
tests/i915/gem_fenced_exec_thrash.c +1 -1
index a9597d801..03ba200a7 100644
@@ -199,5 +199,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 +5 -2
index 2620bc55d..9a014eb07 100644
@@ -147,7 +147,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 */
@@ -156,7 +156,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
@@ -188,4 +188,7 @@ igt_main
 	igt_describe("Tests flink lifetime by referencing from multiple descriptors.");
 	igt_subtest("flink-lifetime")
 		test_flink_lifetime(fd);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_flink_race.c +3 -3
index 70e133d70..c167e5789 100644
@@ -127,7 +127,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)
@@ -188,13 +188,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 8000e58cc..5f0a19b8b 100644
@@ -105,5 +105,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 15a6139ea..c365f1196 100644
@@ -164,7 +164,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 272091fdb..d142b1cf7 100644
@@ -515,5 +515,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 ea32b705a..9c31eeaea 100644
@@ -139,6 +139,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 71a066de3..6fd596feb 100644
@@ -93,7 +93,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();
@@ -132,7 +132,7 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 		igt_i915_driver_unload();
 	}
 }
tests/i915/gem_lmem_swapping.c +2 -2
index 55b044ecd..c4e0fc3be 100644
@@ -736,7 +736,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();
@@ -781,7 +781,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 2502d84c7..c141d208d 100644
@@ -77,7 +77,7 @@ dontneed_before_mmap(void)
 					PROT_READ | PROT_WRITE,
 					t->type);
 
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -99,7 +99,7 @@ dontneed_before_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -123,7 +123,7 @@ dontneed_after_mmap(void)
 					t->type);
 
 		gem_madvise(fd, handle, I915_MADV_DONTNEED);
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -145,7 +145,7 @@ dontneed_after_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -161,7 +161,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
@@ -185,7 +185,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 e418047c2..127d7e3a6 100644
@@ -173,6 +173,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 61f862a8e..053c9ed4c 100644
@@ -315,5 +315,5 @@ igt_main
 		test_huge_bo(2);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_gtt.c +1 -1
index c14ab50ee..a92f42dc1 100644
@@ -1492,5 +1492,5 @@ igt_main
 
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_offset.c +1 -1
index 962fc1b73..1d236f6d0 100644
@@ -926,6 +926,6 @@ igt_main
 		blt_coherency(i915);
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_mmap_wc.c +1 -1
index 6dc7bae49..9fc26593e 100644
@@ -620,5 +620,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 474149d48..affce4ee6 100644
@@ -326,6 +326,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 59959a374..8e9af5088 100644
@@ -183,6 +183,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ppgtt.c +4 -4
index c3102857a..09b4c6acc 100644
@@ -251,8 +251,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
@@ -385,7 +385,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;
 }
@@ -398,7 +398,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 a8bf2b054..e76dbce1f 100644
@@ -350,6 +350,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 3b56f787a..d5d20f58d 100644
@@ -252,5 +252,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_pwrite.c +1 -1
index 6e3f833cd..353ce1a01 100644
@@ -572,5 +572,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 e6a10747d..8883b2737 100644
@@ -140,5 +140,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 2f27abd58..a4209945f 100644
@@ -1293,6 +1293,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_read_read_speed.c +1 -1
index 7c5c90f79..9e84c7a27 100644
@@ -214,6 +214,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_readwrite.c +1 -1
index 2d437dec3..6a24d74ec 100644
@@ -143,5 +143,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_reg_read.c +1 -1
index 79facc1f2..302aa82ab 100644
@@ -170,6 +170,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_render_copy.c +1 -1
index 2c150b2b0..0eaa10754 100644
@@ -879,6 +879,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 5e1daccf1..dd7917413 100644
@@ -81,7 +81,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 +1 -1
index 7b003d88b..9bc7c803d 100644
@@ -999,6 +999,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 afcd7b73e..b0641b483 100644
@@ -401,6 +401,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 5e3bf6a12..7148c9d18 100644
@@ -261,6 +261,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 2f890e83b..4ebf17dcb 100644
@@ -130,5 +130,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 6bec7f27e..170195e47 100644
@@ -99,5 +99,5 @@ igt_simple_main
 
 	munmap(ptr, OBJECT_SIZE);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_shrink.c +7 -7
index 380d2c846..a104c9f3a 100644
@@ -270,7 +270,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;
 }
@@ -319,7 +319,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);
 			}
 		}
 	}
@@ -331,7 +331,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;
@@ -344,7 +344,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;
@@ -356,7 +356,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();
@@ -399,7 +399,7 @@ static void reclaim(unsigned engine, int timeout)
 
 	munmap((void *)shared, 4096);
 	close(debugfs);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -456,7 +456,7 @@ igt_main
 			 num_processes, alloc_size);
 
 		alloc_size <<= 20;
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("reclaim")
tests/i915/gem_softpin.c +1 -1
index 8717860b2..0cf33208f 100644
@@ -1531,6 +1531,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 7dc68ebc7..68e7af7e3 100644
@@ -277,6 +277,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 883fe4293..a8e6c42a8 100644
@@ -419,5 +419,5 @@ igt_main
 		test_batch(fd, 2, 1);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_stress.c +1 -1
index 3765ab14b..23690c077 100644
@@ -926,7 +926,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 e7dc6637a..18adbd19d 100644
@@ -1363,6 +1363,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 5e7ed0c4e..0f8434d7f 100644
@@ -215,6 +215,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_fence_blits.c +1 -1
index a3a0221d6..8e908eac0 100644
@@ -320,5 +320,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_partial_pwrite_pread.c +1 -1
index 95fb69c65..ecc97002e 100644
@@ -318,6 +318,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 2b4cec6e7..48f5c67e1 100644
@@ -222,5 +222,5 @@ igt_simple_main
 		}
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_pread_pwrite.c +1 -1
index 2d21dfb76..885785cab 100644
@@ -154,5 +154,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 f4bdce738..718516def 100644
@@ -246,5 +246,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_wb.c +1 -1
index e9efbdf23..b2337806d 100644
@@ -239,5 +239,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 1f245eb7d..4f733163b 100644
@@ -243,5 +243,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 513d579d3..d326ae7c2 100644
@@ -138,5 +138,5 @@ igt_simple_main
 
 	munmap(ptr, size);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_unfence_active_buffers.c +1 -1
index a0a601de2..71686095d 100644
@@ -99,5 +99,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 735c14720..9d92156a1 100644
@@ -121,5 +121,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
-	close(i915);
+	drm_close_driver(i915);
 }
tests/i915/gem_userptr_blits.c +5 -2
index b00afc32c..381f1b6d9 100644
@@ -1288,9 +1288,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;
@@ -2703,4 +2703,7 @@ igt_main_args("c:", NULL, help_str, opt_handler, NULL)
 		igt_require(has_userptr_probe(fd));
 		test_probe(fd);
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_vm_create.c +1 -1
index f47d8c556..9c5085206 100644
@@ -388,6 +388,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_wait.c +1 -1
index 27d084afa..a33e461d8 100644
@@ -257,6 +257,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_watchdog.c +1 -1
index 27f3a2d7f..18957cee3 100644
@@ -586,6 +586,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_workarounds.c +3 -0
index 7d1199625..b0268e01a 100644
@@ -339,4 +339,7 @@ igt_main
 			}
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(device);
 }
tests/i915/gen7_exec_parse.c +2 -2
index e9751ea73..895aea1ea 100644
@@ -445,7 +445,7 @@ static void hsw_load_register_reg(void)
 				   0xabcdabc0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -717,6 +717,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 26b151705..e7d47fccc 100644
@@ -1252,6 +1252,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 cafa5233c..f3f0c3d0a 100644
@@ -44,5 +44,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 5422d585f..b6988784d 100644
@@ -46,7 +46,7 @@ init(void)
 static void
 deinit(void)
 {
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 
tests/i915/i915_hangman.c +2 -2
index dd396c4e9..d8c9ec0ef 100644
@@ -97,7 +97,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)
@@ -580,6 +580,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 6d9937e99..4b7ecb766 100644
@@ -83,6 +83,6 @@ igt_main
 
 	igt_fixture {
 		close(hwm);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_module_load.c +4 -4
index 725687dab..057c68906 100644
@@ -238,7 +238,7 @@ static void gem_sanitycheck(void)
 		store_all(i915);
 	errno = 0;
 
-	close(i915);
+	drm_close_driver(i915);
 	igt_assert_eq(err, expected);
 }
 
@@ -286,7 +286,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();
@@ -327,7 +327,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;
 }
@@ -419,7 +419,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 377eec58c..9da7dc074 100644
@@ -65,5 +65,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 829606622..0bdb98f3f 100644
@@ -332,6 +332,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 6f08cb3fc..859bfdc55 100644
@@ -689,7 +689,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 662d514a4..096adbbb5 100644
@@ -139,6 +139,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 894ae294c..825f5a326 100644
@@ -167,6 +167,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_lpsp.c +1 -1
index 3ad8b2603..fc4404c9b 100644
@@ -211,6 +211,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 3554f5d77..0fac22770 100644
@@ -611,6 +611,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_rpm.c +1 -1
index 9a6408dd3..5f812d3c9 100644
@@ -874,7 +874,7 @@ static void teardown_environment(bool display_enabled)
 		fini_mode_set_data(&ms_data);
 
 	close(debugfs);
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 
 	has_runtime_pm = false;
 }
tests/i915/i915_pm_rps.c +4 -1
index d4ee2d58a..34abfe690 100644
@@ -877,7 +877,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
@@ -959,4 +959,7 @@ igt_main
 		waitboost(drm_fd, true);
 		igt_disallow_hang(drm_fd, hang);
 	}
+
+	igt_fixture
+		drm_close_driver(drm_fd);
 }
tests/i915/i915_pm_sseu.c +1 -1
index 1b428c9ba..771971851 100644
@@ -315,7 +315,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 51b412e3a..9f6235083 100644
@@ -76,6 +76,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_query.c +1 -1
index e725e04e4..ea191f8a3 100644
@@ -1465,6 +1465,6 @@ igt_main
 		query_parse_and_validate_hwconfig_table(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_suspend.c +2 -2
index a9507964b..1961d85f1 100644
@@ -232,7 +232,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);
@@ -315,5 +315,5 @@ igt_main
 		test_forcewake(fd, true);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/kms_big_fb.c +1 -1
index a0d5ef730..d132f5b98 100644
@@ -1010,6 +1010,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 20d3058fb..74af9229e 100644
@@ -506,6 +506,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 	igt_fixture {
 		gpu_engines_restore_timeouts(fd, num_engines, saved_gpu_timeouts);
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/i915/kms_ccs.c +1 -1
index 1b3462ea9..2661f661c 100644
@@ -708,6 +708,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 c4dfc9251..87aceb1e3 100644
@@ -257,6 +257,6 @@ igt_main
 
 	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 831ec867a..aea724756 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 63657a742..c8a6f1aa1 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 650e14a77..075e3827b 100644
@@ -1351,7 +1351,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 -2
index bc51975f6..77e1cc807 100644
@@ -303,9 +303,8 @@ 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);
-		close(data.drm_fd);
 	}
 }
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 0e8d7f4f0..0ef5f1e82 100644
@@ -639,6 +639,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 4cf986440..a202c613c 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/i915/perf.c +2 -2
index 9ca4d34b6..760c8d692 100644
@@ -5299,7 +5299,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;
@@ -6008,6 +6008,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 c5f083bbd..34b0e10f6 100644
@@ -2111,7 +2111,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);
@@ -2436,13 +2436,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 dda27a0af..94437c0a0 100644
@@ -105,6 +105,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_heartbeat_interval.c +1 -1
index 8a3dd3975..467e0728b 100644
@@ -514,6 +514,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_preempt_timeout.c +1 -1
index 5e0a7d962..b686d6ba8 100644
@@ -343,6 +343,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_timeslice_duration.c +1 -1
index 92c4c5eae..8f0d8d94b 100644
@@ -564,6 +564,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
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 e4783624f..1e5d834ce 100644
@@ -795,7 +795,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);
 	}
@@ -874,6 +874,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 51ffa523a..f44fc4bea 100644
@@ -668,6 +668,6 @@ igt_main_args("e", NULL, help_str, opt_handler, &data)
 		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 fdc7120c7..d444cfe10 100644
@@ -1069,6 +1069,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 3a353a032..d9ae35587 100644
@@ -1010,6 +1010,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 7df6a6125..69e52a864 100644
@@ -1803,6 +1803,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_dp_tiled_display.c +1 -1
index 07b803a50..8dfe93000 100644
@@ -502,6 +502,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_flip.c +1 -1
index e4c98b8ec..8d6a8e74d 100755
@@ -1898,6 +1898,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 f1508efba..d1e516562 100644
@@ -60,7 +60,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)
@@ -386,7 +386,7 @@ end:
 
 	igt_fixture {
 		drmModeFreeConnector(connector);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 
 		reset_connectors();
 	}
tests/kms_getfb.c +2 -2
index 4adc7eee2..3cb568808 100644
@@ -452,7 +452,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);
 	}
 }
 
@@ -484,6 +484,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 81a32dbf8..d47a1977c 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 ec0483055..6059f1f8f 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 65afc9f60..9a354fcfe 100644
@@ -433,6 +433,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 10e16b638..8e0cd2129 100644
@@ -1318,6 +1318,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 a37abd16d..61d0f8c89 100644
@@ -1323,6 +1323,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 96aa6d8d6..d9a5992e4 100644
@@ -178,7 +178,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);
@@ -206,7 +206,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);
@@ -217,7 +217,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);
@@ -338,5 +338,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 28b4fd27c..f0d8b1172 100644
@@ -1279,6 +1279,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_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);
 	}
 }
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);
 	}
 }
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);
+	}
 }
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);
         }
 }
tests/prime_busy.c +1 -1
index 343020f13..f9f1674d4 100644
@@ -162,6 +162,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap.c +1 -1
index bc19f68c9..1c2d2a301 100644
@@ -557,6 +557,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 b22fb35c1..a18c16c5c 100644
@@ -249,7 +249,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);
 }
 
 /*
@@ -346,6 +346,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 bf5486194..0b5ac256d 100644
@@ -106,8 +106,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)
@@ -139,8 +139,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)
@@ -164,8 +164,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);
 }
@@ -211,7 +211,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);
 }
 
@@ -275,14 +275,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);
 }
@@ -357,13 +357,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);
 }
@@ -392,7 +392,7 @@ static void test_llseek_size(void)
 		close(dma_buf_fd);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_llseek_bad(void)
@@ -421,7 +421,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 9aa767c9c..9bd22641c 100644
@@ -1249,7 +1249,7 @@ igt_main
 
 
 	igt_fixture {
-		close(i915);
-		close(vgem);
+		drm_close_driver(i915);
+		drm_close_driver(vgem);
 	}
 }
tests/syncobj_basic.c +1 -1
index 6e20c3411..beb44b1e9 100644
@@ -232,7 +232,7 @@ igt_main
 		test_valid_cycle(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 }
tests/syncobj_timeline.c +1 -1
index 7f5ff6f6c..081f440f3 100644
@@ -1538,6 +1538,6 @@ igt_main
 		test_32bits_limit(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/syncobj_wait.c +1 -1
index 427b6b119..eebc96b67 100644
@@ -914,6 +914,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/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/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);
 	}
 }
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);
 }
tests/vgem_basic.c +3 -3
index ada5518d7..36899b307 100644
@@ -64,8 +64,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)
@@ -537,6 +537,6 @@ igt_main
 		test_debugfs_read(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/vgem_slow.c +1 -1
index 58b09e421..4c4e94ea0 100644
@@ -85,6 +85,6 @@ igt_main
 		test_nohang(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
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);
 	}
 }
tests/xe/xe_compute.c +1 -1
index 7ac64dfe3..5e6cd8529 100644
@@ -45,6 +45,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_create.c +1 -1
index ae841f809..b3d9fd49f 100644
@@ -102,6 +102,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_debugfs.c +1 -1
index 6bdd3ef06..4006981c6 100644
@@ -270,6 +270,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 8920b141b..81ece2428 100644
@@ -220,7 +220,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]);
 	}
 
 }
@@ -257,6 +257,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_evict.c +3 -3
index 5687cce30..14a2d19f1 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 {
@@ -701,5 +701,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/xe/xe_exec_balancer.c +1 -1
index 2018c8104..fb4592903 100644
@@ -708,6 +708,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_basic.c +1 -1
index 2a176a5b3..d14a764f4 100644
@@ -353,6 +353,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 685193990..950cb6159 100644
@@ -361,6 +361,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 a3ab17270..8cd883c09 100644
@@ -570,6 +570,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_reset.c +4 -4
index 0d72a3f20..3700b8dce 100644
@@ -294,7 +294,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;
@@ -475,7 +475,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;
@@ -655,7 +655,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;
@@ -946,6 +946,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_threads.c +4 -4
index 3f2c2de9e..bde92a9c5 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);
 	}
 }
 
@@ -454,7 +454,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);
 	}
 }
 
@@ -698,7 +698,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);
 	}
 }
 
@@ -1403,6 +1403,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_guc_pc.c +1 -1
index 5c71ae147..56d4f9190 100644
@@ -496,6 +496,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 35d61608e..f43beb1a8 100644
@@ -1180,6 +1180,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 6b313a189..352cbcab4 100644
@@ -77,6 +77,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_mmio.c +1 -1
index 42b6241b1..77a38b8d1 100644
@@ -89,6 +89,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_module_load.c +1 -1
index c2d43cc20..16432c78f 100644
@@ -86,7 +86,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 367671883..f276e694c 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 44154143c..7bec294ed 100644
@@ -441,6 +441,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 4e8fd5d4f..a86d0e9f2 100644
@@ -122,9 +122,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);
 }
 
 /**
@@ -202,9 +202,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);
 }
@@ -259,10 +259,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)
@@ -335,7 +335,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 */
@@ -343,7 +343,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);
 }
@@ -429,7 +429,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;
@@ -437,7 +437,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);
 }
@@ -474,7 +474,7 @@ static void test_llseek_size(void)
 	}
 
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 /**
@@ -511,7 +511,7 @@ static void test_llseek_bad(void)
 	close(dma_buf_fd);
 
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -544,6 +544,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_query.c +1 -1
index 87990370f..1c06534d4 100644
@@ -491,6 +491,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_vm.c +1 -1
index d4cec104e..9015a5a57 100644
@@ -1839,6 +1839,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_waitfence.c +1 -1
index cdfcacdb4..8bfb741f6 100644
@@ -98,6 +98,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#18 lore raw

PATCH v2 5/6 tests: Use drm_close_driver() to close the drm fd

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

---
 lib/igt_msm.c                               |  2 +-
 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                      |  4 +--
 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/drm_read.c                            |  3 +++
 tests/dumb_buffer.c                         |  2 +-
 tests/eviction_common.c                     |  2 +-
 tests/fbdev.c                               |  2 +-
 tests/i915/api_intel_allocator.c            |  2 +-
 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               |  3 +++
 tests/i915/gem_basic.c                      |  5 +++-
 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_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                 |  2 +-
 tests/i915/gem_ctx_engines.c                |  4 ++-
 tests/i915/gem_ctx_exec.c                   |  3 +++
 tests/i915/gem_ctx_freq.c                   |  3 +++
 tests/i915/gem_ctx_param.c                  |  2 +-
 tests/i915/gem_ctx_persistence.c            |  2 +-
 tests/i915/gem_ctx_shared.c                 |  3 +++
 tests/i915/gem_ctx_sseu.c                   |  2 +-
 tests/i915/gem_ctx_switch.c                 |  2 +-
 tests/i915/gem_eio.c                        |  3 +++
 tests/i915/gem_evict_alignment.c            |  2 +-
 tests/i915/gem_evict_everything.c           |  2 +-
 tests/i915/gem_exec_alignment.c             |  3 +++
 tests/i915/gem_exec_async.c                 |  2 +-
 tests/i915/gem_exec_await.c                 |  2 +-
 tests/i915/gem_exec_balancer.c              |  3 +++
 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_endless.c               |  3 +++
 tests/i915/gem_exec_fair.c                  |  2 +-
 tests/i915/gem_exec_fence.c                 |  2 +-
 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              |  2 +-
 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               |  2 +-
 tests/i915/gem_exercise_blt.c               |  2 +-
 tests/i915/gem_fd_exhaustion.c              |  2 +-
 tests/i915/gem_fence_thrash.c               |  3 ++-
 tests/i915/gem_fenced_exec_thrash.c         |  2 +-
 tests/i915/gem_flink_basic.c                |  7 +++--
 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              |  4 +--
 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                   |  2 +-
 tests/i915/gem_mmap_offset.c                |  2 +-
 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                |  2 +-
 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                    |  2 +-
 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              |  7 +++--
 tests/i915/gem_vm_create.c                  |  2 +-
 tests/i915/gem_wait.c                       |  2 +-
 tests/i915/gem_watchdog.c                   |  2 +-
 tests/i915/gem_workarounds.c                |  3 +++
 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                   |  4 +--
 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                           |  4 +--
 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                              |  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_dp_tiled_display.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_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                       |  2 +-
 tests/xe/xe_create.c                        |  2 +-
 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_vm.c                            |  2 +-
 tests/xe/xe_waitfence.c                     |  2 +-
 287 files changed, 435 insertions(+), 374 deletions(-)
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);
 }
 
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_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_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_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_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_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);
 	}
 }
tests/amdgpu/amd_psr.c +2 -2
index 966a0dccf..bca3c6449 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]);
@@ -761,7 +761,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 			igt_require_f(igt_amd_set_visual_confirm(data.fd, VISUAL_CONFIRM_DISABLE),
 				      "reset PSR visual confirm option failed\n");
 		}
-		close(data.debugfs_fd);
 		igt_display_fini(&data.display);
+		drm_close_driver(data.debugfs_fd);
 	}
 }
tests/amdgpu/amd_vrr_range.c +1 -0
index 2f27296dd..cacd668cd 100644
@@ -338,5 +338,6 @@ igt_main
 	igt_fixture
 	{
 		igt_display_fini(&data.display);
+		drm_close_driver(data.fd);
 	}
 }
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 7e7262ed3..a650efe16 100644
@@ -558,6 +558,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 008bc34b6..56c985b1a 100644
@@ -1080,6 +1080,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 2b17ce29d..f700673b3 100644
@@ -525,6 +525,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/core_auth.c +5 -5
index 257f12482..110163b00 100644
@@ -189,7 +189,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
@@ -201,7 +201,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.");
@@ -211,11 +211,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 */
@@ -224,7 +224,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 40a1c194d..9e53c46f9 100644
@@ -58,5 +58,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 fde27cdc6..c68b6b559 100644
@@ -52,5 +52,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 f6953b313..0c2949f18 100644
@@ -46,5 +46,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 470f9441d..30348dd62 100644
@@ -85,7 +85,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)
@@ -206,10 +206,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 0b4b8613c..da4662e0a 100644
@@ -66,7 +66,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 8c775158f..b45646d70 100644
@@ -213,6 +213,6 @@ igt_main
 	igt_fixture {
 		close(sysfs);
 		close(debugfs);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
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/drm_read.c +3 -0
index 36dc623ed..e989e7bfb 100644
@@ -311,4 +311,7 @@ igt_main
 
 	igt_subtest("short-buffer-wakeup")
 		test_short_buffer_wakeup(fd, pipe);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/dumb_buffer.c +1 -1
index ded6b809c..8aa320a59 100644
@@ -394,6 +394,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/i915/api_intel_allocator.c +1 -1
index e9039a214..83acc306f 100644
@@ -847,5 +847,5 @@ igt_main
 		gem_pool(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/api_intel_bb.c +1 -1
index 46633b038..da74e1ed3 100644
@@ -1701,6 +1701,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 1b1247553..c8437dc0b 100644
@@ -855,6 +855,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 478e78a66..fc1c6a574 100644
@@ -212,5 +212,5 @@ igt_main
 		negative_reloc_blt(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_barrier_race.c +3 -0
index f446aab62..52f4eef39 100644
@@ -153,4 +153,7 @@ igt_main
 			break;
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_basic.c +4 -1
index 3dd790c6c..edcc6d443 100644
@@ -108,7 +108,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();
@@ -117,4 +117,7 @@ igt_main
 	igt_describe("Verify that closing drm driver is possible with opened gem object.");
 	igt_subtest("create-fd-close")
 		test_create_fd_close(fd);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_blits.c +1 -1
index 5fbb384db..5ac0bfdc3 100644
@@ -893,6 +893,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 08a500a9e..70ba1999f 100644
@@ -562,6 +562,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_caching.c +1 -1
index 6e944f0ac..16c594aa6 100644
@@ -340,6 +340,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 d25e00fc8..4a1ae094d 100644
@@ -731,6 +731,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 9c646f426..c1cbf0f90 100644
@@ -274,7 +274,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();
@@ -293,7 +293,7 @@ static void threads(int timeout, unsigned int flags)
 	igt_waitchildren();
 
 	gem_quiescent_gpu(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -317,7 +317,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.");
@@ -329,7 +329,7 @@ igt_main
 		igt_waitchildren();
 
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Basic workload submission on multi-GPU machine.");
@@ -342,7 +342,7 @@ igt_main
 			igt_assert(fd > 0);
 			process(fd, child);
 			gem_quiescent_gpu(fd);
-			close(fd);
+			drm_close_driver(fd);
 		}
 
 		igt_waitchildren();
@@ -369,7 +369,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_concurrent_all.c +5 -0
index 25b7daf86..e1351c368 100644
@@ -2015,4 +2015,9 @@ igt_main
 			}
 		}
 	}
+
+	igt_fixture {
+		drm_close_driver(fd);
+		drm_close_driver(vgem_drv);
+	}
 }
tests/i915/gem_cs_tlb.c +1 -1
index 2117b41e4..ff96e63ed 100644
@@ -162,5 +162,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_bad_destroy.c +1 -1
index 50bb9aa07..5dc6d040d 100644
@@ -80,5 +80,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_create.c +1 -1
index 39f070af9..f0ef447e3 100644
@@ -667,6 +667,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_engines.c +3 -1
index b87a21fa4..3daed16a0 100644
@@ -633,6 +633,8 @@ igt_main
 			independent_all(i915, ctx);
 	}
 
-	igt_fixture
+	igt_fixture {
 		igt_stop_hang_detector();
+		drm_close_driver(i915);
+	}
 }
tests/i915/gem_ctx_exec.c +3 -0
index 3d94f01db..ec36f0040 100644
@@ -546,4 +546,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 18e736c73..ce4c0ba55 100644
@@ -213,4 +213,7 @@ igt_main
 
 	igt_subtest_f("sysfs")
 		sysfs_range(i915);
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_ctx_param.c +1 -1
index d119ea74e..6fa2e6161 100644
@@ -473,5 +473,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 +1 -1
index 9fb528186..fabb41e66 100644
@@ -1383,6 +1383,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_ctx_shared.c +3 -0
index 3d73db581..e7006f55f 100644
@@ -1088,4 +1088,7 @@ igt_main
 			igt_stop_hang_detector();
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_ctx_sseu.c +1 -1
index 7685511f0..dcc38ae17 100644
@@ -545,6 +545,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_switch.c +1 -1
index 4e46b7634..f675570ec 100644
@@ -440,6 +440,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 +3 -0
index 8dbaa7a75..80eca558f 100644
@@ -1126,4 +1126,7 @@ igt_main
 			intel_allocator_multiprocess_stop();
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_evict_alignment.c +1 -1
index 0b560ab03..7a40b0128 100644
@@ -265,6 +265,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_evict_everything.c +1 -1
index 120f89072..d5d464889 100644
@@ -290,6 +290,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_alignment.c +3 -0
index a9fcd2a74..3084da5fc 100644
@@ -546,4 +546,7 @@ igt_main
 		prio_inversion(fd, SHARED);
 	igt_subtest("pi-isolated")
 		prio_inversion(fd, ISOLATED);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_exec_async.c +1 -1
index 173bc4648..6895b9c6c 100644
@@ -213,6 +213,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 4935cf395..0fd8cbf67 100644
@@ -287,6 +287,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_balancer.c +3 -0
index 1c655e583..df16f8bec 100644
@@ -3482,4 +3482,7 @@ igt_main
 		igt_subtest("nohangcheck")
 			nohangcheck(i915);
 	}
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_basic.c +1 -1
index ca4fc7b96..c018d4089 100644
@@ -98,6 +98,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 4619bda81..5a8df7264 100644
@@ -326,5 +326,5 @@ igt_main
 		exhaustive(i915);
 
 	igt_fixture
-		close(i915);
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_capture.c +1 -1
index 9c391192d..56f5c6ba8 100644
@@ -1013,6 +1013,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 449aa5b2e..8ca564b09 100644
@@ -225,6 +225,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_endless.c +3 -0
index 77719de83..f895c6783 100644
@@ -367,4 +367,7 @@ igt_main
 			intel_register_access_fini(&mmio);
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_fair.c +1 -1
index 8208ab404..916686b55 100644
@@ -1348,6 +1348,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_fence.c +1 -1
index c2d874f84..799995865 100644
@@ -3351,6 +3351,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_flush.c +1 -1
index 42ddbc529..6a156c5c5 100644
@@ -711,6 +711,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_gttfill.c +2 -2
index d6c8f2192..320b47001 100644
@@ -279,7 +279,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();
@@ -287,6 +287,6 @@ igt_main
 
 	igt_fixture {
 		intel_allocator_multiprocess_stop();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_latency.c +1 -1
index 4838a7082..d344db05e 100644
@@ -971,6 +971,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 497f57f08..77c3aea54 100644
@@ -1083,6 +1083,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 +1 -1
index 705b22cb9..8c82abdd7 100644
@@ -364,6 +364,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 d0805d330..80024fb3d 100644
@@ -646,6 +646,6 @@ igt_main
 	igt_fixture {
 		gem_close(fd, handle);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_reloc.c +1 -1
index 3ce89ca64..bcaffd1d9 100644
@@ -1178,5 +1178,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_exec_schedule.c +1 -1
index ab1dd7749..a12db4df2 100644
@@ -3369,6 +3369,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 7d23bcd5b..6bf392bd2 100644
@@ -455,6 +455,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 8d56093fa..2295ed04c 100644
@@ -411,6 +411,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 +1 -1
index 29d96cdca..08cc7f78a 100644
@@ -660,6 +660,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 fb11fb925..365b9b005 100644
@@ -381,6 +381,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 a6463685e..717422951 100644
@@ -69,5 +69,5 @@ igt_simple_main
 
 	igt_waitchildren();
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_fence_thrash.c +2 -1
index 89a5ae29d..348100476 100644
@@ -225,7 +225,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;
 }
@@ -252,4 +252,5 @@ igt_main
 
 	igt_subtest("bo-copy")
 		igt_assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0);
+
 }
tests/i915/gem_fenced_exec_thrash.c +1 -1
index a9597d801..03ba200a7 100644
@@ -199,5 +199,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 +5 -2
index 2620bc55d..9a014eb07 100644
@@ -147,7 +147,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 */
@@ -156,7 +156,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
@@ -188,4 +188,7 @@ igt_main
 	igt_describe("Tests flink lifetime by referencing from multiple descriptors.");
 	igt_subtest("flink-lifetime")
 		test_flink_lifetime(fd);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_flink_race.c +3 -3
index 70e133d70..c167e5789 100644
@@ -127,7 +127,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)
@@ -188,13 +188,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 8000e58cc..5f0a19b8b 100644
@@ -105,5 +105,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 15a6139ea..c365f1196 100644
@@ -164,7 +164,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 272091fdb..d142b1cf7 100644
@@ -515,5 +515,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 ea32b705a..9c31eeaea 100644
@@ -139,6 +139,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 71a066de3..6fd596feb 100644
@@ -93,7 +93,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();
@@ -132,7 +132,7 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 		igt_i915_driver_unload();
 	}
 }
tests/i915/gem_lmem_swapping.c +2 -2
index 55b044ecd..c4e0fc3be 100644
@@ -736,7 +736,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();
@@ -781,7 +781,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 2502d84c7..c141d208d 100644
@@ -77,7 +77,7 @@ dontneed_before_mmap(void)
 					PROT_READ | PROT_WRITE,
 					t->type);
 
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -99,7 +99,7 @@ dontneed_before_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -123,7 +123,7 @@ dontneed_after_mmap(void)
 					t->type);
 
 		gem_madvise(fd, handle, I915_MADV_DONTNEED);
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -145,7 +145,7 @@ dontneed_after_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -161,7 +161,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
@@ -185,7 +185,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 e418047c2..127d7e3a6 100644
@@ -173,6 +173,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 61f862a8e..053c9ed4c 100644
@@ -315,5 +315,5 @@ igt_main
 		test_huge_bo(2);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_gtt.c +1 -1
index c14ab50ee..a92f42dc1 100644
@@ -1492,5 +1492,5 @@ igt_main
 
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_offset.c +1 -1
index 962fc1b73..1d236f6d0 100644
@@ -926,6 +926,6 @@ igt_main
 		blt_coherency(i915);
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_mmap_wc.c +1 -1
index 6dc7bae49..9fc26593e 100644
@@ -620,5 +620,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 474149d48..affce4ee6 100644
@@ -326,6 +326,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 59959a374..8e9af5088 100644
@@ -183,6 +183,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ppgtt.c +4 -4
index c3102857a..09b4c6acc 100644
@@ -251,8 +251,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
@@ -385,7 +385,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;
 }
@@ -398,7 +398,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 a8bf2b054..e76dbce1f 100644
@@ -350,6 +350,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 3b56f787a..d5d20f58d 100644
@@ -252,5 +252,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_pwrite.c +1 -1
index 6e3f833cd..353ce1a01 100644
@@ -572,5 +572,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 e6a10747d..8883b2737 100644
@@ -140,5 +140,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 2f27abd58..a4209945f 100644
@@ -1293,6 +1293,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_read_read_speed.c +1 -1
index 7c5c90f79..9e84c7a27 100644
@@ -214,6 +214,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_readwrite.c +1 -1
index 2d437dec3..6a24d74ec 100644
@@ -143,5 +143,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_reg_read.c +1 -1
index 79facc1f2..302aa82ab 100644
@@ -170,6 +170,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_render_copy.c +1 -1
index 2c150b2b0..0eaa10754 100644
@@ -879,6 +879,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 5e1daccf1..dd7917413 100644
@@ -81,7 +81,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 +1 -1
index 7b003d88b..9bc7c803d 100644
@@ -999,6 +999,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 afcd7b73e..b0641b483 100644
@@ -401,6 +401,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 5e3bf6a12..7148c9d18 100644
@@ -261,6 +261,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 2f890e83b..4ebf17dcb 100644
@@ -130,5 +130,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 6bec7f27e..170195e47 100644
@@ -99,5 +99,5 @@ igt_simple_main
 
 	munmap(ptr, OBJECT_SIZE);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_shrink.c +7 -7
index 380d2c846..a104c9f3a 100644
@@ -270,7 +270,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;
 }
@@ -319,7 +319,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);
 			}
 		}
 	}
@@ -331,7 +331,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;
@@ -344,7 +344,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;
@@ -356,7 +356,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();
@@ -399,7 +399,7 @@ static void reclaim(unsigned engine, int timeout)
 
 	munmap((void *)shared, 4096);
 	close(debugfs);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -456,7 +456,7 @@ igt_main
 			 num_processes, alloc_size);
 
 		alloc_size <<= 20;
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("reclaim")
tests/i915/gem_softpin.c +1 -1
index 8717860b2..0cf33208f 100644
@@ -1531,6 +1531,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 7dc68ebc7..68e7af7e3 100644
@@ -277,6 +277,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 883fe4293..a8e6c42a8 100644
@@ -419,5 +419,5 @@ igt_main
 		test_batch(fd, 2, 1);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_stress.c +1 -1
index 3765ab14b..23690c077 100644
@@ -926,7 +926,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 e7dc6637a..18adbd19d 100644
@@ -1363,6 +1363,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 5e7ed0c4e..0f8434d7f 100644
@@ -215,6 +215,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_fence_blits.c +1 -1
index a3a0221d6..8e908eac0 100644
@@ -320,5 +320,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_partial_pwrite_pread.c +1 -1
index 95fb69c65..ecc97002e 100644
@@ -318,6 +318,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 2b4cec6e7..48f5c67e1 100644
@@ -222,5 +222,5 @@ igt_simple_main
 		}
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_pread_pwrite.c +1 -1
index 2d21dfb76..885785cab 100644
@@ -154,5 +154,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 f4bdce738..718516def 100644
@@ -246,5 +246,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_wb.c +1 -1
index e9efbdf23..b2337806d 100644
@@ -239,5 +239,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 1f245eb7d..4f733163b 100644
@@ -243,5 +243,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 513d579d3..d326ae7c2 100644
@@ -138,5 +138,5 @@ igt_simple_main
 
 	munmap(ptr, size);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_unfence_active_buffers.c +1 -1
index a0a601de2..71686095d 100644
@@ -99,5 +99,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 735c14720..9d92156a1 100644
@@ -121,5 +121,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
-	close(i915);
+	drm_close_driver(i915);
 }
tests/i915/gem_userptr_blits.c +5 -2
index b00afc32c..381f1b6d9 100644
@@ -1288,9 +1288,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;
@@ -2703,4 +2703,7 @@ igt_main_args("c:", NULL, help_str, opt_handler, NULL)
 		igt_require(has_userptr_probe(fd));
 		test_probe(fd);
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_vm_create.c +1 -1
index f47d8c556..9c5085206 100644
@@ -388,6 +388,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_wait.c +1 -1
index 27d084afa..a33e461d8 100644
@@ -257,6 +257,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_watchdog.c +1 -1
index 27f3a2d7f..18957cee3 100644
@@ -586,6 +586,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_workarounds.c +3 -0
index 7d1199625..b0268e01a 100644
@@ -339,4 +339,7 @@ igt_main
 			}
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(device);
 }
tests/i915/gen7_exec_parse.c +2 -2
index e9751ea73..895aea1ea 100644
@@ -445,7 +445,7 @@ static void hsw_load_register_reg(void)
 				   0xabcdabc0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -717,6 +717,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 26b151705..e7d47fccc 100644
@@ -1252,6 +1252,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 cafa5233c..f3f0c3d0a 100644
@@ -44,5 +44,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 5422d585f..b6988784d 100644
@@ -46,7 +46,7 @@ init(void)
 static void
 deinit(void)
 {
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 
tests/i915/i915_hangman.c +2 -2
index dd396c4e9..d8c9ec0ef 100644
@@ -97,7 +97,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)
@@ -580,6 +580,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 6d9937e99..4b7ecb766 100644
@@ -83,6 +83,6 @@ igt_main
 
 	igt_fixture {
 		close(hwm);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_module_load.c +4 -4
index 725687dab..057c68906 100644
@@ -238,7 +238,7 @@ static void gem_sanitycheck(void)
 		store_all(i915);
 	errno = 0;
 
-	close(i915);
+	drm_close_driver(i915);
 	igt_assert_eq(err, expected);
 }
 
@@ -286,7 +286,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();
@@ -327,7 +327,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;
 }
@@ -419,7 +419,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 377eec58c..9da7dc074 100644
@@ -65,5 +65,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 829606622..0bdb98f3f 100644
@@ -332,6 +332,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 6f08cb3fc..859bfdc55 100644
@@ -689,7 +689,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 662d514a4..096adbbb5 100644
@@ -139,6 +139,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 894ae294c..825f5a326 100644
@@ -167,6 +167,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_lpsp.c +1 -1
index 3ad8b2603..fc4404c9b 100644
@@ -211,6 +211,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 3554f5d77..0fac22770 100644
@@ -611,6 +611,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_rps.c +4 -1
index d4ee2d58a..34abfe690 100644
@@ -877,7 +877,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
@@ -959,4 +959,7 @@ igt_main
 		waitboost(drm_fd, true);
 		igt_disallow_hang(drm_fd, hang);
 	}
+
+	igt_fixture
+		drm_close_driver(drm_fd);
 }
tests/i915/i915_pm_sseu.c +1 -1
index 1b428c9ba..771971851 100644
@@ -315,7 +315,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 51b412e3a..9f6235083 100644
@@ -76,6 +76,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_query.c +1 -1
index e725e04e4..ea191f8a3 100644
@@ -1465,6 +1465,6 @@ igt_main
 		query_parse_and_validate_hwconfig_table(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_suspend.c +2 -2
index a9507964b..1961d85f1 100644
@@ -232,7 +232,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);
@@ -315,5 +315,5 @@ igt_main
 		test_forcewake(fd, true);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/kms_big_fb.c +1 -1
index a0d5ef730..d132f5b98 100644
@@ -1010,6 +1010,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 20d3058fb..74af9229e 100644
@@ -506,6 +506,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 	igt_fixture {
 		gpu_engines_restore_timeouts(fd, num_engines, saved_gpu_timeouts);
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/i915/kms_ccs.c +1 -1
index 1b3462ea9..2661f661c 100644
@@ -708,6 +708,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 c4dfc9251..87aceb1e3 100644
@@ -257,6 +257,6 @@ igt_main
 
 	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 831ec867a..aea724756 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 63657a742..c8a6f1aa1 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 650e14a77..075e3827b 100644
@@ -1351,7 +1351,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 -2
index bc51975f6..77e1cc807 100644
@@ -303,9 +303,8 @@ 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);
-		close(data.drm_fd);
 	}
 }
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 0e8d7f4f0..0ef5f1e82 100644
@@ -639,6 +639,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 4cf986440..a202c613c 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/i915/perf.c +2 -2
index 9ca4d34b6..760c8d692 100644
@@ -5299,7 +5299,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;
@@ -6008,6 +6008,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 c5f083bbd..34b0e10f6 100644
@@ -2111,7 +2111,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);
@@ -2436,13 +2436,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 dda27a0af..94437c0a0 100644
@@ -105,6 +105,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_heartbeat_interval.c +1 -1
index 8a3dd3975..467e0728b 100644
@@ -514,6 +514,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_preempt_timeout.c +1 -1
index 5e0a7d962..b686d6ba8 100644
@@ -343,6 +343,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_timeslice_duration.c +1 -1
index 92c4c5eae..8f0d8d94b 100644
@@ -564,6 +564,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
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 e4783624f..1e5d834ce 100644
@@ -795,7 +795,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);
 	}
@@ -874,6 +874,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 51ffa523a..f44fc4bea 100644
@@ -668,6 +668,6 @@ igt_main_args("e", NULL, help_str, opt_handler, &data)
 		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 fdc7120c7..d444cfe10 100644
@@ -1069,6 +1069,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 3a353a032..d9ae35587 100644
@@ -1010,6 +1010,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 7df6a6125..69e52a864 100644
@@ -1803,6 +1803,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_dp_tiled_display.c +1 -1
index 07b803a50..8dfe93000 100644
@@ -502,6 +502,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_flip.c +1 -1
index e4c98b8ec..8d6a8e74d 100755
@@ -1898,6 +1898,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 f1508efba..d1e516562 100644
@@ -60,7 +60,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)
@@ -386,7 +386,7 @@ end:
 
 	igt_fixture {
 		drmModeFreeConnector(connector);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 
 		reset_connectors();
 	}
tests/kms_getfb.c +2 -2
index 4adc7eee2..3cb568808 100644
@@ -452,7 +452,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);
 	}
 }
 
@@ -484,6 +484,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 81a32dbf8..d47a1977c 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 ec0483055..6059f1f8f 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 65afc9f60..9a354fcfe 100644
@@ -433,6 +433,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 10e16b638..8e0cd2129 100644
@@ -1318,6 +1318,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 a37abd16d..61d0f8c89 100644
@@ -1323,6 +1323,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 96aa6d8d6..d9a5992e4 100644
@@ -178,7 +178,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);
@@ -206,7 +206,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);
@@ -217,7 +217,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);
@@ -338,5 +338,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 28b4fd27c..f0d8b1172 100644
@@ -1279,6 +1279,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_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);
 	}
 }
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);
 	}
 }
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);
+	}
 }
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);
         }
 }
tests/prime_busy.c +1 -1
index 343020f13..f9f1674d4 100644
@@ -162,6 +162,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap.c +1 -1
index bc19f68c9..1c2d2a301 100644
@@ -557,6 +557,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 b22fb35c1..a18c16c5c 100644
@@ -249,7 +249,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);
 }
 
 /*
@@ -346,6 +346,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 bf5486194..0b5ac256d 100644
@@ -106,8 +106,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)
@@ -139,8 +139,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)
@@ -164,8 +164,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);
 }
@@ -211,7 +211,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);
 }
 
@@ -275,14 +275,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);
 }
@@ -357,13 +357,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);
 }
@@ -392,7 +392,7 @@ static void test_llseek_size(void)
 		close(dma_buf_fd);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_llseek_bad(void)
@@ -421,7 +421,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 9aa767c9c..9bd22641c 100644
@@ -1249,7 +1249,7 @@ igt_main
 
 
 	igt_fixture {
-		close(i915);
-		close(vgem);
+		drm_close_driver(i915);
+		drm_close_driver(vgem);
 	}
 }
tests/syncobj_basic.c +1 -1
index 6e20c3411..beb44b1e9 100644
@@ -232,7 +232,7 @@ igt_main
 		test_valid_cycle(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 }
tests/syncobj_timeline.c +1 -1
index 7f5ff6f6c..081f440f3 100644
@@ -1538,6 +1538,6 @@ igt_main
 		test_32bits_limit(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/syncobj_wait.c +1 -1
index 427b6b119..eebc96b67 100644
@@ -914,6 +914,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/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/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);
 	}
 }
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);
 }
tests/vgem_basic.c +3 -3
index ada5518d7..36899b307 100644
@@ -64,8 +64,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)
@@ -537,6 +537,6 @@ igt_main
 		test_debugfs_read(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/vgem_slow.c +1 -1
index 58b09e421..4c4e94ea0 100644
@@ -85,6 +85,6 @@ igt_main
 		test_nohang(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
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);
 	}
 }
tests/xe/xe_compute.c +1 -1
index 7ac64dfe3..5e6cd8529 100644
@@ -45,6 +45,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_create.c +1 -1
index ae841f809..b3d9fd49f 100644
@@ -102,6 +102,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_debugfs.c +1 -1
index 6bdd3ef06..4006981c6 100644
@@ -270,6 +270,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 8920b141b..81ece2428 100644
@@ -220,7 +220,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]);
 	}
 
 }
@@ -257,6 +257,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_evict.c +3 -3
index 5687cce30..14a2d19f1 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 {
@@ -701,5 +701,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/xe/xe_exec_balancer.c +1 -1
index 2018c8104..fb4592903 100644
@@ -708,6 +708,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_basic.c +1 -1
index 2a176a5b3..d14a764f4 100644
@@ -353,6 +353,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 685193990..950cb6159 100644
@@ -361,6 +361,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 a3ab17270..8cd883c09 100644
@@ -570,6 +570,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_reset.c +4 -4
index 0d72a3f20..3700b8dce 100644
@@ -294,7 +294,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;
@@ -475,7 +475,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;
@@ -655,7 +655,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;
@@ -946,6 +946,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_threads.c +4 -4
index 3f2c2de9e..bde92a9c5 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);
 	}
 }
 
@@ -454,7 +454,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);
 	}
 }
 
@@ -698,7 +698,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);
 	}
 }
 
@@ -1403,6 +1403,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_guc_pc.c +1 -1
index 5c71ae147..56d4f9190 100644
@@ -496,6 +496,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 35d61608e..f43beb1a8 100644
@@ -1180,6 +1180,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 6b313a189..352cbcab4 100644
@@ -77,6 +77,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_mmio.c +1 -1
index 42b6241b1..77a38b8d1 100644
@@ -89,6 +89,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_module_load.c +1 -1
index c2d43cc20..16432c78f 100644
@@ -86,7 +86,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 367671883..f276e694c 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 44154143c..7bec294ed 100644
@@ -441,6 +441,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 4e8fd5d4f..a86d0e9f2 100644
@@ -122,9 +122,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);
 }
 
 /**
@@ -202,9 +202,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);
 }
@@ -259,10 +259,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)
@@ -335,7 +335,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 */
@@ -343,7 +343,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);
 }
@@ -429,7 +429,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;
@@ -437,7 +437,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);
 }
@@ -474,7 +474,7 @@ static void test_llseek_size(void)
 	}
 
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 /**
@@ -511,7 +511,7 @@ static void test_llseek_bad(void)
 	close(dma_buf_fd);
 
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -544,6 +544,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_query.c +1 -1
index 87990370f..1c06534d4 100644
@@ -491,6 +491,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_vm.c +1 -1
index d4cec104e..9015a5a57 100644
@@ -1839,6 +1839,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_waitfence.c +1 -1
index cdfcacdb4..8bfb741f6 100644
@@ -98,6 +98,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#19 lore raw

Re: [igt-dev] [i-g-t V2 5/6] tests: Use drm_close_driver() to close the drm fd

Hi Bhanuprakash,

Quoted 3 lines · Bhanuprakash Modem

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

What changed in v2 ? Please describe it here like:

v2: added/corrected/changed description

Add here e-mails for cc, like:

Cc Janga Rahul Kumar <[email protected]>
Quoted 1 line

Please use checkpatch.pl to correct some whitespace errors or if they are already there do not correct them in this patch, that should go in some other trivial one.

Please also look at lib/igt_types.c and add there also xe_device_put if fd is xe device.

Quoted 2 lines
---
 lib/igt_msm.c                               |  2 +-

---------- ^
Non-related arch.

Quoted 1 line
 tests/amdgpu/amd_abm.c                      |  1 +

-------- ^
Non-related arch.

If you are changing some other archs you should also Cc: developers or maybe if it is used only for intel/Xe just do it in few more patches, one for each arch ? In that case you could Cc: only to respective dev of given architecture. These Cc: should be also placed in patch before your s-o-b.

Quoted 4 lines
 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 +-
Quoted 8 lines
 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                      |  4 +--
 tests/amdgpu/amd_vrr_range.c                |  1 +
 tests/chamelium/kms_chamelium_audio.c       |  2 +-

-------- ^
These should stay.

Quoted 8 lines
 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 ++---
Quoted 8 lines
 tests/core_setmaster_vs_auth.c              |  6 ++---
 tests/debugfs_test.c                        |  2 +-
 tests/dmabuf_sync_file.c                    |  3 +++
 tests/drm_read.c                            |  3 +++
 tests/dumb_buffer.c                         |  2 +-
 tests/eviction_common.c                     |  2 +-
 tests/fbdev.c                               |  2 +-
 tests/i915/api_intel_allocator.c            |  2 +-

-------- ^
This can also go in separate patchset as i915 is not Xe device. Btw some of them are fixes, there are no close(fd) there, so maybe that should be yet another patch with fixing exit without close.

Quoted 187 lines
 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               |  3 +++
 tests/i915/gem_basic.c                      |  5 +++-
 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_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                 |  2 +-
 tests/i915/gem_ctx_engines.c                |  4 ++-
 tests/i915/gem_ctx_exec.c                   |  3 +++
 tests/i915/gem_ctx_freq.c                   |  3 +++
 tests/i915/gem_ctx_param.c                  |  2 +-
 tests/i915/gem_ctx_persistence.c            |  2 +-
 tests/i915/gem_ctx_shared.c                 |  3 +++
 tests/i915/gem_ctx_sseu.c                   |  2 +-
 tests/i915/gem_ctx_switch.c                 |  2 +-
 tests/i915/gem_eio.c                        |  3 +++
 tests/i915/gem_evict_alignment.c            |  2 +-
 tests/i915/gem_evict_everything.c           |  2 +-
 tests/i915/gem_exec_alignment.c             |  3 +++
 tests/i915/gem_exec_async.c                 |  2 +-
 tests/i915/gem_exec_await.c                 |  2 +-
 tests/i915/gem_exec_balancer.c              |  3 +++
 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_endless.c               |  3 +++
 tests/i915/gem_exec_fair.c                  |  2 +-
 tests/i915/gem_exec_fence.c                 |  2 +-
 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              |  2 +-
 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               |  2 +-
 tests/i915/gem_exercise_blt.c               |  2 +-
 tests/i915/gem_fd_exhaustion.c              |  2 +-
 tests/i915/gem_fence_thrash.c               |  3 ++-
 tests/i915/gem_fenced_exec_thrash.c         |  2 +-
 tests/i915/gem_flink_basic.c                |  7 +++--
 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              |  4 +--
 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                   |  2 +-
 tests/i915/gem_mmap_offset.c                |  2 +-
 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                |  2 +-
 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                    |  2 +-
 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              |  7 +++--
 tests/i915/gem_vm_create.c                  |  2 +-
 tests/i915/gem_wait.c                       |  2 +-
 tests/i915/gem_watchdog.c                   |  2 +-
 tests/i915/gem_workarounds.c                |  3 +++
 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                   |  4 +--
 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                           |  4 +--
 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                              |  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_dp_tiled_display.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 +-
Quoted 8 lines
 tests/kms_sequence.c                        |  2 +-
 tests/kms_setmode.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 +++--

-------- ^
Non-related arch.

Quoted 1 line
 tests/panfrost_gem_new.c                    |  4 +--

-------- ^
Non-related arch.

Quoted 7 lines
 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 +-
Quoted 8 lines
 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 +--

-------- ^
Non-related arch.

Quoted 9 lines
 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 +--

-------- ^
Non-related arch.

Quoted 4 lines
 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 +-
Quoted 8 lines
 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 +-

-------- ^
Non-related arch.

Quoted 173 lines
 tests/vmwgfx/vmw_ref_count.c                |  4 +--
 tests/vmwgfx/vmw_surface_copy.c             |  2 +-
 tests/xe/xe_compute.c                       |  2 +-
 tests/xe/xe_create.c                        |  2 +-
 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_vm.c                            |  2 +-
 tests/xe/xe_waitfence.c                     |  2 +-
 287 files changed, 435 insertions(+), 374 deletions(-)
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);
 }
 
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_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_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_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_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_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);
 	}
 }
tests/amdgpu/amd_psr.c +0 -0
index 966a0dccf..bca3c6449 100644

tests/amdgpu/amd_psr.c static void run_check_psr_su_cursor(data_t *data, bool test_mpo) · line 643

Quoted 5 lines
tests/amdgpu/amd_psr.c +1 -1
@@ -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)
-	 */ 
+	 */

Do not make unrelated changes.

tests/amdgpu/amd_psr.c igt_main_args("", long_options, help_str, opt_handler, NULL) · line 764

Quoted 8 lines
tests/amdgpu/amd_psr.c +0 -1
 	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]);
@@ -761,7 +761,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 			igt_require_f(igt_amd_set_visual_confirm(data.fd, VISUAL_CONFIRM_DISABLE),
 				      "reset PSR visual confirm option failed\n");
 		}
-		close(data.debugfs_fd);

This is debugfs fd, not drm one.

Quoted 100 lines
tests/amdgpu/amd_psr.c +1 -0
 		igt_display_fini(&data.display);
+		drm_close_driver(data.debugfs_fd);
 	}
 }
tests/amdgpu/amd_vrr_range.c +1 -0
index 2f27296dd..cacd668cd 100644
@@ -338,5 +338,6 @@ igt_main
 	igt_fixture
 	{
 		igt_display_fini(&data.display);
+		drm_close_driver(data.fd);
 	}
 }
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 7e7262ed3..a650efe16 100644
@@ -558,6 +558,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 008bc34b6..56c985b1a 100644
@@ -1080,6 +1080,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 2b17ce29d..f700673b3 100644
@@ -525,6 +525,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
-		close(data.drm_fd);
+		drm_close_driver(data.drm_fd);
 	}
 }
tests/core_auth.c +4 -4
index 257f12482..110163b00 100644
@@ -189,7 +189,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
@@ -201,7 +201,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.");
@@ -211,11 +211,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 227

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

Do not make unrelated changes.

Quoted 94 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 40a1c194d..9e53c46f9 100644
@@ -58,5 +58,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 fde27cdc6..c68b6b559 100644
@@ -52,5 +52,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 f6953b313..0c2949f18 100644
@@ -46,5 +46,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 470f9441d..30348dd62 100644
@@ -85,7 +85,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)
@@ -206,10 +206,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 0b4b8613c..da4662e0a 100644
@@ -66,7 +66,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 8c775158f..b45646d70 100644
@@ -213,6 +213,6 @@ igt_main
 	igt_fixture {
 		close(sysfs);
 		close(debugfs);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/dmabuf_sync_file.c +0 -0
index 25bb6ad75..cfa73117b 100644

tests/dmabuf_sync_file.c igt_main · line 385

Quoted 6 lines
tests/dmabuf_sync_file.c +3 -0
@@ -380,4 +380,7 @@ igt_main
 		     "operations.");
 	igt_subtest("import-multiple-read-write")
 		test_import_multiple(fd, true);
+
+	igt_fixture
+		drm_close_driver(fd);

This is a fix.

tests/drm_read.c igt_main · line 316

Quoted 12 lines
tests/dmabuf_sync_file.c +0 -0
 }
tests/drm_read.c +3 -0
index 36dc623ed..e989e7bfb 100644
@@ -311,4 +311,7 @@ igt_main
 
 	igt_subtest("short-buffer-wakeup")
 		test_short_buffer_wakeup(fd, pipe);
+
+	igt_fixture
+		drm_close_driver(fd);

This is a fix.

Quoted 228 lines
tests/drm_read.c +0 -0
 }
tests/dumb_buffer.c +1 -1
index ded6b809c..8aa320a59 100644
@@ -394,6 +394,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/i915/api_intel_allocator.c +1 -1
index e9039a214..83acc306f 100644
@@ -847,5 +847,5 @@ igt_main
 		gem_pool(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/api_intel_bb.c +1 -1
index 46633b038..da74e1ed3 100644
@@ -1701,6 +1701,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 1b1247553..c8437dc0b 100644
@@ -855,6 +855,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 478e78a66..fc1c6a574 100644
@@ -212,5 +212,5 @@ igt_main
 		negative_reloc_blt(fd);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_barrier_race.c +3 -0
index f446aab62..52f4eef39 100644
@@ -153,4 +153,7 @@ igt_main
 			break;
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_basic.c +4 -1
index 3dd790c6c..edcc6d443 100644
@@ -108,7 +108,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();
@@ -117,4 +117,7 @@ igt_main
 	igt_describe("Verify that closing drm driver is possible with opened gem object.");
 	igt_subtest("create-fd-close")
 		test_create_fd_close(fd);
+
+	igt_fixture
+		drm_close_driver(fd);
 }
tests/i915/gem_blits.c +1 -1
index 5fbb384db..5ac0bfdc3 100644
@@ -893,6 +893,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 08a500a9e..70ba1999f 100644
@@ -562,6 +562,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_caching.c +1 -1
index 6e944f0ac..16c594aa6 100644
@@ -340,6 +340,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 d25e00fc8..4a1ae094d 100644
@@ -731,6 +731,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 9c646f426..c1cbf0f90 100644
@@ -274,7 +274,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();
@@ -293,7 +293,7 @@ static void threads(int timeout, unsigned int flags)
 	igt_waitchildren();
 
 	gem_quiescent_gpu(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -317,7 +317,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.");
@@ -329,7 +329,7 @@ igt_main
 		igt_waitchildren();
 
 		gem_quiescent_gpu(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_describe("Basic workload submission on multi-GPU machine.");
@@ -342,7 +342,7 @@ igt_main
 			igt_assert(fd > 0);
 			process(fd, child);
 			gem_quiescent_gpu(fd);
-			close(fd);
+			drm_close_driver(fd);
 		}
 
 		igt_waitchildren();
@@ -369,7 +369,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_concurrent_all.c +0 -0
index 25b7daf86..e1351c368 100644

tests/i915/gem_concurrent_all.c igt_main · line 2022

Quoted 8 lines
tests/i915/gem_concurrent_all.c +5 -0
@@ -2015,4 +2015,9 @@ igt_main
 			}
 		}
 	}
+
+	igt_fixture {
+		drm_close_driver(fd);
+		drm_close_driver(vgem_drv);
+	}

This is a fix.

Quoted 40 lines
tests/i915/gem_concurrent_all.c +0 -0
 }
tests/i915/gem_cs_tlb.c +1 -1
index 2117b41e4..ff96e63ed 100644
@@ -162,5 +162,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_bad_destroy.c +1 -1
index 50bb9aa07..5dc6d040d 100644
@@ -80,5 +80,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_ctx_create.c +1 -1
index 39f070af9..f0ef447e3 100644
@@ -667,6 +667,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_engines.c +0 -0
index b87a21fa4..3daed16a0 100644

tests/i915/gem_ctx_engines.c igt_main · line 638

Quoted 7 lines
tests/i915/gem_ctx_engines.c +2 -1
@@ -633,6 +633,8 @@ igt_main
 			independent_all(i915, ctx);
 	}
 
-	igt_fixture
+	igt_fixture {
 		igt_stop_hang_detector();
+		drm_close_driver(i915);

This is a fix.

tests/i915/gem_ctx_exec.c igt_main · line 551

Quoted 13 lines
tests/i915/gem_ctx_engines.c +1 -0
+	}
 }
tests/i915/gem_ctx_exec.c +3 -0
index 3d94f01db..ec36f0040 100644
@@ -546,4 +546,7 @@ igt_main
 		gem_context_destroy(fd, ctx_id);
 		put_ahnd(ahnd);
 	}
+
+	igt_fixture
+		drm_close_driver(fd);

This is a fix.

tests/i915/gem_ctx_freq.c igt_main · line 218

Quoted 12 lines
tests/i915/gem_ctx_exec.c +0 -0
 }
tests/i915/gem_ctx_freq.c +3 -0
index 18e736c73..ce4c0ba55 100644
@@ -213,4 +213,7 @@ igt_main
 
 	igt_subtest_f("sysfs")
 		sysfs_range(i915);
+
+	igt_fixture
+		drm_close_driver(i915);

This is a fix.

Quoted 29 lines
tests/i915/gem_ctx_freq.c +0 -0
 }
tests/i915/gem_ctx_param.c +1 -1
index d119ea74e..6fa2e6161 100644
@@ -473,5 +473,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 +1 -1
index 9fb528186..fabb41e66 100644
@@ -1383,6 +1383,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_ctx_shared.c +0 -0
index 3d73db581..e7006f55f 100644

tests/i915/gem_ctx_shared.c igt_main · line 1093

Quoted 6 lines
tests/i915/gem_ctx_shared.c +3 -0
@@ -1088,4 +1088,7 @@ igt_main
 			igt_stop_hang_detector();
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(i915);

This is a fix.

Quoted 30 lines
tests/i915/gem_ctx_shared.c +0 -0
 }
tests/i915/gem_ctx_sseu.c +1 -1
index 7685511f0..dcc38ae17 100644
@@ -545,6 +545,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ctx_switch.c +1 -1
index 4e46b7634..f675570ec 100644
@@ -440,6 +440,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 +0 -0
index 8dbaa7a75..80eca558f 100644

tests/i915/gem_eio.c igt_main · line 1131

Quoted 6 lines
tests/i915/gem_eio.c +3 -0
@@ -1126,4 +1126,7 @@ igt_main
 			intel_allocator_multiprocess_stop();
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(fd);

This is a fix.

Quoted 30 lines
tests/i915/gem_eio.c +0 -0
 }
tests/i915/gem_evict_alignment.c +1 -1
index 0b560ab03..7a40b0128 100644
@@ -265,6 +265,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_evict_everything.c +1 -1
index 120f89072..d5d464889 100644
@@ -290,6 +290,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_helper();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_alignment.c +0 -0
index a9fcd2a74..3084da5fc 100644

tests/i915/gem_exec_alignment.c igt_main · line 551

Quoted 6 lines
tests/i915/gem_exec_alignment.c +3 -0
@@ -546,4 +546,7 @@ igt_main
 		prio_inversion(fd, SHARED);
 	igt_subtest("pi-isolated")
 		prio_inversion(fd, ISOLATED);
+
+	igt_fixture
+		drm_close_driver(fd);

This is a fix.

Quoted 30 lines
tests/i915/gem_exec_alignment.c +0 -0
 }
tests/i915/gem_exec_async.c +1 -1
index 173bc4648..6895b9c6c 100644
@@ -213,6 +213,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 4935cf395..0fd8cbf67 100644
@@ -287,6 +287,6 @@ igt_main
 	igt_fixture {
 		igt_stop_hang_detector();
 		intel_ctx_destroy(device, ctx);
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_balancer.c +0 -0
index 1c655e583..df16f8bec 100644

tests/i915/gem_exec_balancer.c igt_main · line 3487

Quoted 6 lines
tests/i915/gem_exec_balancer.c +3 -0
@@ -3482,4 +3482,7 @@ igt_main
 		igt_subtest("nohangcheck")
 			nohangcheck(i915);
 	}
+
+	igt_fixture
+		drm_close_driver(i915);

This is a fix.

Quoted 53 lines
tests/i915/gem_exec_balancer.c +0 -0
 }
tests/i915/gem_exec_basic.c +1 -1
index ca4fc7b96..c018d4089 100644
@@ -98,6 +98,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 4619bda81..5a8df7264 100644
@@ -326,5 +326,5 @@ igt_main
 		exhaustive(i915);
 
 	igt_fixture
-		close(i915);
+		drm_close_driver(i915);
 }
tests/i915/gem_exec_capture.c +1 -1
index 9c391192d..56f5c6ba8 100644
@@ -1013,6 +1013,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 449aa5b2e..8ca564b09 100644
@@ -225,6 +225,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(device);
+		drm_close_driver(device);
 	}
 }
tests/i915/gem_exec_endless.c +0 -0
index 77719de83..f895c6783 100644

tests/i915/gem_exec_endless.c igt_main · line 372

Quoted 6 lines
tests/i915/gem_exec_endless.c +3 -0
@@ -367,4 +367,7 @@ igt_main
 			intel_register_access_fini(&mmio);
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(i915);

This is a fix.

Quoted 241 lines
tests/i915/gem_exec_endless.c +0 -0
 }
tests/i915/gem_exec_fair.c +1 -1
index 8208ab404..916686b55 100644
@@ -1348,6 +1348,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_fence.c +1 -1
index c2d874f84..799995865 100644
@@ -3351,6 +3351,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_flush.c +1 -1
index 42ddbc529..6a156c5c5 100644
@@ -711,6 +711,6 @@ igt_main
 
 	igt_fixture {
 		igt_stop_hang_detector();
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_gttfill.c +2 -2
index d6c8f2192..320b47001 100644
@@ -279,7 +279,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();
@@ -287,6 +287,6 @@ igt_main
 
 	igt_fixture {
 		intel_allocator_multiprocess_stop();
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_exec_latency.c +1 -1
index 4838a7082..d344db05e 100644
@@ -971,6 +971,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 497f57f08..77c3aea54 100644
@@ -1083,6 +1083,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 +1 -1
index 705b22cb9..8c82abdd7 100644
@@ -364,6 +364,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 d0805d330..80024fb3d 100644
@@ -646,6 +646,6 @@ igt_main
 	igt_fixture {
 		gem_close(fd, handle);
 
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_exec_reloc.c +1 -1
index 3ce89ca64..bcaffd1d9 100644
@@ -1178,5 +1178,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_exec_schedule.c +1 -1
index ab1dd7749..a12db4df2 100644
@@ -3369,6 +3369,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 7d23bcd5b..6bf392bd2 100644
@@ -455,6 +455,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 8d56093fa..2295ed04c 100644
@@ -411,6 +411,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 +1 -1
index 29d96cdca..08cc7f78a 100644
@@ -660,6 +660,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 fb11fb925..365b9b005 100644
@@ -381,6 +381,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 a6463685e..717422951 100644
@@ -69,5 +69,5 @@ igt_simple_main
 
 	igt_waitchildren();
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_fence_thrash.c +2 -1
index 89a5ae29d..348100476 100644
@@ -225,7 +225,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;
 }
@@ -252,4 +252,5 @@ igt_main
 
 	igt_subtest("bo-copy")
 		igt_assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0);
+
 }
tests/i915/gem_fenced_exec_thrash.c +1 -1
index a9597d801..03ba200a7 100644
@@ -199,5 +199,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 2620bc55d..9a014eb07 100644
@@ -147,7 +147,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 */
@@ -156,7 +156,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_basic.c igt_main · line 193

Quoted 6 lines
tests/i915/gem_flink_basic.c +3 -0
@@ -188,4 +188,7 @@ igt_main
 	igt_describe("Tests flink lifetime by referencing from multiple descriptors.");
 	igt_subtest("flink-lifetime")
 		test_flink_lifetime(fd);
+
+	igt_fixture
+		drm_close_driver(fd);

This is a fix.

Quoted 735 lines
tests/i915/gem_flink_basic.c +0 -0
 }
tests/i915/gem_flink_race.c +3 -3
index 70e133d70..c167e5789 100644
@@ -127,7 +127,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)
@@ -188,13 +188,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 8000e58cc..5f0a19b8b 100644
@@ -105,5 +105,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 15a6139ea..c365f1196 100644
@@ -164,7 +164,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 272091fdb..d142b1cf7 100644
@@ -515,5 +515,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 ea32b705a..9c31eeaea 100644
@@ -139,6 +139,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 71a066de3..6fd596feb 100644
@@ -93,7 +93,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();
@@ -132,7 +132,7 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 		igt_i915_driver_unload();
 	}
 }
tests/i915/gem_lmem_swapping.c +2 -2
index 55b044ecd..c4e0fc3be 100644
@@ -736,7 +736,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();
@@ -781,7 +781,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 2502d84c7..c141d208d 100644
@@ -77,7 +77,7 @@ dontneed_before_mmap(void)
 					PROT_READ | PROT_WRITE,
 					t->type);
 
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -99,7 +99,7 @@ dontneed_before_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -123,7 +123,7 @@ dontneed_after_mmap(void)
 					t->type);
 
 		gem_madvise(fd, handle, I915_MADV_DONTNEED);
-		close(fd);
+		drm_close_driver(fd);
 		if (!ptr)
 			continue;
 
@@ -145,7 +145,7 @@ dontneed_after_mmap(void)
 		fd = drm_open_driver(DRIVER_INTEL);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void
@@ -161,7 +161,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
@@ -185,7 +185,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 e418047c2..127d7e3a6 100644
@@ -173,6 +173,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 61f862a8e..053c9ed4c 100644
@@ -315,5 +315,5 @@ igt_main
 		test_huge_bo(2);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_gtt.c +1 -1
index c14ab50ee..a92f42dc1 100644
@@ -1492,5 +1492,5 @@ igt_main
 
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_mmap_offset.c +1 -1
index 962fc1b73..1d236f6d0 100644
@@ -926,6 +926,6 @@ igt_main
 		blt_coherency(i915);
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_mmap_wc.c +1 -1
index 6dc7bae49..9fc26593e 100644
@@ -620,5 +620,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 474149d48..affce4ee6 100644
@@ -326,6 +326,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 59959a374..8e9af5088 100644
@@ -183,6 +183,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_ppgtt.c +4 -4
index c3102857a..09b4c6acc 100644
@@ -251,8 +251,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
@@ -385,7 +385,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;
 }
@@ -398,7 +398,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 a8bf2b054..e76dbce1f 100644
@@ -350,6 +350,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 3b56f787a..d5d20f58d 100644
@@ -252,5 +252,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_pwrite.c +1 -1
index 6e3f833cd..353ce1a01 100644
@@ -572,5 +572,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 e6a10747d..8883b2737 100644
@@ -140,5 +140,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 2f27abd58..a4209945f 100644
@@ -1293,6 +1293,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_read_read_speed.c +1 -1
index 7c5c90f79..9e84c7a27 100644
@@ -214,6 +214,6 @@ igt_main
 
 	igt_fixture {
 		buf_ops_destroy(bops);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_readwrite.c +1 -1
index 2d437dec3..6a24d74ec 100644
@@ -143,5 +143,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_reg_read.c +1 -1
index 79facc1f2..302aa82ab 100644
@@ -170,6 +170,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_render_copy.c +1 -1
index 2c150b2b0..0eaa10754 100644
@@ -879,6 +879,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 5e1daccf1..dd7917413 100644
@@ -81,7 +81,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 +1 -1
index 7b003d88b..9bc7c803d 100644
@@ -999,6 +999,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 afcd7b73e..b0641b483 100644
@@ -401,6 +401,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 5e3bf6a12..7148c9d18 100644
@@ -261,6 +261,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 2f890e83b..4ebf17dcb 100644
@@ -130,5 +130,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 6bec7f27e..170195e47 100644
@@ -99,5 +99,5 @@ igt_simple_main
 
 	munmap(ptr, OBJECT_SIZE);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_shrink.c +7 -7
index 380d2c846..a104c9f3a 100644
@@ -270,7 +270,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;
 }
@@ -319,7 +319,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);
 			}
 		}
 	}
@@ -331,7 +331,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;
@@ -344,7 +344,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;
@@ -356,7 +356,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();
@@ -399,7 +399,7 @@ static void reclaim(unsigned engine, int timeout)
 
 	munmap((void *)shared, 4096);
 	close(debugfs);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -456,7 +456,7 @@ igt_main
 			 num_processes, alloc_size);
 
 		alloc_size <<= 20;
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 	igt_subtest("reclaim")
tests/i915/gem_softpin.c +1 -1
index 8717860b2..0cf33208f 100644
@@ -1531,6 +1531,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 7dc68ebc7..68e7af7e3 100644
@@ -277,6 +277,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 883fe4293..a8e6c42a8 100644
@@ -419,5 +419,5 @@ igt_main
 		test_batch(fd, 2, 1);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_stress.c +1 -1
index 3765ab14b..23690c077 100644
@@ -926,7 +926,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 e7dc6637a..18adbd19d 100644
@@ -1363,6 +1363,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 5e7ed0c4e..0f8434d7f 100644
@@ -215,6 +215,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_tiled_fence_blits.c +1 -1
index a3a0221d6..8e908eac0 100644
@@ -320,5 +320,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_partial_pwrite_pread.c +1 -1
index 95fb69c65..ecc97002e 100644
@@ -318,6 +318,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 2b4cec6e7..48f5c67e1 100644
@@ -222,5 +222,5 @@ igt_simple_main
 		}
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_tiled_pread_pwrite.c +1 -1
index 2d21dfb76..885785cab 100644
@@ -154,5 +154,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 f4bdce738..718516def 100644
@@ -246,5 +246,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/gem_tiled_wb.c +1 -1
index e9efbdf23..b2337806d 100644
@@ -239,5 +239,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 1f245eb7d..4f733163b 100644
@@ -243,5 +243,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 513d579d3..d326ae7c2 100644
@@ -138,5 +138,5 @@ igt_simple_main
 
 	munmap(ptr, size);
 
-	close(fd);
+	drm_close_driver(fd);
 }
tests/i915/gem_unfence_active_buffers.c +1 -1
index a0a601de2..71686095d 100644
@@ -99,5 +99,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 735c14720..9d92156a1 100644
@@ -121,5 +121,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
-	close(i915);
+	drm_close_driver(i915);
 }
tests/i915/gem_userptr_blits.c +2 -2
index b00afc32c..381f1b6d9 100644
@@ -1288,9 +1288,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_userptr_blits.c igt_main_args("c:", NULL, help_str, opt_handler, NULL) · line 2708

Quoted 6 lines
tests/i915/gem_userptr_blits.c +3 -0
@@ -2703,4 +2703,7 @@ igt_main_args("c:", NULL, help_str, opt_handler, NULL)
 		igt_require(has_userptr_probe(fd));
 		test_probe(fd);
 	}
+
+	igt_fixture
+		drm_close_driver(fd);

This is a fix.

Quoted 42 lines
tests/i915/gem_userptr_blits.c +0 -0
 }
tests/i915/gem_vm_create.c +1 -1
index f47d8c556..9c5085206 100644
@@ -388,6 +388,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_wait.c +1 -1
index 27d084afa..a33e461d8 100644
@@ -257,6 +257,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/gem_watchdog.c +1 -1
index 27f3a2d7f..18957cee3 100644
@@ -586,6 +586,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(i915, ctx);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/gem_workarounds.c +0 -0
index 7d1199625..b0268e01a 100644

tests/i915/gem_workarounds.c igt_main · line 344

Quoted 6 lines
tests/i915/gem_workarounds.c +3 -0
@@ -339,4 +339,7 @@ igt_main
 			}
 		}
 	}
+
+	igt_fixture
+		drm_close_driver(device);

This is a fix.

Quoted 229 lines
tests/i915/gem_workarounds.c +0 -0
 }
tests/i915/gen7_exec_parse.c +2 -2
index e9751ea73..895aea1ea 100644
@@ -445,7 +445,7 @@ static void hsw_load_register_reg(void)
 				   0xabcdabc0);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -717,6 +717,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 26b151705..e7d47fccc 100644
@@ -1252,6 +1252,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 cafa5233c..f3f0c3d0a 100644
@@ -44,5 +44,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 5422d585f..b6988784d 100644
@@ -46,7 +46,7 @@ init(void)
 static void
 deinit(void)
 {
-	close(drm_fd);
+	drm_close_driver(drm_fd);
 }
 
 
tests/i915/i915_hangman.c +2 -2
index dd396c4e9..d8c9ec0ef 100644
@@ -97,7 +97,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)
@@ -580,6 +580,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 6d9937e99..4b7ecb766 100644
@@ -83,6 +83,6 @@ igt_main
 
 	igt_fixture {
 		close(hwm);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_module_load.c +4 -4
index 725687dab..057c68906 100644
@@ -238,7 +238,7 @@ static void gem_sanitycheck(void)
 		store_all(i915);
 	errno = 0;
 
-	close(i915);
+	drm_close_driver(i915);
 	igt_assert_eq(err, expected);
 }
 
@@ -286,7 +286,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();
@@ -327,7 +327,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;
 }
@@ -419,7 +419,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 377eec58c..9da7dc074 100644
@@ -65,5 +65,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 829606622..0bdb98f3f 100644
@@ -332,6 +332,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 6f08cb3fc..859bfdc55 100644
@@ -689,7 +689,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 662d514a4..096adbbb5 100644
@@ -139,6 +139,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 894ae294c..825f5a326 100644
@@ -167,6 +167,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_pm_lpsp.c +1 -1
index 3ad8b2603..fc4404c9b 100644
@@ -211,6 +211,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 3554f5d77..0fac22770 100644
@@ -611,6 +611,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 d4ee2d58a..34abfe690 100644
@@ -877,7 +877,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_rps.c igt_main · line 964

Quoted 6 lines
tests/i915/i915_pm_rps.c +3 -0
@@ -959,4 +959,7 @@ igt_main
 		waitboost(drm_fd, true);
 		igt_disallow_hang(drm_fd, hang);
 	}
+
+	igt_fixture
+		drm_close_driver(drm_fd);

This is a fix.

Quoted 221 lines
tests/i915/i915_pm_rps.c +0 -0
 }
tests/i915/i915_pm_sseu.c +1 -1
index 1b428c9ba..771971851 100644
@@ -315,7 +315,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 51b412e3a..9f6235083 100644
@@ -76,6 +76,6 @@ igt_main
 	}
 
 	igt_fixture {
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/i915_query.c +1 -1
index e725e04e4..ea191f8a3 100644
@@ -1465,6 +1465,6 @@ igt_main
 		query_parse_and_validate_hwconfig_table(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/i915/i915_suspend.c +2 -2
index a9507964b..1961d85f1 100644
@@ -232,7 +232,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);
@@ -315,5 +315,5 @@ igt_main
 		test_forcewake(fd, true);
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/i915/kms_big_fb.c +1 -1
index a0d5ef730..d132f5b98 100644
@@ -1010,6 +1010,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 20d3058fb..74af9229e 100644
@@ -506,6 +506,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 	igt_fixture {
 		gpu_engines_restore_timeouts(fd, num_engines, saved_gpu_timeouts);
 		igt_display_fini(&display);
-		close(display.drm_fd);
+		drm_close_driver(display.drm_fd);
 	}
 }
tests/i915/kms_ccs.c +1 -1
index 1b3462ea9..2661f661c 100644
@@ -708,6 +708,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 c4dfc9251..87aceb1e3 100644
@@ -257,6 +257,6 @@ igt_main
 
 	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 831ec867a..aea724756 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 63657a742..c8a6f1aa1 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 650e14a77..075e3827b 100644
@@ -1351,7 +1351,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 +0 -0
index bc51975f6..77e1cc807 100644

tests/i915/kms_mmap_write_crc.c igt_main_args("n", NULL, NULL, opt_handler, NULL) · line 309

Quoted 8 lines
tests/i915/kms_mmap_write_crc.c +1 -2
@@ -303,9 +303,8 @@ 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);
-		close(data.drm_fd);

This is a fix.

Quoted 794 lines
tests/i915/kms_mmap_write_crc.c +0 -0
 	}
 }
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 0e8d7f4f0..0ef5f1e82 100644
@@ -639,6 +639,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 4cf986440..a202c613c 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/i915/perf.c +2 -2
index 9ca4d34b6..760c8d692 100644
@@ -5299,7 +5299,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;
@@ -6008,6 +6008,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 c5f083bbd..34b0e10f6 100644
@@ -2111,7 +2111,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);
@@ -2436,13 +2436,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 dda27a0af..94437c0a0 100644
@@ -105,6 +105,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_heartbeat_interval.c +1 -1
index 8a3dd3975..467e0728b 100644
@@ -514,6 +514,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_preempt_timeout.c +1 -1
index 5e0a7d962..b686d6ba8 100644
@@ -343,6 +343,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
tests/i915/sysfs_timeslice_duration.c +1 -1
index 92c4c5eae..8f0d8d94b 100644
@@ -564,6 +564,6 @@ igt_main
 
 	igt_fixture {
 		close(engines);
-		close(i915);
+		drm_close_driver(i915);
 	}
 }
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 e4783624f..1e5d834ce 100644
@@ -795,7 +795,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);
 	}
@@ -874,6 +874,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 51ffa523a..f44fc4bea 100644
@@ -668,6 +668,6 @@ igt_main_args("e", NULL, help_str, opt_handler, &data)
 		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 fdc7120c7..d444cfe10 100644
@@ -1069,6 +1069,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 3a353a032..d9ae35587 100644
@@ -1010,6 +1010,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 7df6a6125..69e52a864 100644
@@ -1803,6 +1803,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_dp_tiled_display.c +1 -1
index 07b803a50..8dfe93000 100644
@@ -502,6 +502,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_flip.c +1 -1
index e4c98b8ec..8d6a8e74d 100755
@@ -1898,6 +1898,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 f1508efba..d1e516562 100644
@@ -60,7 +60,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)
@@ -386,7 +386,7 @@ end:
 
 	igt_fixture {
 		drmModeFreeConnector(connector);
-		close(drm_fd);
+		drm_close_driver(drm_fd);
 
 		reset_connectors();
 	}
tests/kms_getfb.c +2 -2
index 4adc7eee2..3cb568808 100644
@@ -452,7 +452,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);
 	}
 }
 
@@ -484,6 +484,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 81a32dbf8..d47a1977c 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 ec0483055..6059f1f8f 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 65afc9f60..9a354fcfe 100644
@@ -433,6 +433,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 10e16b638..8e0cd2129 100644
@@ -1318,6 +1318,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 a37abd16d..61d0f8c89 100644
@@ -1323,6 +1323,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 96aa6d8d6..d9a5992e4 100644
@@ -178,7 +178,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);
@@ -206,7 +206,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);
@@ -217,7 +217,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);
@@ -338,5 +338,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 28b4fd27c..f0d8b1172 100644
@@ -1279,6 +1279,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_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);
 	}
 }
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);
 	}
 }
tests/nouveau_crc.c +0 -0
index 785d39bde..d5aa0e650 100644

tests/nouveau_crc.c igt_main · line 416

Quoted 10 lines
tests/nouveau_crc.c +4 -2
@@ -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);
+	}

This is a fix.

Quoted 609 lines
tests/nouveau_crc.c +0 -0
 }
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);
         }
 }
tests/prime_busy.c +1 -1
index 343020f13..f9f1674d4 100644
@@ -162,6 +162,6 @@ igt_main
 
 	igt_fixture {
 		intel_ctx_destroy(fd, ctx);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/prime_mmap.c +1 -1
index bc19f68c9..1c2d2a301 100644
@@ -557,6 +557,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 b22fb35c1..a18c16c5c 100644
@@ -249,7 +249,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);
 }
 
 /*
@@ -346,6 +346,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 bf5486194..0b5ac256d 100644
@@ -106,8 +106,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)
@@ -139,8 +139,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)
@@ -164,8 +164,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);
 }
@@ -211,7 +211,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);
 }
 
@@ -275,14 +275,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);
 }
@@ -357,13 +357,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);
 }
@@ -392,7 +392,7 @@ static void test_llseek_size(void)
 		close(dma_buf_fd);
 	}
 
-	close(fd);
+	drm_close_driver(fd);
 }
 
 static void test_llseek_bad(void)
@@ -421,7 +421,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 9aa767c9c..9bd22641c 100644
@@ -1249,7 +1249,7 @@ igt_main
 
 
 	igt_fixture {
-		close(i915);
-		close(vgem);
+		drm_close_driver(i915);
+		drm_close_driver(vgem);
 	}
 }
tests/syncobj_basic.c +1 -1
index 6e20c3411..beb44b1e9 100644
@@ -232,7 +232,7 @@ igt_main
 		test_valid_cycle(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 
 }
tests/syncobj_timeline.c +1 -1
index 7f5ff6f6c..081f440f3 100644
@@ -1538,6 +1538,6 @@ igt_main
 		test_32bits_limit(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/syncobj_wait.c +1 -1
index 427b6b119..eebc96b67 100644
@@ -914,6 +914,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/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/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);
 	}
 }
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);
 }
tests/vgem_basic.c +3 -3
index ada5518d7..36899b307 100644
@@ -64,8 +64,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)
@@ -537,6 +537,6 @@ igt_main
 		test_debugfs_read(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/vgem_slow.c +1 -1
index 58b09e421..4c4e94ea0 100644
@@ -85,6 +85,6 @@ igt_main
 		test_nohang(fd);
 
 	igt_fixture {
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
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);
 	}
 }
tests/xe/xe_compute.c +0 -0
index 7ac64dfe3..5e6cd8529 100644

tests/xe/xe_compute.c igt_main · line 47

Quoted 3 lines
tests/xe/xe_compute.c +0 -0
@@ -45,6 +45,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);

--------------- ^
You should remove this line as now it is done in drm_close_driver. The same change should be done for other Xe tests in tests/xe/

Regards,
Kamil

Quoted 454 lines
tests/xe/xe_compute.c +1 -1
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_create.c +1 -1
index ae841f809..b3d9fd49f 100644
@@ -102,6 +102,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_debugfs.c +1 -1
index 6bdd3ef06..4006981c6 100644
@@ -270,6 +270,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 8920b141b..81ece2428 100644
@@ -220,7 +220,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]);
 	}
 
 }
@@ -257,6 +257,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_evict.c +3 -3
index 5687cce30..14a2d19f1 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 {
@@ -701,5 +701,5 @@ igt_main
 	}
 
 	igt_fixture
-		close(fd);
+		drm_close_driver(fd);
 }
tests/xe/xe_exec_balancer.c +1 -1
index 2018c8104..fb4592903 100644
@@ -708,6 +708,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_basic.c +1 -1
index 2a176a5b3..d14a764f4 100644
@@ -353,6 +353,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 685193990..950cb6159 100644
@@ -361,6 +361,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 a3ab17270..8cd883c09 100644
@@ -570,6 +570,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_reset.c +4 -4
index 0d72a3f20..3700b8dce 100644
@@ -294,7 +294,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;
@@ -475,7 +475,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;
@@ -655,7 +655,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;
@@ -946,6 +946,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_exec_threads.c +4 -4
index 3f2c2de9e..bde92a9c5 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);
 	}
 }
 
@@ -454,7 +454,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);
 	}
 }
 
@@ -698,7 +698,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);
 	}
 }
 
@@ -1403,6 +1403,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_guc_pc.c +1 -1
index 5c71ae147..56d4f9190 100644
@@ -496,6 +496,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 35d61608e..f43beb1a8 100644
@@ -1180,6 +1180,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 6b313a189..352cbcab4 100644
@@ -77,6 +77,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_mmio.c +1 -1
index 42b6241b1..77a38b8d1 100644
@@ -89,6 +89,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_module_load.c +1 -1
index c2d43cc20..16432c78f 100644
@@ -86,7 +86,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 367671883..f276e694c 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 44154143c..7bec294ed 100644
@@ -441,6 +441,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 4e8fd5d4f..a86d0e9f2 100644
@@ -122,9 +122,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);
 }
 
 /**
@@ -202,9 +202,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);
 }
@@ -259,10 +259,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)
@@ -335,7 +335,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 */
@@ -343,7 +343,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);
 }
@@ -429,7 +429,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;
@@ -437,7 +437,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);
 }
@@ -474,7 +474,7 @@ static void test_llseek_size(void)
 	}
 
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 /**
@@ -511,7 +511,7 @@ static void test_llseek_bad(void)
 	close(dma_buf_fd);
 
 	xe_device_put(fd);
-	close(fd);
+	drm_close_driver(fd);
 }
 
 igt_main
@@ -544,6 +544,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_query.c +1 -1
index 87990370f..1c06534d4 100644
@@ -491,6 +491,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(xe);
-		close(xe);
+		drm_close_driver(xe);
 	}
 }
tests/xe/xe_vm.c +1 -1
index d4cec104e..9015a5a57 100644
@@ -1839,6 +1839,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
tests/xe/xe_waitfence.c +1 -1
index cdfcacdb4..8bfb741f6 100644
@@ -98,6 +98,6 @@ igt_main
 
 	igt_fixture {
 		xe_device_put(fd);
-		close(fd);
+		drm_close_driver(fd);
 	}
 }
Signature · 1 line
2.40.0
#20 lore raw

PATCH 6/6 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.

---
 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            |  8 ++------
 tests/xe/xe_debugfs.c           |  8 ++------
 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        |  6 +-----
 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_vm.c                |  5 +----
 tests/xe/xe_waitfence.c         |  8 ++------
 30 files changed, 40 insertions(+), 220 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 1e5d834ce..629b81aa7 100644
@@ -836,9 +836,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);
@@ -870,10 +867,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 8d6a8e74d..c8ca21fe4 100755
@@ -1826,9 +1826,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);
 		}
@@ -1894,10 +1891,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 3cb568808..0b2e66ddf 100644
@@ -399,9 +399,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;
@@ -449,9 +446,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);
 	}
 }
@@ -463,9 +457,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
@@ -480,10 +471,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 5e6cd8529..d2d198a95 100644
@@ -35,16 +35,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 -6
index b3d9fd49f..02a0a7338 100644
@@ -91,17 +91,13 @@ 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);
 	}
 
-	igt_fixture {
-		xe_device_put(xe);
+	igt_fixture
 		drm_close_driver(xe);
-	}
 }
tests/xe/xe_debugfs.c +2 -6
index 4006981c6..c4396a37a 100644
@@ -240,19 +240,17 @@ 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);
 	}
 
 	igt_subtest("base") {
-		test_base(fd, xe_dev->config);
+		test_base(fd, xe_config(fd));
 	}
 
 
@@ -268,8 +266,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 81ece2428..64027d68f 100644
@@ -113,7 +113,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);
 	}
@@ -218,11 +217,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
@@ -232,7 +228,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) {
@@ -255,8 +250,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 14a2d19f1..241eff191 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);
 }
 
@@ -668,7 +664,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 fb4592903..81ec526e7 100644
@@ -626,10 +626,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)
@@ -706,8 +704,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 d14a764f4..d1f39e4b6 100644
@@ -311,10 +311,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)
@@ -351,8 +349,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 950cb6159..a58067e64 100644
@@ -327,10 +327,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)
@@ -359,8 +357,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 8cd883c09..ee167f359 100644
@@ -524,7 +524,6 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 		igt_require(xe_supports_faults(fd));
 	}
 
@@ -568,8 +567,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 3700b8dce..bd8ad76fc 100644
@@ -178,10 +178,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)
@@ -293,7 +291,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);
@@ -388,10 +385,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;
@@ -474,7 +469,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);
@@ -566,10 +560,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);
@@ -654,7 +646,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);
@@ -831,10 +822,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)
@@ -944,8 +933,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 bde92a9c5..6450d1e40 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
@@ -282,7 +279,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;
 	}
 
@@ -453,7 +449,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);
 	}
 }
@@ -491,7 +486,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;
 	}
 
@@ -696,10 +690,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 {
@@ -1391,18 +1383,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 +1 -5
index 5bca19c87..c7391a26a 100644
@@ -120,16 +120,12 @@ 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") {
 		gpgpu_fill(&data, fill_fn, 0);
 	}
 
-	igt_fixture {
-		xe_device_put(data.drm_fd);
+	igt_fixture
 		buf_ops_destroy(data.bops);
-	}
 }
tests/xe/xe_guc_pc.c +0 -2
index 56d4f9190..13b862c5a 100644
@@ -387,7 +387,6 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 
 		sysfs = igt_sysfs_open(fd);
 		igt_assert(sysfs != -1);
@@ -495,7 +494,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 f43beb1a8..59740d4d2 100644
@@ -1105,7 +1105,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");
@@ -1178,7 +1177,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 352cbcab4..463d0cac7 100644
@@ -61,10 +61,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));
@@ -75,8 +73,6 @@ igt_main
 	igt_subtest("vram-system")
 		test_mmap(fd, vram_memory(fd, 0) | system_memory(fd));
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_mmio.c +2 -6
index 77a38b8d1..6825478f0 100644
@@ -77,18 +77,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 f276e694c..3c2b340bd 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 7bec294ed..b4d5fe252 100644
@@ -370,8 +370,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);
@@ -440,7 +438,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 a86d0e9f2..5b21a39ea 100644
@@ -104,9 +104,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);
 
@@ -121,9 +119,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);
 }
 
@@ -185,9 +177,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);
@@ -201,9 +191,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);
@@ -222,9 +210,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);
 
@@ -258,10 +244,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);
 }
 
@@ -314,7 +298,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);
 
@@ -334,7 +317,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]);
 
@@ -406,13 +388,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++) {
@@ -428,7 +408,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 */
@@ -436,7 +415,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);
@@ -458,7 +436,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;
@@ -473,7 +450,6 @@ static void test_llseek_size(void)
 		close(dma_buf_fd);
 	}
 
-	xe_device_put(fd);
 	drm_close_driver(fd);
 }
 
@@ -493,7 +469,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);
@@ -510,7 +485,6 @@ static void test_llseek_bad(void)
 
 	close(dma_buf_fd);
 
-	xe_device_put(fd);
 	drm_close_driver(fd);
 }
 
@@ -534,7 +508,6 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
@@ -542,8 +515,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 1c06534d4..99e92b7c1 100644
@@ -457,10 +457,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);
@@ -489,8 +487,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_vm.c +1 -4
index 9015a5a57..13295cbe1 100644
@@ -1621,7 +1621,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) {
@@ -1837,8 +1836,6 @@ igt_main
 		}
 	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
tests/xe/xe_waitfence.c +2 -6
index 8bfb741f6..c9d7f6981 100644
@@ -88,16 +88,12 @@ igt_main
 {
 	int fd;
 
-	igt_fixture {
+	igt_fixture
 		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
 	igt_subtest("test")
 		test(fd);
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
 		drm_close_driver(fd);
-	}
 }
Signature · 1 line
2.40.0
#21 lore raw

Re: [igt-dev] [i-g-t 6/6] tests: Drop xe_device get/put from test level

Quoted 4 lines · Bhanuprakash Modem

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

Cc Janga Rahul Kumar <[email protected]>
Quoted 1,089 lines
---
  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            |  8 ++------
  tests/xe/xe_debugfs.c           |  8 ++------
  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        |  6 +-----
  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_vm.c                |  5 +----
  tests/xe/xe_waitfence.c         |  8 ++------
  30 files changed, 40 insertions(+), 220 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 1e5d834ce..629b81aa7 100644
@@ -836,9 +836,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);
@@ -870,10 +867,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 8d6a8e74d..c8ca21fe4 100755
@@ -1826,9 +1826,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);
  		}
@@ -1894,10 +1891,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 3cb568808..0b2e66ddf 100644
@@ -399,9 +399,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;
@@ -449,9 +446,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);
  	}
  }
@@ -463,9 +457,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
@@ -480,10 +471,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 5e6cd8529..d2d198a95 100644
@@ -35,16 +35,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 -6
index b3d9fd49f..02a0a7338 100644
@@ -91,17 +91,13 @@ 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);
  	}
 
-	igt_fixture {
-		xe_device_put(xe);
+	igt_fixture
  		drm_close_driver(xe);
-	}
  }
tests/xe/xe_debugfs.c +2 -6
index 4006981c6..c4396a37a 100644
@@ -240,19 +240,17 @@ 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);
  	}
 
  	igt_subtest("base") {
-		test_base(fd, xe_dev->config);
+		test_base(fd, xe_config(fd));
  	}
 
 
@@ -268,8 +266,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 81ece2428..64027d68f 100644
@@ -113,7 +113,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);
  	}
@@ -218,11 +217,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
@@ -232,7 +228,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) {
@@ -255,8 +250,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 14a2d19f1..241eff191 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);
  }
 
@@ -668,7 +664,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 fb4592903..81ec526e7 100644
@@ -626,10 +626,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)
@@ -706,8 +704,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 d14a764f4..d1f39e4b6 100644
@@ -311,10 +311,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)
@@ -351,8 +349,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 950cb6159..a58067e64 100644
@@ -327,10 +327,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)
@@ -359,8 +357,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 8cd883c09..ee167f359 100644
@@ -524,7 +524,6 @@ igt_main
 
  	igt_fixture {
  		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
  		igt_require(xe_supports_faults(fd));
  	}
 
@@ -568,8 +567,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 3700b8dce..bd8ad76fc 100644
@@ -178,10 +178,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)
@@ -293,7 +291,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);
@@ -388,10 +385,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;
@@ -474,7 +469,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);
@@ -566,10 +560,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);
@@ -654,7 +646,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);
@@ -831,10 +822,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)
@@ -944,8 +933,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 bde92a9c5..6450d1e40 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
@@ -282,7 +279,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;
  	}
 
@@ -453,7 +449,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);
  	}
  }
@@ -491,7 +486,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;
  	}
 
@@ -696,10 +690,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 {
@@ -1391,18 +1383,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 +1 -5
index 5bca19c87..c7391a26a 100644
@@ -120,16 +120,12 @@ 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") {
  		gpgpu_fill(&data, fill_fn, 0);
  	}
 
-	igt_fixture {
-		xe_device_put(data.drm_fd);
+	igt_fixture
  		buf_ops_destroy(data.bops);
-	}
  }
tests/xe/xe_guc_pc.c +0 -2
index 56d4f9190..13b862c5a 100644
@@ -387,7 +387,6 @@ igt_main
 
  	igt_fixture {
  		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
 
  		sysfs = igt_sysfs_open(fd);
  		igt_assert(sysfs != -1);
@@ -495,7 +494,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 f43beb1a8..59740d4d2 100644
@@ -1105,7 +1105,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");
@@ -1178,7 +1177,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 352cbcab4..463d0cac7 100644
@@ -61,10 +61,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));
@@ -75,8 +73,6 @@ igt_main
  	igt_subtest("vram-system")
  		test_mmap(fd, vram_memory(fd, 0) | system_memory(fd));
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
  		drm_close_driver(fd);
-	}
  }
tests/xe/xe_mmio.c +2 -6
index 77a38b8d1..6825478f0 100644
@@ -77,18 +77,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 f276e694c..3c2b340bd 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 7bec294ed..b4d5fe252 100644
@@ -370,8 +370,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);
@@ -440,7 +438,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 a86d0e9f2..5b21a39ea 100644
@@ -104,9 +104,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);
 
@@ -121,9 +119,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);
  }
 
@@ -185,9 +177,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);
@@ -201,9 +191,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);
@@ -222,9 +210,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);
 
@@ -258,10 +244,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);
  }
 
@@ -314,7 +298,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);
 
@@ -334,7 +317,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]);
 
@@ -406,13 +388,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++) {
@@ -428,7 +408,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 */
@@ -436,7 +415,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);
@@ -458,7 +436,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;
@@ -473,7 +450,6 @@ static void test_llseek_size(void)
  		close(dma_buf_fd);
  	}
 
-	xe_device_put(fd);
  	drm_close_driver(fd);
  }
 
@@ -493,7 +469,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);
@@ -510,7 +485,6 @@ static void test_llseek_bad(void)
 
  	close(dma_buf_fd);
 
-	xe_device_put(fd);
  	drm_close_driver(fd);
  }
 
@@ -534,7 +508,6 @@ igt_main
 
  	igt_fixture {
  		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
  	}
 
  	for (i = 0; i < ARRAY_SIZE(tests); i++) {
@@ -542,8 +515,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 1c06534d4..99e92b7c1 100644
@@ -457,10 +457,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);
@@ -489,8 +487,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_vm.c +1 -4
index 9015a5a57..13295cbe1 100644
@@ -1621,7 +1621,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) {
@@ -1837,8 +1836,6 @@ igt_main
  		}
  	}
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
  		drm_close_driver(fd);
-	}
  }
tests/xe/xe_waitfence.c +2 -6
index 8bfb741f6..c9d7f6981 100644
@@ -88,16 +88,12 @@ igt_main
  {
  	int fd;
 
-	igt_fixture {
+	igt_fixture
  		fd = drm_open_driver(DRIVER_XE);
-		xe_device_get(fd);
-	}
 
  	igt_subtest("test")
  		test(fd);
 
-	igt_fixture {
-		xe_device_put(fd);
+	igt_fixture
  		drm_close_driver(fd);
-	}
  }