From: Tom Rini <trini@konsulko.com>
To: Simon Glass <sjg@chromium.org>
Cc: U-Boot Mailing List <u-boot@lists.denx.de>,
Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
Masahiro Yamada <yamada.masahiro@socionext.com>
Subject: Re: [PATCH v5 05/13] kconfig: Add support for conditional values
Date: Wed, 9 Feb 2022 11:37:53 -0500 [thread overview]
Message-ID: <20220209163753.GG7515@bill-the-cat> (raw)
In-Reply-To: <20220122050728.v5.5.I623f0db3bbfe77d70eafaa8b80da052623aa364c@changeid>
[-- Attachment #1: Type: text/plain, Size: 1697 bytes --]
On Sat, Jan 22, 2022 at 05:07:26AM -0700, Simon Glass wrote:
> At present if an optional Kconfig value needs to be used it must be
> bracketed by #ifdef. For example, with this Kconfig setup:
>
> config WIBBLE
> bool "Support wibbles, the world needs more wibbles"
>
> config WIBBLE_ADDR
> hex "Address of the wibble"
> depends on WIBBLE
>
> then the following code must be used:
>
> #ifdef CONFIG_WIBBLE
> static void handle_wibble(void)
> {
> int val = CONFIG_WIBBLE_ADDR;
>
> ...
> }
> #endif
>
> static void init_machine()
> {
> ...
> #ifdef CONFIG_WIBBLE
> handle_wibble();
> #endif
> }
>
> Add a new IF_ENABLED_INT() to help with this. So now it is possible to
> write, without #ifdefs:
>
> static void handle_wibble(void)
> {
> int val = IF_ENABLED_INT(CONFIG_WIBBLE, CONFIG_WIBBLE_ADDR);
>
> ...
> }
>
> static void init_machine()
> {
> ...
> if (IS_ENABLED(CONFIG_WIBBLE))
> handle_wibble();
> }
>
> The value will be CONFIG_WIBBLE_ADDR if CONFIG_WIBBLE is defined and will
> produce a build error if not.. This allows us to reduce the use of #ifdef
> in the code, ensuring that the compiler still checks the code even if it
> is not ultimately used for a particular build.
>
> Add a CONFIG_IF_ENABLED_INT() version as well.
>
> If an attempt is made to use a value that does not exist (i.e. when the
> conditional is not enabled), an error about a non-existing function is
> generated, e.g.:
>
> common/bloblist.c:447: undefined reference to `invalid_use_of_IF_ENABLED_INT'
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
Applied to u-boot/master, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
next prev parent reply other threads:[~2022-02-09 16:38 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-22 12:07 [PATCH v5 00/13] kconfig: Add some new macros Simon Glass
2022-01-22 12:07 ` [PATCH v5 01/13] imx: Don't define __ASSEMBLY__ in source files Simon Glass
2022-02-09 16:37 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 02/13] mips: Avoid using config_enabled() directly Simon Glass
2022-02-09 16:37 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 03/13] mmc: fsl: Use brackets around if() Simon Glass
2022-01-26 23:17 ` Jaehoon Chung
2022-02-09 16:37 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 04/13] kconfig: Update IS_ENABLED() internals Simon Glass
2022-02-09 16:37 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 05/13] kconfig: Add support for conditional values Simon Glass
2022-02-09 16:37 ` Tom Rini [this message]
2022-01-22 12:07 ` [PATCH v5 06/13] bloblist: Update to use conditional value Simon Glass
2022-02-09 16:37 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 07/13] patman: Update test_util to run doc tests Simon Glass
2022-02-09 16:38 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 08/13] buildman: Add a flag to control the traceback Simon Glass
2022-02-09 16:38 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 09/13] buildman: Make use of test_util Simon Glass
2022-02-09 16:38 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 10/13] buildman: Add helper functions for updating .config files Simon Glass
2022-02-09 16:38 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 11/13] buildman: Provide a hint on how to debug thread crashes Simon Glass
2022-02-09 16:38 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 12/13] buildman: Allow adjusting board config on the fly Simon Glass
2022-02-09 16:38 ` Tom Rini
2022-01-22 12:07 ` [PATCH v5 13/13] test: Add some tests for kconfig.h Simon Glass
2022-02-09 14:57 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220209163753.GG7515@bill-the-cat \
--to=trini@konsulko.com \
--cc=rasmus.villemoes@prevas.dk \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
--cc=yamada.masahiro@socionext.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox