[PATCH 2/2] relocate_to_current_adr: hang directly on error instead of panic()

Sascha Hauer sha at pengutronix.de
Tue Oct 4 23:30:49 PDT 2022


On Fri, Sep 30, 2022 at 05:42:47PM +0200, Ahmad Fatoum wrote:
> panic() will format a panic message, turn on a panic LED, dump a
> stack trace and finally either restart the system or print a
> message to ask the user to restart the system before hanging.
> 
> When relocation fails, all of these aren't possible, so instead of
> devolving into undefined behavior, fall directly into an infinite loop.
> 
> Motivation for this change is to avoid linking printf code when it's
> only usage is the relocation error case.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  arch/arm/cpu/common.c  | 4 ++--
>  arch/riscv/lib/reloc.c | 2 +-
>  include/common.h       | 6 ++++++
>  3 files changed, 9 insertions(+), 3 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/cpu/common.c b/arch/arm/cpu/common.c
> index 5ccacf204751..7cd97e938b3d 100644
> --- a/arch/arm/cpu/common.c
> +++ b/arch/arm/cpu/common.c
> @@ -90,7 +90,7 @@ void relocate_to_current_adr(void)
>  			putc_ll(' ');
>  			puthex_ll(rel->r_addend);
>  			putc_ll('\n');
> -			panic("");
> +			__hang();
>  		}
>  
>  		dstart += sizeof(*rel);
> @@ -120,7 +120,7 @@ void relocate_to_current_adr(void)
>  			putc_ll(' ');
>  			puthex_ll(rel->r_offset);
>  			putc_ll('\n');
> -			panic("");
> +			__hang();
>  		}
>  
>  		dstart += sizeof(*rel);
> diff --git a/arch/riscv/lib/reloc.c b/arch/riscv/lib/reloc.c
> index da53c50448d7..13118a9ac54f 100644
> --- a/arch/riscv/lib/reloc.c
> +++ b/arch/riscv/lib/reloc.c
> @@ -66,7 +66,7 @@ void relocate_to_current_adr(void)
>  			putc_ll(' ');
>  			puthex_ll(rela->r_addend);
>  			putc_ll('\n');
> -			panic("");
> +			__hang();
>  		}
>  	}
>  
> diff --git a/include/common.h b/include/common.h
> index bd120356883a..cf3e0447a09a 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -43,6 +43,12 @@
>   */
>  void reginfo(void);
>  
> +/* For use when unrelocated */
> +static inline void __hang(void)
> +{
> +	while (1);
> +}
> +
>  void __noreturn hang (void);
>  
>  char *size_human_readable(unsigned long long size);
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list