public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [igt-dev] [PATCH 1/4] lib/igt_kmod: simplify check for loaded module
Date: Thu,  4 Apr 2019 15:39:22 -0700	[thread overview]
Message-ID: <20190404223925.1102-1-lucas.demarchi@intel.com> (raw)

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@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

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

             reply	other threads:[~2019-04-04 22:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-04 22:39 Lucas De Marchi [this message]
2019-04-04 22:39 ` [igt-dev] [PATCH 2/4] gem_exec_parallel: do not special case the default Lucas De Marchi
2019-04-04 22:57   ` Chris Wilson
2019-04-04 22:39 ` [igt-dev] [PATCH 3/4] lib: add igt_allow_unlimited_files() Lucas De Marchi
2019-04-04 23:00   ` Chris Wilson
2019-04-04 22:39 ` [igt-dev] [PATCH 4/4] gem_exec_parallel: allow unlimited open files Lucas De Marchi
2019-04-04 23:01   ` Chris Wilson
2019-04-04 23:19 ` [igt-dev] [PATCH 1/4] lib/igt_kmod: simplify check for loaded module Chris Wilson
2019-04-05 16:33   ` Lucas De Marchi
2019-04-04 23:39 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [1/4] " Patchwork
2019-04-05 19:29 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2019-04-08 11:56   ` Petri Latvala
2019-04-30 17:09     ` Lucas De Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190404223925.1102-1-lucas.demarchi@intel.com \
    --to=lucas.demarchi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox