* [PATCH 1/2] include: move panic() prototype to <printk.h>
@ 2022-09-30 15:42 Ahmad Fatoum
2022-09-30 15:42 ` [PATCH 2/2] relocate_to_current_adr: hang directly on error instead of panic() Ahmad Fatoum
0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2022-09-30 15:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The panic declaration in <linux/kernel.h> is out of place and unexpected
as it's not a Linux kernel. printf() and printk() are defined in
<printk.h>, so move it there too. Most files making use of panic(), pull
it in via <common.h>, so we only need to adjust two headers for the
new location.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/cpu/mmu-common.h | 1 +
include/firmware.h | 1 +
include/linux/kernel.h | 2 --
include/printk.h | 2 ++
4 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/mmu-common.h b/arch/arm/cpu/mmu-common.h
index c9ea2c122857..7a69122ee6fa 100644
--- a/arch/arm/cpu/mmu-common.h
+++ b/arch/arm/cpu/mmu-common.h
@@ -3,6 +3,7 @@
#ifndef __ARM_MMU_COMMON_H
#define __ARM_MMU_COMMON_H
+#include <printk.h>
#include <linux/types.h>
#include <linux/ioport.h>
#include <linux/kernel.h>
diff --git a/include/firmware.h b/include/firmware.h
index 2cfaeb1e6a91..cfb88993222a 100644
--- a/include/firmware.h
+++ b/include/firmware.h
@@ -7,6 +7,7 @@
#define FIRMWARE_H
#include <pbl.h>
+#include <printk.h>
#include <types.h>
#include <driver.h>
#include <debug_ll.h>
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4483d33e65bb..44fc02df0bf9 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -82,8 +82,6 @@
(__x < 0) ? -__x : __x; \
})
-void __noreturn panic(const char *fmt, ...);
-
extern unsigned long simple_strtoul(const char *,char **,unsigned int);
extern long simple_strtol(const char *,char **,unsigned int);
extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
diff --git a/include/printk.h b/include/printk.h
index 8de8202af97c..b313b408a97b 100644
--- a/include/printk.h
+++ b/include/printk.h
@@ -27,6 +27,8 @@ static inline int printf(const char *fmt, ...)
}
#endif
+void __attribute__((noreturn)) panic(const char *fmt, ...);
+
#define printk printf
#define printk_once(fmt, ...) \
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] relocate_to_current_adr: hang directly on error instead of panic()
2022-09-30 15:42 [PATCH 1/2] include: move panic() prototype to <printk.h> Ahmad Fatoum
@ 2022-09-30 15:42 ` Ahmad Fatoum
2022-10-05 6:30 ` Sascha Hauer
0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2022-09-30 15:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] relocate_to_current_adr: hang directly on error instead of panic()
2022-09-30 15:42 ` [PATCH 2/2] relocate_to_current_adr: hang directly on error instead of panic() Ahmad Fatoum
@ 2022-10-05 6:30 ` Sascha Hauer
0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-10-05 6:30 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
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@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 |
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-05 6:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30 15:42 [PATCH 1/2] include: move panic() prototype to <printk.h> Ahmad Fatoum
2022-09-30 15:42 ` [PATCH 2/2] relocate_to_current_adr: hang directly on error instead of panic() Ahmad Fatoum
2022-10-05 6:30 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox