[PATCH 04/32] spl: Avoid #ifdef with CONFIG_SPL_SYS_MALLOC

Tom Rini trini at konsulko.com
Wed Aug 30 23:32:00 CEST 2023


On Wed, Aug 30, 2023 at 12:04:35PM -0600, Simon Glass wrote:

> Use IF_ENABLED_INT() to avoid needing to use the preprocessor.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
> 
>  common/spl/spl.c           | 12 ++++++++----
>  include/system-constants.h |  5 ++++-
>  2 files changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index 27266b393ea..78db9ef5318 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -754,10 +754,14 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
>  
>  	spl_set_bd();
>  
> -#if defined(CONFIG_SPL_SYS_MALLOC)
> -	mem_malloc_init(SPL_SYS_MALLOC_START, CONFIG_SPL_SYS_MALLOC_SIZE);
> -	gd->flags |= GD_FLG_FULL_MALLOC_INIT;
> -#endif
> +	if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC)) {
> +		ulong size;
> +
> +		size = IF_ENABLED_INT(CONFIG_SPL_SYS_MALLOC,
> +				      CONFIG_SPL_SYS_MALLOC_SIZE);
> +		mem_malloc_init(SPL_SYS_MALLOC_START, size);
> +		gd->flags |= GD_FLG_FULL_MALLOC_INIT;
> +	}
>  	if (!(gd->flags & GD_FLG_SPL_INIT)) {
>  		if (spl_init())
>  			hang();
> diff --git a/include/system-constants.h b/include/system-constants.h
> index f0a191be590..aa02c48f49d 100644
> --- a/include/system-constants.h
> +++ b/include/system-constants.h
> @@ -24,9 +24,12 @@
>   */
>  #ifdef CONFIG_SPL_HAS_CUSTOM_MALLOC_START
>  #define SPL_SYS_MALLOC_START		CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR
> -#else
> +#elif defined(CONFIG_SPL_BSS_START_ADDR)
>  #define SPL_SYS_MALLOC_START		(CONFIG_SPL_BSS_START_ADDR + \
>  					 CONFIG_SPL_BSS_MAX_SIZE)
> +#else
> +/* feature not enabled: this value avoids compiler errors but is not used */
> +#define SPL_SYS_MALLOC_START	0
>  #endif
>  
>  #endif

Does this become relevant later?  It decreases, rather than increases
readability of the code to me.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20230830/47ba0c22/attachment.sig>


More information about the U-Boot mailing list