Commit Graph

1205 Commits

Author SHA1 Message Date
Masahiro Yamada
77a92660d8 kconfig: remove wrong expr_trans_bool()
expr_trans_bool() performs an incorrect transformation.

[Test Code]

    config MODULES
            def_bool y
            modules

    config A
            def_bool y
            select C if B != n

    config B
            def_tristate m

    config C
            tristate

[Result]

    CONFIG_MODULES=y
    CONFIG_A=y
    CONFIG_B=m
    CONFIG_C=m

This output is incorrect because CONFIG_C=y is expected.

Documentation/kbuild/kconfig-language.rst clearly explains the function
of the '!=' operator:

    If the values of both symbols are equal, it returns 'n',
    otherwise 'y'.

Therefore, the statement:

    select C if B != n

should be equivalent to:

    select C if y

Or, more simply:

    select C

Hence, the symbol C should be selected by the value of A, which is 'y'.

However, expr_trans_bool() wrongly transforms it to:

    select C if B

Therefore, the symbol C is selected by (A && B), which is 'm'.

The comment block of expr_trans_bool() correctly explains its intention:

  * bool FOO!=n => FOO
    ^^^^

If FOO is bool, FOO!=n can be simplified into FOO. This is correct.

However, the actual code performs this transformation when FOO is
tristate:

    if (e->left.sym->type == S_TRISTATE) {
                             ^^^^^^^^^^

While it can be fixed to S_BOOLEAN, there is no point in doing so
because expr_tranform() already transforms FOO!=n to FOO when FOO is
bool. (see the "case E_UNEQUAL" part)

expr_trans_bool() is wrong and unnecessary.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
2024-06-06 20:09:10 +09:00
Masahiro Yamada
46edf4372e kconfig: gconf: give a proper initial state to the Save button
Currently, the initial state of the "Save" button is always active.

If none of the CONFIG options are changed while loading the .config
file, the "Save" button should be greyed out.

This can be fixed by calling conf_read() after widget initialization.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-06-06 20:03:16 +09:00
Masahiro Yamada
c181689bc4 kconfig: remove unneeded code for user-supplied values being out of range
This is a leftover from commit ce1fc9345a ("kconfig: do not clear
SYMBOL_DEF_USER when the value is out of range").

This code is now redundant because if a user-supplied value is out
of range, the value adjusted by sym_validate_range() differs, and
conf_unsaved has already been incremented a few lines above.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-06-06 20:03:14 +09:00
Masahiro Yamada
31894d35b5 kconfig: remove redundant check in expr_join_or()
The check for 'sym1 == sym2' is redundant here because it has already
been done a few lines above:

    if (sym1 != sym2)
            return NULL;

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-29 16:40:03 +09:00
Masahiro Yamada
aabdc960a2 kconfig: fix comparison to constant symbols, 'm', 'n'
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>
2024-05-29 16:40:03 +09:00
Masahiro Yamada
a607468b52 kconfig: remove unused expr_is_no()
This has not been used since commit e911503085 ("Kconfig: Remove
bad inference rules expr_eliminate_dups2()").

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-29 16:40:03 +09:00
Masahiro Yamada
6ffe4fdf89 kconfig: use sym_get_choice_menu() in sym_check_prop()
Choices and their members are associated via the P_CHOICE property.

Currently, prop_get_symbol(sym_get_choice_prop()) is used to obtain
the choice of the given choice member.

Replace it with sym_get_choice_menu(), which retrieves the choice
without relying on P_CHOICE.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-16 03:18:41 +09:00
Masahiro Yamada
01b9916254 kconfig: lxdialog: remove initialization with A_NORMAL
A_NORMAL is zero, so the attribute is set to the default A_NORMAL
without explicit assignment.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-14 23:36:19 +09:00
Masahiro Yamada
648d82a984 kconfig: m/nconf: merge two item_add_str() calls
Just trivial cleanups.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-14 23:36:19 +09:00
Masahiro Yamada
cc3e4e5e38 kconfig: m/nconf: remove dead code to display value of bool choice
Previously, optional bool choices met the following conditions
simultaneously:

 - sym_is_choice(sym)
 - sym_is_changeable(sym)
 - type == S_BOOLEAN

It no longer occurs since 6a1215888e ("kconfig: remove 'optional'
property support"). Remove the dead code.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-14 23:36:19 +09:00
Masahiro Yamada
e89b46159c kconfig: m/nconf: remove dead code to display children of choice members
This code previously displayed child symbols of the selected choice
member.

Since commit 7e3465f63a ("kconfig: do not reparent the menu inside
a choice block"), choice members never have child symbols, therefore
this is dead code.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-14 23:36:19 +09:00
Masahiro Yamada
6ba750ddeb kconfig: gconf: show checkbox for choice correctly
Currently, bool choices have a checkbox, but tristate choices do not.
It is opposite.

Bool choices should not have a checkbox, as they are fixed to 'y' since
commit 6a1215888e ("kconfig: remove 'optional' property support").
Tristate choices, however, should have a checkbox to allow users to
toggle the value.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-14 23:36:19 +09:00
Masahiro Yamada
dfff05cc10 kconfig: use menu_list_for_each_sym() in sym_check_choice_deps()
Choices and their members are associated via the P_CHOICE property.

Currently, sym_get_choice_prop() and expr_list_for_each_sym() are
used to iterate on choice members.

Replace them with menu_for_each_sub_entry(), which achieves the same
without relying on P_CHOICE.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:53 +09:00
Masahiro Yamada
fb8dd48214 kconfig: use sym_get_choice_menu() in conf_write_defconfig()
Choices and their members are associated via the P_CHOICE property.

Currently, prop_get_symbol(sym_get_choice_prop()) is used to obtain
the choice of the given choice member.

Replace it with sym_get_choice_menu(), which retrieves the choice
without relying on P_CHOICE.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:53 +09:00
Masahiro Yamada
7bcf2e03b5 kconfig: add sym_get_choice_menu() helper
Choices and their members are associated via the P_CHOICE property.

Currently, prop_get_symbol(sym_get_choice_prop()) is used to obtain
the choice of the given choice member.

We can do this without relying on P_CHOICE by checking the parent in
the menu structure.

Introduce a new helper to retrieve the choice if the given symbol is a
choice member.

This is intended to replace prop_get_symbol(sym_get_choice_prop()) and
deprecate P_CHOICE eventually.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:53 +09:00
Masahiro Yamada
8a22f867e3 kconfig: turn defaults and additional prompt for choice members into error
menu_finalize() warns default properties for choice members and prompts
outside the choice block. These should be hard errors.

While I was here, I moved the checks to slim down menu_finalize().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:53 +09:00
Masahiro Yamada
700e7a8d05 kconfig: turn missing prompt for choice members into error
Choice members must have a prompt; hence make it an error.

While I was here, I moved the check to the parser to slim down
_menu_finalize().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:53 +09:00
Masahiro Yamada
8c00e58005 kconfig: turn conf_choice() into void function
The return value of conf_choice() is not used.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:53 +09:00
Masahiro Yamada
7d2806746d kconfig: use linked list in sym_set_changed()
Following the approach employed in commit bedf923623 ("kconfig: use
linked list in get_symbol_str() to iterate over menus"), simplify the
iteration on the menus of the specified symbol.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:52 +09:00
Masahiro Yamada
4cc7e6cef3 kconfig: gconf: use MENU_CHANGED instead of SYMBOL_CHANGED
SYMBOL_CHANGED and MENU_CHANGED are used to update GUI frontends
when the symbol value is changed. These are used inconsistently:
SYMBOL_CHANGED in gconf.c and MENU_CHANGE in qconf.cc.

MENU_CHANGED works more properly when a symbol has multiple prompts
(although such code is not ideal).

[test code]

    config FOO
            bool "foo prompt 1"

    config FOO
            bool "foo prompt 2"

In gconfig, if one of the two checkboxes is clicked, only the first
one is toggled. In xconfig, the two checkboxes work in sync.

Replace SYMBOL_CHANGED in gconf.c with MENU_CHANGED to align with
the xconfig behavior.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:52 +09:00
Masahiro Yamada
a7efb160f6 kconfig: gconf: remove debug code
This is not so useful. If necessary, you can insert printf() or
whatever during debugging.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:52 +09:00
Masahiro Yamada
4763175ad2 kconfig: gconf: update pane correctly after loading a config file
Every time a config file is loaded (either by clicking the "Load" button
or selecting "File" -> "Load" from the menu), a new list is appended to
the pane.

The current tree needs to be cleared by calling gtk_tree_store_clear().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-10 04:34:52 +09:00
Masahiro Yamada
b1992c3772 kbuild: use $(src) instead of $(srctree)/$(src) for source directory
Kbuild conventionally uses $(obj)/ for generated files, and $(src)/ for
checked-in source files. It is merely a convention without any functional
difference. In fact, $(obj) and $(src) are exactly the same, as defined
in scripts/Makefile.build:

    src := $(obj)

When the kernel is built in a separate output directory, $(src) does
not accurately reflect the source directory location. While Kbuild
resolves this discrepancy by specifying VPATH=$(srctree) to search for
source files, it does not cover all cases. For example, when adding a
header search path for local headers, -I$(srctree)/$(src) is typically
passed to the compiler.

This introduces inconsistency between upstream and downstream Makefiles
because $(src) is used instead of $(srctree)/$(src) for the latter.

To address this inconsistency, this commit changes the semantics of
$(src) so that it always points to the directory in the source tree.

Going forward, the variables used in Makefiles will have the following
meanings:

  $(obj)     - directory in the object tree
  $(src)     - directory in the source tree  (changed by this commit)
  $(objtree) - the top of the kernel object tree
  $(srctree) - the top of the kernel source tree

Consequently, $(srctree)/$(src) in upstream Makefiles need to be replaced
with $(src).

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2024-05-10 04:34:52 +09:00
Masahiro Yamada
a7c79cf3e4 kconfig: remove SYMBOL_NO_WRITE flag
This flag is set to symbols that are not intended to be written
to the .config file.

Since commit b75b0a819a ("kconfig: change defconfig_list option to
environment variable"), SYMBOL_NO_WRITE is only set to choices.

Therefore, (sym->flags & SYMBOL_NO_WRITE) is equivalent to
sym_is_choice(sym). This flag is no longer necessary.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-02 20:14:16 +09:00
Masahiro Yamada
6a1215888e kconfig: remove 'optional' property support
The 'choice' statement is primarily used to exclusively select one
option, but the 'optional' property allows all entries to be disabled.

In the following example, both A and B can be disabled simultaneously:

    choice
            prompt "choose A, B, or nothing"
            optional

    config A
            bool "A"

    config B
            bool "B"

    endchoice

You can achieve the equivalent outcome by other means.

A common solution is to add another option to guard the choice block.
In the following example, you can set ENABLE_A_B_CHOICE=n to disable
the entire choice block:

    choice
            prompt "choose A or B"
            depends on ENABLE_A_B_CHOICE

    config A
            bool "A"

    config B
            bool "B"

    endchoice

Another approach is to insert one more entry:

    choice
            prompt "choose A, B, or disable both"

    config A
            bool "A"

    config B
            bool "B"

    config DISABLE_A_AND_B
            bool "choose this to disable both A and B"

    endchoice

Some real examples are DEBUG_INFO_NONE, INITRAMFS_COMPRESSION_NONE,
LTO_NONE, etc.

The 'optional' property is even more unnecessary for a tristate choice.

Without the 'optional' property, you can disable A and B; you can set
'm' in the choice prompt, and disable A and B individually:

    choice
            prompt "choose one built-in or make them modular"

    config A
            tristate "A"

    config B
            tristate "B"

    endchoice

In conclusion, the 'optional' property was unneeded.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
2024-05-02 19:48:26 +09:00
Masahiro Yamada
1da251c60d kconfig: remove SYMBOL_CHOICE flag
All symbols except choices have a name.

Previously, choices were allowed to have a name, but commit c83f020973
("kconfig: remove named choice support") eliminated that possibility.

Now, it is easy to distinguish choices from normal symbols; if the name
is NULL, it is a choice.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
2024-05-02 19:48:26 +09:00
Masahiro Yamada
c2af3d03c5 kconfig: remove unneeded if-conditional in conf_choice()
All symbols except choices have a name.

child->sym->name never becomes NULL inside choice blocks.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-02 19:48:26 +09:00
Masahiro Yamada
03c4ecaa5c kconfig: use menu_for_each_entry() to traverse menu tree
Use menu_for_each_entry() to traverse the menu tree instead of
implementing similar logic in each function.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-02 19:48:26 +09:00
Masahiro Yamada
7284b4fbc8 kconfig: add menu_next() function and menu_for_each(_sub)_entry macros
Several functions require traversing menu entries sequentially. This
commit introduces some helpers to simplify such operations.

The menu_next() function facilitates depth-first traversal:

 1. Descend to the child level if the current menu has one
 2. Move to the next sibling at the same level if available
 3. Ascend to the parent level if there is no more child or sibling

The menu_for_each_sub_entry() macro iterates over all submenu entries
using depth-first traverse.

The menu_for_each_entry() macro is the same, but over all menu entries.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-02 19:48:26 +09:00
Isak Ellmer
89e5462bb5 kconfig: Fix typo HEIGTH to HEIGHT
Fixed a typo in some variables where height was misspelled as heigth.

Signed-off-by: Isak Ellmer <isak01@gmail.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-03-31 21:09:50 +09:00
Masahiro Yamada
7e3465f63a kconfig: do not reparent the menu inside a choice block
The boolean 'choice' is used to list exclusively selected config
options.

You must not add a dependency between choice members, because such a
dependency would create an invisible entry.

In the following test case, it is impossible to choose 'C'.

[Test Case 1]

  choice
          prompt "Choose one, but how to choose C?"

  config A
          bool "A"

  config B
          bool "B"

  config C
          bool "C"
          depends on A

  endchoice

Hence, Kconfig shows the following error message:

  Kconfig:1:error: recursive dependency detected!
  Kconfig:1:      choice <choice> contains symbol C
  Kconfig:10:     symbol C is part of choice A
  Kconfig:4:      symbol A is part of choice <choice>
  For a resolution refer to Documentation/kbuild/kconfig-language.rst
  subsection "Kconfig recursive dependency limitations"

However, Kconfig does not report anything for the following similar code:

[Test Case 2]

  choice
         prompt "Choose one, but how to choose B?"

  config A
          bool "A"

  config B
          bool "B"
          depends on A

  config C
          bool "C"

  endchoice

This is because menu_finalize() reparents the menu tree when an entry
depends on the preceding one.

With reparenting, the menu tree:

  choice
   |- A
   |- B
   \- C

... will be transformed into the following structure:

  choice
   |- A
   |  \- B
   \- C

Consequently, Kconfig considers only 'A' and 'C' as choice members.
This behavior is awkward. The second test case should be an error too.

This commit stops reparenting inside a choice.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-03-28 11:02:13 +09:00
Masahiro Yamada
f2fd2aad19 kconfig: tests: test dependency after shuffling choices
Commit c8fb7d7e48 ("kconfig: fix broken dependency in randconfig-
generated .config") fixed the issue, but I did not add a test case.

This commit adds a test case that emulates the reported situation.
The test would fail without c8fb7d7e48.

To handle the choice "choose X", FOO must be calculated beforehand.
FOO depends on A, which is a member of another choice "choose A or B".
Kconfig _temporarily_ assumes the value of A to proceed. The choice
"choose A or B" will be shuffled later, but the result may or may not
meet "FOO depends on A". Kconfig should invalidate the symbol values
and recompute them.

In the real example for ARCH=arm64, the choice "Instrumentation type"
needs the value of CPU_BIG_ENDIAN. The choice "Endianness" will be
shuffled later.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-03-21 02:40:39 +09:00
Masahiro Yamada
47ad16894c kconfig: tests: add a test for randconfig with dependent choices
Since commit 3b9a19e089 ("kconfig: loop as long as we changed some
symbols in randconfig"), conf_set_all_new_symbols() is repeated until
there is no more choice left to be shuffled. The motivation was to
shuffle a choice nested in another choice.

Although commit 09d5873e4d ("kconfig: allow only 'config', 'comment',
and 'if' inside 'choice'") disallowed the nested choice structure,
we must still keep 3b9a19e089 because there are still cases where
conf_set_all_new_symbols() must iterate.

scripts/kconfig/tests/choice_randomize/Kconfig is the test case.
The second choice depends on 'B', which is the member of the first
choice.

With 3b9a19e089 reverted, we would never get the pattern specified by
scripts/kconfig/tests/choice_randomize/expected_config2.

A real example can be found in lib/Kconfig.debug. Without 3b9a19e089,
the randconfig would not shuffle the "Compressed Debug information"
choice, which depends on DEBUG_INFO, which is derived from another
choice "Debug information".

My goal is to refactor Kconfig so that randconfig will work more
simply, without using the loop.

For now, let's add a test case to ensure all dependent choices are
shuffled, as it is a somewhat tricky case for the current Kconfig.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-03-21 02:39:55 +09:00
Masahiro Yamada
c9aa7d8621 kconfig: tests: support KCONFIG_SEED for the randconfig runner
This will help get consistent results for randconfig tests.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-03-21 02:39:40 +09:00
Masahiro Yamada
b27a91383a kconfig: remove unneeded menu_is_visible() call in conf_write_defconfig()
When the condition 'sym == NULL' is met, the code will reach the
'next_menu' label regardless of the return value from menu_is_visible().

menu_is_visible() calculates some symbol values as a side-effect, for
instance by calling expr_calc_value(menu->visibility), but all the
symbol values will be calculated eventually.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-03-19 02:30:51 +09:00
Masahiro Yamada
4957515b9c kconfig: check prompt for choice while parsing
This can be checked on-the-fly.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-03-19 02:30:51 +09:00
Masahiro Yamada
c33a4315c4 kconfig: lxdialog: remove unused dialog colors
Remove inputbox_order, searchbox, searchbox_title, searchbox_border
because they are initialized, but not used anywhere.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-03-19 02:30:51 +09:00
Masahiro Yamada
137bb8b814 kconfig: lxdialog: fix button color for blackbg theme
For MENUCONFIG_COLOR=blackbg, the text in inactive buttons is invisible
because both the foreground and background are black.

Change the foreground color to white and remove the highlighting.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-03-19 02:30:51 +09:00
Masahiro Yamada
c83f020973 kconfig: remove named choice support
Commit 5a1aa8a1af ("kconfig: add named choice group") did not provide
enough explanation regarding its benefits. A use case was found in
another project [1] sometime later, this feature has never been used in
the kernel.

[1]: https://lore.kernel.org/all/201012150034.01356.yann.morin.1998@anciens.enib.fr/

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2024-03-10 13:29:48 +09:00
Masahiro Yamada
bedf923623 kconfig: use linked list in get_symbol_str() to iterate over menus
Currently, get_symbol_str() uses a tricky approach to traverse the
associated menus.

With relevant menus now linked to the symbol using a linked list,
use list_for_each_entry() for iterating on the menus.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2024-03-09 15:04:22 +09:00
Masahiro Yamada
e0492219a6 kconfig: link menus to a symbol
Currently, there is no direct link from (struct symbol) to (struct menu).

It is still possible to access associated menus through the P_SYMBOL
property, because property::menu is the relevant menu entry, but it
results in complex code, as seen in get_symbol_str().

Use a linked list for simpler traversal of relevant menus.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2024-03-09 15:01:00 +09:00
Matthew Bystrin
ba3b759fb6 kconfig: lxdialog: fix cursor render in checklist
When a checklist is opened, the cursor is rendered in a wrong position
(after the last list element on the screen). You can observe it by
opening any checklist in menuconfig.

Added wmove() to set the cursor in the proper position, just like in
menubox.c. Removed wnoutrefresh(dialog) because dialog window has
already been updated in print_buttons(). Replaced wnoutrefresh(list) and
doupdate() calls with one wrefresh(list) call.

Signed-off-by: Matthew Bystrin <dev.mbstr@gmail.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-20 23:06:38 +09:00
Masahiro Yamada
91b69454f9 kconfig: use generic macros to implement symbol hashtable
Use helper macros in hashtable.h for generic hashtable implementation.

We can git rid of the hash head index of for_all_symbols().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-20 20:47:45 +09:00
Masahiro Yamada
cc25cfc563 kconfig: print recursive dependency errors in the parsed order
for_all_symbols() iterates in the symbol hash table. The order of
iteration depends on the hash table implementation.

If you use it for printing errors, they are shown in random order.

For example, the order of following test input and the corresponding
error do not match:
 - scripts/kconfig/tests/err_recursive_dep/Kconfig
 - scripts/kconfig/tests/err_recursive_dep/expected_stderr

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-20 20:47:45 +09:00
Masahiro Yamada
7d5f52a433 kconfig: do not imply the type of choice value
Do not feed back the choice type to choice values.

Each choice value should explicitly specify 'bool' or 'tristate',
as all the Kconfig files already do. If the type were missing,
"config symbol defined without type" would be shown.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-20 20:47:45 +09:00
Masahiro Yamada
980c9e198f kconfig: convert linked list of files to hash table
Currently, a linked list is used to keep track of all the Kconfig
files that have ever been parsed. Every time the "source" statement
is encountered, the linked list is traversed to check if the file has
been opened before. This prevents the same file from being recorded
in include/config/auto.conf.cmd again.

Given 1500+ Kconfig files parsed, a hashtable is now a more optimal
data structure.

By the way, you may wonder why we check this in the first place.
It matters only when the same file is included multiple times.
In old days, such a use case was forbidden, but commit f094f8a1b2
("kconfig: allow multiple inclusion of the same file") provided a bit
more flexibility. Of course, it is almost hypothetical...

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-20 20:44:48 +09:00
Masahiro Yamada
7c4aa901bd kconfig: move strhash() to util.c as a global function
Remove the 'static' qualifier from strhash() so that it can be accessed
from other files. Move it to util.c, which is a more appropriate location.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-20 20:36:15 +09:00
Masahiro Yamada
a6dac4002b kconfig: move ARRAY_SIZE to a header
To use ARRAY_SIZE from other files, move it to its own header,
just like include/linux/array_size.h.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:41 +09:00
Masahiro Yamada
0a3128e751 kconfig: add macros useful for hashtable
This is similar to include/linux/hashtable.h, but the implementation
has been simplified.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:41 +09:00
Masahiro Yamada
5e3cf304a0 kconfig: import more list macros and inline functions
Import more macros and inline functions from include/linux/list.h
and include/linux/types.h.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:41 +09:00