From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>,
Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Subject: [PATCH i-g-t v4 6/6] lib/igt_kmod: Do not leak kmod ctx
Date: Mon, 18 Nov 2024 21:29:54 -0800 [thread overview]
Message-ID: <20241119052954.1993905-7-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20241119052954.1993905-1-lucas.demarchi@intel.com>
kmod_ctx() is used as a cheap way to cache the kmod ctx. Make sure it's
released when the process exit by using igt_install_exit_handler(),
which also guarantees children forked with igt_fork* don't free it on
exit. Normal forks are still susceptible to breakage, but if it that
happens, let it break so we can fix.
Reviewed-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
lib/igt_kmod.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 3f77a0c94..eef3657c3 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -71,14 +71,20 @@ static void squelch(void *data, int priority,
{
}
+static struct kmod_ctx *ctx__;
+
+static void free_kmod_ctx(int sig)
+{
+ kmod_unref(ctx__);
+}
+
static struct kmod_ctx *kmod_ctx(void)
{
- static struct kmod_ctx *ctx;
const char **config_paths = NULL;
char *config_paths_str;
char *dirname;
- if (ctx)
+ if (ctx__)
goto out;
dirname = getenv("IGT_KMOD_DIRNAME");
@@ -112,14 +118,16 @@ static struct kmod_ctx *kmod_ctx(void)
config_paths[i] = NULL;
}
- ctx = kmod_new(dirname, config_paths);
- igt_assert(ctx != NULL);
+ ctx__ = kmod_new(dirname, config_paths);
+ igt_assert(ctx__ != NULL);
free(config_paths);
+ igt_install_exit_handler(free_kmod_ctx);
+
+ kmod_set_log_fn(ctx__, squelch, NULL);
- kmod_set_log_fn(ctx, squelch, NULL);
out:
- return ctx;
+ return ctx__;
}
/**
--
2.47.0
next prev parent reply other threads:[~2024-11-19 5:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 5:29 [PATCH i-g-t v4 0/6] lib/igt_kmod: Drop legacy kunit integration Lucas De Marchi
2024-11-19 5:29 ` [PATCH i-g-t v4 1/6] lib/igt_kmod: Drop legacy kunit fallback Lucas De Marchi
2024-11-19 5:29 ` [PATCH i-g-t v4 2/6] lib/igt_kmod: Fix leaking subtest name Lucas De Marchi
2024-11-19 5:29 ` [PATCH i-g-t v4 3/6] lib/igt_kmod: Let the fixture open/close debugfs Lucas De Marchi
2024-11-19 11:02 ` Janusz Krzysztofik
2024-11-21 22:52 ` Lucas De Marchi
2024-11-19 5:29 ` [PATCH i-g-t v4 4/6] lib/igt_kmod: Stop passing ktap around Lucas De Marchi
2024-11-19 5:29 ` [PATCH i-g-t v4 5/6] lib/igt_ktap: Just free ktap Lucas De Marchi
2024-11-19 5:29 ` Lucas De Marchi [this message]
2024-11-19 14:32 ` ✗ CI.xeBAT: failure for lib/igt_kmod: Drop legacy kunit integration (rev5) Patchwork
2024-11-19 14:39 ` ✗ Fi.CI.BAT: " Patchwork
2024-11-20 0:06 ` ✗ CI.xeFULL: " Patchwork
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=20241119052954.1993905-7-lucas.demarchi@intel.com \
--to=lucas.demarchi@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=janusz.krzysztofik@linux.intel.com \
/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