[igt-dev] [PATCH i-g-t] lib/kmod: Recursively unload the modules
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Mon Nov 23 07:52:52 UTC 2020
On Thu, Nov 19, 2020 at 04:21:12PM +0000, Chris Wilson wrote:
> When asked to unload a module, look at all the modules that are
> trying to use the module and try to unload those first.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
> lib/igt_kmod.c | 21 ++++++++++++++++++++-
> 1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
> index e701545d3..5778bf953 100644
> --- a/lib/igt_kmod.c
> +++ b/lib/igt_kmod.c
> @@ -243,6 +243,25 @@ out:
> return err < 0 ? err : 0;
> }
>
> +static int kmod_unload_r(struct kmod_module *kmod, unsigned int flags)
> +{
> + struct kmod_list *holders, *pos;
> + int err = 0;
> +
> + holders = kmod_module_get_holders(kmod);
> + kmod_list_foreach(pos, holders) {
> + struct kmod_module *it = kmod_module_get_module(pos);
> + err = kmod_unload_r(it, flags);
> + kmod_module_unref(it);
> + if (err < 0)
> + break;
> + }
> + kmod_module_unref_list(holders);
> + if (err < 0)
> + return err;
> +
> + return kmod_module_remove_module(kmod, flags);
> +}
Code looks ok, I've also I played with it for a while and no issues found.
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
--
Zbigniew
>
> /**
> * igt_kmod_unload:
> @@ -269,7 +288,7 @@ igt_kmod_unload(const char *mod_name, unsigned int flags)
> goto out;
> }
>
> - err = kmod_module_remove_module(kmod, flags);
> + err = kmod_unload_r(kmod, flags);
> if (err < 0) {
> igt_debug("Could not remove module %s (%s)\n", mod_name,
> strerror(-err));
> --
> 2.29.2
>
> _______________________________________________
> igt-dev mailing list
> igt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev
More information about the igt-dev
mailing list