]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modprobe: don't attempt to remove an already removed module
authorJan Stancek <jstancek@redhat.com>
Tue, 30 Sep 2025 08:37:21 +0000 (10:37 +0200)
committerLucas De Marchi <demarchi@kernel.org>
Tue, 3 Feb 2026 04:58:59 +0000 (22:58 -0600)
In a scenario like following:
    # lsmod | grep -e bnx2i -e cnic
    bnx2i                  94208  0
    libiscsi               94208  1 bnx2i
    cnic                   90112  1 bnx2i
    uio                    32768  1 cnic
    scsi_transport_iscsi   196608  2 bnx2i,libiscsi

    # modprobe -v --remove --remove-holders cnic
    rmmod bnx2i
    rmmod cnic
    rmmod libiscsi
    rmmod cnic
    modprobe: ERROR: libkmod/libkmod-module.c:856 kmod_module_remove_module()
    could not remove 'cnic': No such file or directory

modprobe attempts to remove cnic module twice and propagates that error
to the user with a message as well as an exit code.

Add a check to avoid attempts to remove modules that are already gone.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/pull/393
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
tools/modprobe.c

index 757723e8519c7ddc7ceb7bb6a6e2f5daa84cc8fb..349e7e0ef6b2cdf03bdf0c40bcf77881db0e1f4a 100644 (file)
@@ -507,9 +507,12 @@ static int rmmod_do_module(struct kmod_module *mod, int flags)
                }
        }
 
-       if (!cmd)
-               err = rmmod_do_remove_module(mod);
-       else
+       if (!cmd) {
+               if (kmod_module_get_refcnt(mod) != -ENOENT)
+                       err = rmmod_do_remove_module(mod);
+               else
+                       err = 0;
+       } else
                err = command_do(mod, "remove", cmd, NULL);
 
        if (err < 0)