kernel_samsung_a53x/scripts/kconfig
Masahiro Yamada 8b43658bc7 kconfig: fix comparison to constant symbols, 'm', 'n'
[ 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: 31847b67bec0 ("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-11-19 12:27:10 +01:00
..
lxdialog Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tests Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
conf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
confdata.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
expr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
expr.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gconf-cfg.sh Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gconf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gconf.glade Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
images.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
images.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lexer.l kconfig: fix infinite loop when expanding a macro at the end of file 2024-11-19 08:44:58 +01:00
list.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lkc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lkc_proto.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mconf-cfg.sh Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mconf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
menu.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
merge_config.sh Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nconf-cfg.sh Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nconf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nconf.gui.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nconf.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
parser.y Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
preprocess.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
qconf-cfg.sh Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
qconf.cc Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
qconf.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
streamline_config.pl Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
symbol.c kconfig: fix comparison to constant symbols, 'm', 'n' 2024-11-19 12:27:10 +01:00
util.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00