insmod: check if module already loaded and if so exit early

Signed-off-by: Thierry Laurion <insurgo@riseup.net>
This commit is contained in:
Thierry Laurion 2024-02-22 13:36:25 -05:00
parent 65f0b905f6
commit bec2545688
No known key found for this signature in database
GPG Key ID: 9A53E1BB3FF00461
2 changed files with 11 additions and 5 deletions

View File

@ -11,8 +11,7 @@ echo "Loading Ethernet network modules..."
network_modules="e1000 e1000e igb sfc mdio mlx4_core mlx4_en"
for module in $(echo $network_modules); do
if [ -f /lib/modules/$module.ko ]; then
#check if module is already loaded and load it if not
lsmod | grep -q $module || insmod /lib/modules/$module.ko
insmod /lib/modules/$module.ko
fi
done
@ -30,8 +29,7 @@ if [ -e /lib/modules/cdc_ether.ko ]; then
echo "Loading USB tethering network related modules: $network_modules..."
for module in $(echo $network_modules); do
if [ -f /lib/modules/$module.ko ]; then
#check if module is already loaded and load it if not
lsmod | grep -q $module || insmod /lib/modules/$module.ko
insmod /lib/modules/$module.ko
fi
done
if ! [ -e /sys/class/net/usb0 ]; then

View File

@ -23,6 +23,14 @@ if [ ! -r "$MODULE" ]; then
die "$MODULE: not found?"
fi
# Check if module is already loaded while remove trailing .ko if present
module=$(basename "$MODULE")
module=${module%.ko}
if lsmod | grep -q "^$module\\b"; then
DEBUG "$module: already loaded"
exit 0
fi
if [ ! -r /sys/class/tpm/tpm0/pcrs -o ! -x /bin/tpm ]; then
if [ ! -c /dev/tpmrm0 -o ! -x /bin/tpm2 ]; then
tpm_missing=1
@ -48,4 +56,4 @@ fi
# the busybox insmod via the original executable
DEBUG "Loading $MODULE with busybox insmod"
busybox insmod "$MODULE" "$@" \
|| die "$MODULE: insmod failed"
|| die "$MODULE: insmod failed"