[igt-dev] [PATCH i-g-t v2 1/2] lib: Add silent __igt_i915_driver_unload

Anshuman Gupta anshuman.gupta at intel.com
Tue Feb 15 14:10:52 UTC 2022


Add silent __igt_i915_driver_unload(), which will not
print any warning in case of passed argument is NULL.
This will be used by some igt test, which marks i915
module busy and expect i915 module unload to fail.
These tests requires a silent lib function to unload
the i915 module correctly.

v2:
- Change commit log. [Ashutosh]
- Change whom to who. [Ashutosh]
- When aux audule unload fails mark who with module name. [Ashutosh]
- Keep same type of return type in
  __igt_i915_driver_unload(). [Ashutosh]

Cc: Chris Wilson <chris.p.wilson at intel.com>
Signed-off-by: Anshuman Gupta <anshuman.gupta at intel.com>
---
 lib/igt_kmod.c | 90 ++++++++++++++++++++++++++++++--------------------
 lib/igt_kmod.h |  1 +
 2 files changed, 56 insertions(+), 35 deletions(-)

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 10e983844..a249ea922 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -369,54 +369,74 @@ igt_i915_driver_load(const char *opts)
 	return IGT_EXIT_SUCCESS;
 }
 
-/**
- * igt_i915_driver_unload:
- *
- * Unloads the i915 driver and its dependencies.
- *
- */
-int
-igt_i915_driver_unload(void)
+int __igt_i915_driver_unload(const char **who)
 {
+	const char *sound[] = {
+		"snd_hda_intel",
+		"snd_hdmi_lpe_audio",
+		NULL,
+	};
+
+	const char *aux[] = {
+		/* gen5: ips uses symbol_get() so only a soft module dependency */
+		"intel_ips",
+		NULL,
+	};
+
 	/* unbind vt */
 	bind_fbcon(false);
 
-	if (igt_kmod_is_loaded("snd_hda_intel")) {
-		igt_terminate_process(SIGTERM, "alsactl");
-
-		/* unbind snd_hda_intel */
-		kick_snd_hda_intel();
-
-		if (igt_kmod_unload("snd_hda_intel", 0)) {
-			igt_warn("Could not unload snd_hda_intel\n");
-			igt_kmod_list_loaded();
-			igt_lsof("/dev/snd");
-			return IGT_EXIT_FAILURE;
+	for (const char **m = sound; *m; m++) {
+		if (igt_kmod_is_loaded(*m)) {
+			igt_terminate_process(SIGTERM, "alsactl");
+			kick_snd_hda_intel();
+			if (igt_kmod_unload(*m, 0)) {
+				if (who)
+					*who = *m;
+				return IGT_EXIT_FAILURE;
+			}
 		}
 	}
 
-	if (igt_kmod_is_loaded("snd_hdmi_lpe_audio")) {
-		igt_terminate_process(SIGTERM, "alsactl");
+	for (const char **m = aux; *m; m++) {
+		if (igt_kmod_is_loaded(*m))
+			if (igt_kmod_unload(*m, 0)) {
+				if (who)
+					*who = *m;
+				return IGT_EXIT_FAILURE;
+			}
+	}
 
-		if (igt_kmod_unload("snd_hdmi_lpe_audio", 0)) {
-			igt_warn("Could not unload snd_hdmi_lpe_audio\n");
-			igt_kmod_list_loaded();
-			igt_lsof("/dev/snd");
+	if (igt_kmod_is_loaded("i915")) {
+		if (igt_kmod_unload("i915", 0)) {
+			if (who)
+				*who = "i915";
 			return IGT_EXIT_FAILURE;
 		}
 	}
 
-	/* gen5: ips uses symbol_get() so only a soft module dependency */
-	if (igt_kmod_is_loaded("intel_ips"))
-		igt_kmod_unload("intel_ips", 0);
+	return IGT_EXIT_SUCCESS;
+}
 
-	if (igt_kmod_is_loaded("i915")) {
-		if (igt_kmod_unload("i915", 0)) {
-			igt_warn("Could not unload i915\n");
-			igt_kmod_list_loaded();
-			igt_lsof("/dev/dri");
-			return IGT_EXIT_SKIP;
-		}
+/**
+ * igt_i915_driver_unload:
+ *
+ * Unloads the i915 driver and its dependencies.
+ *
+ */
+int
+igt_i915_driver_unload(void)
+{
+	const char *who;
+	int ret;
+
+	ret = __igt_i915_driver_unload(&who);
+	if (ret) {
+		igt_warn("Could not unload %s\n", who);
+		igt_kmod_list_loaded();
+		igt_lsof("/dev/dri");
+		igt_lsof("/dev/snd");
+		return ret;
 	}
 
 	if (igt_kmod_is_loaded("intel-gtt"))
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index 04c87516f..0898122b3 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -38,6 +38,7 @@ int igt_kmod_unload(const char *mod_name, unsigned int flags);
 
 int igt_i915_driver_load(const char *opts);
 int igt_i915_driver_unload(void);
+int __igt_i915_driver_unload(const char **whom);
 
 int igt_amdgpu_driver_load(const char *opts);
 int igt_amdgpu_driver_unload(void);
-- 
2.26.2



More information about the igt-dev mailing list