Ubuntu-focal-kernel/scripts
Masahiro Yamada 66f0c66bef kconfig: fix comparison to constant symbols, 'm', 'n'
BugLink: https://bugs.launchpad.net/bugs/2071668

[ Upstream commit aabdc960a283ba78086b0bf66ee74326f49e218e ]

Currently, comparisons to 'm' or 'n' result in incorrect output.

[Test Code]

    config MODULES
            def_bool y
            modules

    config A
            def_tristate m

    config B
            def_bool A > n

CONFIG_B is unset, while CONFIG_B=y is expected.

The reason for the issue is because Kconfig compares the tristate values
as strings.

Currently, the .type fields in the constant symbol definitions,
symbol_{yes,mod,no} are unspecified, i.e., S_UNKNOWN.

When expr_calc_value() evaluates 'A > n', it checks the types of 'A' and
'n' to determine how to compare them.

The left-hand side, 'A', is a tristate symbol with a value of 'm', which
corresponds to a numeric value of 1. (Internally, 'y', 'm', and 'n' are
represented as 2, 1, and 0, respectively.)

The right-hand side, 'n', has an unknown type, so it is treated as the
string "n" during the comparison.

expr_calc_value() compares two values numerically only when both can
have numeric values. Otherwise, they are compared as strings.

    symbol    numeric value    ASCII code
    -------------------------------------
      y           2             0x79
      m           1             0x6d
      n           0             0x6e

'm' is greater than 'n' if compared numerically (since 1 is greater
than 0), but smaller than 'n' if compared as strings (since the ASCII
code 0x6d is smaller than 0x6e).

Specifying .type=S_TRISTATE for symbol_{yes,mod,no} fixes the above
test code.

Doing so, however, would cause a regression to the following test code.

[Test Code 2]

    config MODULES
            def_bool n
            modules

    config A
            def_tristate n

    config B
            def_bool A = m

You would get CONFIG_B=y, while CONFIG_B should not be set.

The reason is because sym_get_string_value() turns 'm' into 'n' when the
module feature is disabled. Consequently, expr_calc_value() evaluates
'A = n' instead of 'A = m'. This oddity has been hidden because the type
of 'm' was previously S_UNKNOWN instead of S_TRISTATE.

sym_get_string_value() should not tweak the string because the tristate
value has already been correctly calculated. There is no reason to
return the string "n" where its tristate value is mod.

