From 69a1974347cffaf4c4c5f69e1ed177561ec94a6f Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 30 Jan 2012 17:16:50 -0500 Subject: [PATCH] modprobe: post-remove module deps with 0 refcnt This commit looks shockingly similar to 0e9bd2d1 because SOMEONE decided to remove it in a872bba in a glorious frenzy of refactoring. --- tools/kmod-modprobe.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/kmod-modprobe.c b/tools/kmod-modprobe.c index af64b72..764b8bf 100644 --- a/tools/kmod-modprobe.c +++ b/tools/kmod-modprobe.c @@ -339,6 +339,7 @@ end: static int rmmod_do_remove_module(struct kmod_module *mod) { const char *modname = kmod_module_get_name(mod); + struct kmod_list *deps, *itr; int flags = 0, err; SHOW("rmmod %s\n", kmod_module_get_name(mod)); @@ -357,6 +358,17 @@ static int rmmod_do_remove_module(struct kmod_module *mod) LOG("Module %s is not in kernel.\n", modname); } + deps = kmod_module_get_dependencies(mod); + if (deps != NULL) { + kmod_list_foreach(itr, deps) { + struct kmod_module *dep = kmod_module_get_module(itr); + if (kmod_module_get_refcnt(dep) == 0) + rmmod_do_remove_module(dep); + kmod_module_unref(dep); + } + kmod_module_unref_list(deps); + } + return err; } -- 2.7.4