]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
04watchdog-modules: Simplify install_kernel using new added helper
authorKairui Song <kasong@redhat.com>
Mon, 12 Oct 2020 07:28:40 +0000 (15:28 +0800)
committerHarald Hoyer <harald@hoyer.xyz>
Fri, 30 Oct 2020 09:13:37 +0000 (10:13 +0100)
The new added get_dev_modules helper can help simplify the driver
detection code by a lot.

Signed-off-by: Kairui Song <kasong@redhat.com>
modules.d/04watchdog-modules/module-setup.sh

index 5fbd769b43fdc1296502f490a0bc0711db8fb4fb..705592fac4cbcb633938a292100f94c895bdab1a 100755 (executable)
@@ -18,41 +18,18 @@ install() {
 installkernel() {
     local -A _drivers
     local _alldrivers _wdtdrv _wdtppath _dir
-    [[ -d /sys/class/watchdog/ ]] || return
-    for _dir in /sys/class/watchdog/*; do
-        [[ -d "$_dir" ]] || continue
-        [[ -f "$_dir/state" ]] || continue
-        # device/modalias will return driver of this device
-        _wdtdrv=$(< "$_dir/device/modalias")
-        # There can be more than one module represented by same
-        # modalias. Currently load all of them.
-        # TODO: Need to find a way to avoid any unwanted module
-        # represented by modalias
-        _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
+
+    for _wd in /sys/class/watchdog/*; do
+        ! [ -e $_wd ] && continue
+        _wdtdrv=$(get_dev_module $_wd)
         if [[ $_wdtdrv ]]; then
             instmods $_wdtdrv
             for i in $_wdtdrv; do
                 _drivers[$i]=1
             done
         fi
-        # however in some cases, we also need to check that if there is
-        # a specific driver for the parent bus/device.  In such cases
-        # we also need to enable driver for parent bus/device.
-        _wdtppath=$(readlink -f "$_dir/device")
-        while [[ -d "$_wdtppath" ]] && [[ "$_wdtppath" != "/sys" ]]; do
-            _wdtppath=$(readlink -f "$_wdtppath/..")
-            [[ -f "$_wdtppath/modalias" ]] || continue
-
-            _wdtdrv=$(< "$_wdtppath/modalias")
-            _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
-            if [[ $_wdtdrv ]]; then
-                instmods $_wdtdrv
-                for i in $_wdtdrv; do
-                    _drivers[$i]=1
-                done
-            fi
-        done
     done
+
     # ensure that watchdog module is loaded as early as possible
     _alldrivers="${!_drivers[*]}"
     [[ $_alldrivers ]] && echo "rd.driver.pre=${_alldrivers// /,}" > ${initdir}/etc/cmdline.d/00-watchdog.conf