Fixes: 31847b67be ("kconfig: allow use of relations other than (in)equality")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Portia Stephens <portia.stephens@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2024-07-05 10:52:02 +02:00
..
atomic
basic
coccinelle
dtc scripts/dtc: dtx_diff: remove broken example from help text 2022-03-07 16:37:02 +01:00
gcc-plugins randstruct: Fix gcc-plugin performance mode to stay in group 2024-02-02 14:13:09 +01:00
gdb scripts/gdb: fix lx-timerlist for Python3 2023-08-09 12:25:23 +02:00
genksyms
kconfig kconfig: fix comparison to constant symbols, 'm', 'n' 2024-07-05 10:52:02 +02:00
ksymoops
mod modpost: fix tee MODULE_DEVICE_TABLE built on big-endian host 2024-02-02 14:13:05 +01:00
package
selinux selinux: use "grep -E" instead of "egrep" 2023-01-06 08:43:54 -08:00
tracing ftrace/scripts: Update the instructions for ftrace-bisect.sh 2023-03-21 10:08:59 +01:00
.gitignore
Kbuild.include kbuild: remove the target in signal traps when interrupted 2023-01-06 08:44:02 -08:00
Kconfig.include
Lindent
Makefile certs: Add ability to preload revocation certs 2021-11-24 15:28:34 +01:00
Makefile.asm-generic
Makefile.build kbuild: Fix objtool dependency for 'OBJECT_FILES_NON_STANDARD_<obj> := n' 2021-08-13 09:45:24 +02:00
Makefile.clean
Makefile.dtbinst
Makefile.extrawarn kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 2024-06-07 15:01:35 +02:00
Makefile.gcc-plugins gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file 2022-10-17 15:01:52 +02:00
Makefile.headersinst
Makefile.host
Makefile.kasan
Makefile.kcov
Makefile.lib
Makefile.modbuiltin
Makefile.modfinal
Makefile.modinst
Makefile.modpost kbuild: Fix include path in scripts/Makefile.modpost 2022-10-17 15:02:22 +02:00
Makefile.modsign
Makefile.package
Makefile.ubsan
adjust_autoksyms.sh
asn1_compiler.c ASN.1: Fix check for strdup() success 2023-08-09 12:25:13 +02:00
bin2c.c
bloat-o-meter scripts: switch explicitly to Python 3 2021-06-18 15:02:28 +02:00
bootgraph.pl
bpf_helpers_doc.py scripts/bpf: Fix xdp_md forward declaration typo 2024-04-26 10:54:09 +02:00
cc-can-link.sh
check_extable.sh
checkincludes.pl
checkkconfigsymbols.py
checkpatch.pl
checkstack.pl
checksyscalls.sh
checkversion.pl
clang-version.sh
cleanfile
cleanpatch
coccicheck
config tweewide: Fix most Shebang lines 2021-06-18 15:02:27 +02:00
conmakehash.c
const_structs.checkpatch
decode_stacktrace.sh
decodecode
depmod.sh
diffconfig scripts: switch explicitly to Python 3 2021-06-18 15:02:28 +02:00
documentation-file-ref-check
export_report.pl
extract-cert.c cert host tools: Stop complaining about deprecated OpenSSL functions 2023-02-01 15:21:02 +01:00
extract-ikconfig
extract-module-sig.pl
extract-sys-certs.pl
extract-vmlinux
extract_xc3028.pl
faddr2line scripts/faddr2line: Fix regression in name resolution on ppc64le 2023-02-01 15:21:36 +01:00
file-size.sh
find-unused-docs.sh
gcc-goto.sh
gcc-ld
gcc-plugin.sh
gcc-version.sh
gcc-x86_32-has-stack-protector.sh
gcc-x86_64-has-stack-protector.sh
gen_compile_commands.py
gen_ksymdeps.sh kbuild: Fix 'no symbols' warning when CONFIG_TRIM_UNUSD_KSYMS=y 2021-10-12 16:31:27 -06:00
get_abi.pl tweewide: Fix most Shebang lines 2021-06-18 15:02:27 +02:00
get_dvb_firmware
get_maintainer.pl
gfp-translate
headerdep.pl
headers_check.pl
headers_install.sh
insert-sys-cert.c
kallsyms.c
kernel-doc stddef: Introduce DECLARE_FLEX_ARRAY() helper 2024-04-26 10:54:12 +02:00
kmsg-doc
ld-version.sh
leaking_addresses.pl leaking_addresses: Always print a trailing newline 2022-01-13 18:42:10 +01:00
link-vmlinux.sh kbuild: Fix changing ELF file type for output of gen_btf for big endian 2024-03-28 15:18:42 +01:00
makelst
markup_oops.pl
mkcompile_h kbuild: mkcompile_h: consider timestamp if KBUILD_BUILD_TIMESTAMP is set 2021-09-20 18:49:15 +02:00
mkmakefile
mksysmap mksysmap: Fix the mismatch of 'L0' symbols in System.map 2022-11-24 10:28:30 +01:00
mkuboot.sh
module-common.lds
modules-check.sh
namespace.pl
nsdeps
objdiff
parse-maintainers.pl
patch-kernel
pnmtologo.c
profile2linkerlist.pl
prune-kernel
recordmcount.c recordmcount: Fix memory leaks in the uwrite function 2023-08-09 12:25:29 +02:00
recordmcount.h recordmcount: Correct st_shndx handling 2021-08-13 09:44:22 +02:00
recordmcount.pl recordmcount.pl: fix typo in s390 mcount regex 2022-03-07 16:34:40 +01:00
setlocalversion
show_delta tweewide: Fix most Shebang lines 2021-06-18 15:02:27 +02:00
sign-file.c sign-file: Fix incorrect return values check 2024-02-02 14:13:21 +01:00
sortextable.c
sortextable.h
spdxcheck-test.sh
spdxcheck.py
spelling.txt
sphinx-pre-install tweewide: Fix most Shebang lines 2021-06-18 15:02:27 +02:00
split-man.pl tweewide: Fix most Shebang lines 2021-06-18 15:02:27 +02:00
stackdelta
stackusage
subarch.include
tags.sh scripts/tags.sh: Resolve gtags empty index generation 2023-10-02 12:12:00 +02:00
tools-support-relr.sh Makefile: fix GDB warning with CONFIG_RELR 2021-08-13 09:45:07 +02:00
unifdef.c
ver_linux
xen-hypercalls.sh
xz_wrap.sh