Skip to content

Commit c1aff4b

Browse files
jstanceklucasdemarchi
authored andcommitted
modprobe: don't attempt to remove an already removed module
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>
1 parent ca9a7f4 commit c1aff4b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

tools/modprobe.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,12 @@ static int rmmod_do_module(struct kmod_module *mod, int flags)
507507
}
508508
}
509509

510-
if (!cmd)
511-
err = rmmod_do_remove_module(mod);
512-
else
510+
if (!cmd) {
511+
if (kmod_module_get_refcnt(mod) != -ENOENT)
512+
err = rmmod_do_remove_module(mod);
513+
else
514+
err = 0;
515+
} else
513516
err = command_do(mod, "remove", cmd, NULL);
514517

515518
if (err < 0)

0 commit comments

Comments
 (0)