Skip to content

Commit 1d0fbb3

Browse files
mcgrofgregkh
authored andcommitted
selftests: firmware: skip timeout checks for kernels without user mode helper
The CONFIG_FW_LOADER_USER_HELPER is mostly disabled these days, so skip timeout setting for these kernels. Signed-off-by: Luis R. Rodriguez <[email protected]> Acked-by: Kees Cook <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 71cf5ae commit 1d0fbb3

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

tools/testing/selftests/firmware/fw_filesystem.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,37 @@ modprobe test_firmware
99

1010
DIR=/sys/devices/virtual/misc/test_firmware
1111

12-
OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
12+
# CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/
13+
# These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that
14+
# as an indicator for CONFIG_FW_LOADER_USER_HELPER.
15+
HAS_FW_LOADER_USER_HELPER=$(if [ -d /sys/class/firmware/ ]; then echo yes; else echo no; fi)
16+
17+
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
18+
OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
19+
fi
20+
1321
OLD_FWPATH=$(cat /sys/module/firmware_class/parameters/path)
1422

1523
FWPATH=$(mktemp -d)
1624
FW="$FWPATH/test-firmware.bin"
1725

1826
test_finish()
1927
{
20-
echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
28+
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
29+
echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
30+
fi
2131
echo -n "$OLD_PATH" >/sys/module/firmware_class/parameters/path
2232
rm -f "$FW"
2333
rmdir "$FWPATH"
2434
}
2535

2636
trap "test_finish" EXIT
2737

28-
# Turn down the timeout so failures don't take so long.
29-
echo 1 >/sys/class/firmware/timeout
38+
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
39+
# Turn down the timeout so failures don't take so long.
40+
echo 1 >/sys/class/firmware/timeout
41+
fi
42+
3043
# Set the kernel search path.
3144
echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path
3245

@@ -41,7 +54,9 @@ if diff -q "$FW" /dev/test_firmware >/dev/null ; then
4154
echo "$0: firmware was not expected to match" >&2
4255
exit 1
4356
else
44-
echo "$0: timeout works"
57+
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
58+
echo "$0: timeout works"
59+
fi
4560
fi
4661

4762
# This should succeed via kernel load or will fail after 1 second after

tools/testing/selftests/firmware/fw_userhelper.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ modprobe test_firmware
99

1010
DIR=/sys/devices/virtual/misc/test_firmware
1111

12-
OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
12+
# CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/
13+
# These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that
14+
# as an indicator for CONFIG_FW_LOADER_USER_HELPER.
15+
HAS_FW_LOADER_USER_HELPER=$(if [ -d /sys/class/firmware/ ]; then echo yes; else echo no; fi)
16+
17+
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
18+
OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
19+
else
20+
echo "usermode helper disabled so ignoring test"
21+
exit 0
22+
fi
1323

1424
FWPATH=$(mktemp -d)
1525
FW="$FWPATH/test-firmware.bin"

0 commit comments

Comments
 (0)