mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] relocate_to_current_adr: hang directly on error instead of panic()
Date: Fri, 30 Sep 2022 17:42:47 +0200	[thread overview]
Message-ID: <20220930154247.756577-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220930154247.756577-1-a.fatoum@pengutronix.de>

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@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(-)

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




  reply	other threads:[~2022-09-30 15:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 15:42 [PATCH 1/2] include: move panic() prototype to <printk.h> Ahmad Fatoum
2022-09-30 15:42 ` Ahmad Fatoum [this message]
2022-10-05  6:30   ` [PATCH 2/2] relocate_to_current_adr: hang directly on error instead of panic() Sascha Hauer

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=20220930154247.756577-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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