[igt-dev] [PATCH 1/4] lib/igt_kmod: simplify check for loaded module

Lucas De Marchi lucas.demarchi at intel.com
Thu Apr 4 22:39:22 UTC 2019


No need to go through the list of loaded modules and check one by one.
We can just check if it's in "live" state or if it's builtin.

Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
 lib/igt_kmod.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 91662eb3..8d5ac788 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -119,25 +119,18 @@ bool
 igt_kmod_is_loaded(const char *mod_name)
 {
 	struct kmod_ctx *ctx = kmod_ctx();
-	struct kmod_list *mod, *list;
+	enum kmod_module_initstate state;
+	struct kmod_module *kmod;
 	bool ret = false;
 
-	if (kmod_module_new_from_loaded(ctx, &list) < 0)
+	if (kmod_module_new_from_name(ctx, mod_name, &kmod) < 0)
 		goto out;
 
-	kmod_list_foreach(mod, list) {
-		struct kmod_module *kmod = kmod_module_get_module(mod);
-		const char *kmod_name = kmod_module_get_name(kmod);
+	state = kmod_module_get_initstate(kmod);
+	ret = state == KMOD_MODULE_LIVE || state == KMOD_MODULE_BUILTIN;
 
-		if (!strcmp(kmod_name, mod_name)) {
-			kmod_module_unref(kmod);
-			ret = true;
-			break;
-		}
-		kmod_module_unref(kmod);
-	}
-	kmod_module_unref_list(list);
 out:
+	kmod_module_unref(kmod);
 	return ret;
 }
 
-- 
2.21.0



More information about the igt-dev mailing list