[U-Boot] [PATCH] board_f: drop 'dead code' in ram_top computation

Dr. Philipp Tomsich philipp.tomsich at theobroma-systems.com
Fri Jul 27 09:32:12 UTC 2018


> On 27 Jul 2018, at 11:16, Philipp Tomsich <philipp.tomsich at theobroma-systems.com> wrote:
> 
> gd->ram_top is assigned to twice on consecutive lines and the compiler
> won't be able to tell that the first assignment is dead (including its
> r-value) due to the r-value containing a (side-effect free) function
> call.
> 
> This drops the first assignment.
> 
> Signed-off-by: Philipp Tomsich <philipp.tomsich at theobroma-systems.com>
> ---
> 
> common/board_f.c | 1 -
> 1 file changed, 1 deletion(-)
> 
> diff --git a/common/board_f.c b/common/board_f.c
> index 88d7700..1b8a003 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -283,7 +283,6 @@ static int setup_dest_addr(void)
> #ifdef CONFIG_SYS_SDRAM_BASE
> 	gd->ram_base = CONFIG_SYS_SDRAM_BASE;
> #endif
> -	gd->ram_top = gd->ram_base + get_effective_memsize();
> 	gd->ram_top = board_get_usable_ram_top(gd->mon_len);
> 	gd->relocaddr = gd->ram_top;
> 	debug("Ram top: %08lX\n", (ulong)gd->ram_top);
> -- 
> 2.1.4
> 

Oh my, I’ll need to revise, as board_get_usable_ram_top is implemented as follows:
> /* Get the top of usable RAM */
> __weak ulong board_get_usable_ram_top(ulong total_size)
> {
> #ifdef CONFIG_SYS_SDRAM_BASE
> 	/*                                                                      
>          * Detect whether we have so much RAM that it goes past the end of our  
>          * 32-bit address space. If so, clip the usable RAM so it doesn't.      
>          */
> 	if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
> 		/*                                                              
>                  * Will wrap back to top of 32-bit space when reservations      
>                  * are made.                                                    
>                  */
>                 return 0;
> #endif
>       	return gd->ram_top;
> }

I.e. it consumes the previous value of gd->ram_top and ignores its argument.
I’ll clean this up before someone else falls into the same pit.


More information about the U-Boot mailing list