Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

test_firmware: enable custom fallback testing on limited kernel configs

When a kernel is not built with:

CONFIG_HAS_FW_LOADER_USER_HELPER_FALLBACK=y

We don't currently enable testing fw_fallback.sh. For kernels that
still enable the fallback mechanism, its possible to use the async
request firmware API call request_firmware_nowait() using the custom
interface to use the fallback mechanism, so we should be able to test
this but we currently cannot.

We can enable testing without CONFIG_HAS_FW_LOADER_USER_HELPER_FALLBACK=y
by relying on /proc/config.gz (CONFIG_IKCONFIG_PROC), if present. If you
don't have this we'll have no option but to rely on old heuristics for now.

We stuff the new kconfig_has() helper into our shared library as we'll
later expando on its use elsewhere.

Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Luis R. Rodriguez and committed by
Greg Kroah-Hartman
ef557787 29a1c00c

+33 -1
+4
tools/testing/selftests/firmware/config
··· 1 1 CONFIG_TEST_FIRMWARE=y 2 + CONFIG_FW_LOADER=y 3 + CONFIG_FW_LOADER_USER_HELPER=y 4 + CONFIG_IKCONFIG=y 5 + CONFIG_IKCONFIG_PROC=y
+5 -1
tools/testing/selftests/firmware/fw_fallback.sh
··· 15 15 # These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that 16 16 # as an indicator for CONFIG_FW_LOADER_USER_HELPER. 17 17 HAS_FW_LOADER_USER_HELPER=$(if [ -d /sys/class/firmware/ ]; then echo yes; else echo no; fi) 18 + HAS_FW_LOADER_USER_HELPER_FALLBACK=$(kconfig_has CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y) 18 19 19 20 if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then 20 21 OLD_TIMEOUT=$(cat /sys/class/firmware/timeout) ··· 288 287 fi 289 288 } 290 289 291 - run_sysfs_main_tests 290 + if [ "$HAS_FW_LOADER_USER_HELPER_FALLBACK" = "yes" ]; then 291 + run_sysfs_main_tests 292 + fi 293 + 292 294 run_sysfs_custom_load_tests 293 295 294 296 exit 0
+24
tools/testing/selftests/firmware/fw_lib.sh
··· 42 42 fi 43 43 fi 44 44 } 45 + 46 + kconfig_has() 47 + { 48 + if [ -f $PROC_CONFIG ]; then 49 + if zgrep -q $1 $PROC_CONFIG 2>/dev/null; then 50 + echo "yes" 51 + else 52 + echo "no" 53 + fi 54 + else 55 + # We currently don't have easy heuristics to infer this 56 + # so best we can do is just try to use the kernel assuming 57 + # you had enabled it. This matches the old behaviour. 58 + if [ "$1" = "CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y" ]; then 59 + echo "yes" 60 + elif [ "$1" = "CONFIG_FW_LOADER_USER_HELPER=y" ]; then 61 + if [ -d /sys/class/firmware/ ]; then 62 + echo yes 63 + else 64 + echo no 65 + fi 66 + fi 67 + fi 68 + }