linux-stable/scripts/kconfig
Masahiro Yamada c3438b829f kconfig: fix comparison to constant symbols, 'm', 'n'
[ Upstream commit aabdc960a2 ]

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>
2024-06-12 11:39:54 +02:00
..
lxdialog kconfig: Fix typo HEIGTH to HEIGHT 2024-03-31 21:09:50 +09:00
tests kconfig: tests: test dependency after shuffling choices 2024-03-21 02:40:39 +09:00
.gitignore kconfig: Update all declared targets 2023-01-13 16:29:52 +09:00
Makefile kconfig: Use KCONFIG_CONFIG instead of .config 2023-12-28 16:22:47 +09:00
array_size.h kconfig: move ARRAY_SIZE to a header 2024-02-19 18:20:41 +09:00
conf.c kconfig: do not reparent the menu inside a choice block 2024-03-28 11:02:13 +09:00
confdata.c kconfig: remove unneeded menu_is_visible() call in conf_write_defconfig() 2024-03-19 02:30:51 +09:00
expr.c kconfig: remove unreachable printf() 2023-12-28 16:22:47 +09:00
expr.h kconfig: link menus to a symbol 2024-03-09 15:01:00 +09:00
gconf-cfg.sh kconfig: refactor Makefile to reduce process forks 2022-12-13 22:29:10 +09:00
gconf.c kconfig: gconfig: correct program name in help text 2023-07-12 23:46:57 +09:00
gconf.glade scripts/kconfig/gconf.glade Update broken web addresses. 2010-09-17 16:54:42 +02:00
hashtable.h kconfig: add macros useful for hashtable 2024-02-19 18:20:41 +09:00
images.c kconfig: constify XPM data 2020-08-14 13:30:03 +09:00
images.h kconfig: constify XPM data 2020-08-14 13:30:03 +09:00
internal.h kconfig: use generic macros to implement symbol hashtable 2024-02-20 20:47:45 +09:00
lexer.l kconfig: change file_lookup() to return the file name 2024-02-19 18:20:41 +09:00
list.h kconfig: import more list macros and inline functions 2024-02-19 18:20:41 +09:00
list_types.h kconfig: import more list macros and inline functions 2024-02-19 18:20:41 +09:00
lkc.h kconfig: do not reparent the menu inside a choice block 2024-03-28 11:02:13 +09:00
lkc_proto.h kconfig: use generic macros to implement symbol hashtable 2024-02-20 20:47:45 +09:00
mconf-cfg.sh kconfig: refactor Makefile to reduce process forks 2022-12-13 22:29:10 +09:00
mconf.c kconfig: Fix typo HEIGTH to HEIGHT 2024-03-31 21:09:50 +09:00
menu.c kconfig: do not reparent the menu inside a choice block 2024-03-28 11:02:13 +09:00
merge_config.sh scripts: merge_config: Fix typo in variable name. 2023-03-23 15:27:40 +09:00
mnconf-common.c kconfig: factor out common code shared by mconf and nconf 2023-12-10 15:34:37 +09:00
mnconf-common.h kconfig: factor out common code shared by mconf and nconf 2023-12-10 15:34:37 +09:00
nconf-cfg.sh kconfig: refactor Makefile to reduce process forks 2022-12-13 22:29:10 +09:00
nconf.c kconfig: split list_head into a separate header 2024-02-19 18:20:41 +09:00
nconf.gui.c kconfig: nconf: Add search jump feature 2023-08-13 21:29:41 +09:00
nconf.h kconfig: nconf: Add search jump feature 2023-08-13 21:29:41 +09:00
parser.y kconfig: do not reparent the menu inside a choice block 2024-03-28 11:02:13 +09:00
preprocess.c kconfig: move ARRAY_SIZE to a header 2024-02-19 18:20:41 +09:00
preprocess.h kconfig: split preprocessor prototypes into preprocess.h 2024-02-19 18:20:40 +09:00
qconf-cfg.sh kconfig: port qconf to work with Qt6 in addition to Qt5 2023-08-16 12:06:29 +09:00
qconf.cc kconfig: associate struct menu with file name directly 2024-02-19 18:20:40 +09:00
qconf.h kconfig: qconf: remove Y, M, N columns 2020-09-25 00:37:13 +09:00
streamline_config.pl streamline_config.pl: handle also ${CONFIG_FOO} 2023-06-08 11:11:32 +09:00
symbol.c kconfig: fix comparison to constant symbols, 'm', 'n' 2024-06-12 11:39:54 +02:00
util.c kconfig: convert linked list of files to hash table 2024-02-20 20:44:48 +09:00