diff mbox series

Don't use variable length arrays in exception code

Message ID 20190228032620.16610-1-stewart@linux.ibm.com
State Accepted
Headers show
Series Don't use variable length arrays in exception code | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present

Commit Message

Stewart Smith Feb. 28, 2019, 3:26 a.m. UTC
OMG Kees Cook was right, the code is *smaller*. We save like a dozen
instructions in the exception path!

Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
---
 core/exceptions.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

Comments

Stewart Smith March 4, 2019, 3:03 a.m. UTC | #1
Stewart Smith <stewart@linux.ibm.com> writes:
> OMG Kees Cook was right, the code is *smaller*. We save like a dozen
> instructions in the exception path!
>
> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
> ---
>  core/exceptions.c | 27 +++++++++++++--------------
>  1 file changed, 13 insertions(+), 14 deletions(-)

Merged to master as of 0eea56b06b4ff23163d5dc400f800cb827c1948f
diff mbox series

Patch

diff --git a/core/exceptions.c b/core/exceptions.c
index e15848ad34af..4e5c0819e14e 100644
--- a/core/exceptions.c
+++ b/core/exceptions.c
@@ -39,14 +39,15 @@  static void dump_regs(struct stack_frame *stack)
 		       i, stack->gpr[i], i + 16, stack->gpr[i + 16]);
 }
 
+#define EXCEPTION_MAX_STR 320
+
 void exception_entry(struct stack_frame *stack)
 {
 	bool fatal = false;
 	bool hv;
 	uint64_t nip;
 	uint64_t msr;
-	const size_t max = 320;
-	char buf[max];
+	char buf[EXCEPTION_MAX_STR];
 	size_t l;
 
 	switch (stack->type) {
@@ -81,23 +82,23 @@  void exception_entry(struct stack_frame *stack)
 	l = 0;
 	if (stack->type == 0x100) {
 		if (fatal) {
-			l += snprintf(buf + l, max - l,
+			l += snprintf(buf + l, EXCEPTION_MAX_STR - l,
 				"Fatal System Reset at "REG"   ", nip);
 		} else {
-			l += snprintf(buf + l, max - l,
+			l += snprintf(buf + l, EXCEPTION_MAX_STR - l,
 				"System Reset at "REG"   ", nip);
 		}
 	} else if (stack->type == 0x200) {
 		fatal = true;
-		l += snprintf(buf + l, max - l,
+		l += snprintf(buf + l, EXCEPTION_MAX_STR - l,
 			"Fatal MCE at "REG"   ", nip);
 	} else {
 		fatal = true;
-		l += snprintf(buf + l, max - l,
+		l += snprintf(buf + l, EXCEPTION_MAX_STR - l,
 			"Fatal Exception 0x%llx at "REG"  ", stack->type, nip);
 	}
-	l += snprintf_symbol(buf + l, max - l, nip);
-	l += snprintf(buf + l, max - l, "  MSR "REG, msr);
+	l += snprintf_symbol(buf + l, EXCEPTION_MAX_STR - l, nip);
+	l += snprintf(buf + l, EXCEPTION_MAX_STR - l, "  MSR "REG, msr);
 	prerror("%s\n", buf);
 	dump_regs(stack);
 
@@ -115,13 +116,12 @@  void exception_entry(struct stack_frame *stack)
 
 void exception_entry_pm_sreset(void)
 {
-	const size_t max = 320;
-	char buf[max];
+	char buf[EXCEPTION_MAX_STR];
 	size_t l;
 
 	prerror("***********************************************\n");
 	l = 0;
-	l += snprintf(buf + l, max - l,
+	l += snprintf(buf + l, EXCEPTION_MAX_STR - l,
 		"System Reset in sleep");
 	prerror("%s\n", buf);
 	backtrace();
@@ -129,13 +129,12 @@  void exception_entry_pm_sreset(void)
 
 void __noreturn exception_entry_pm_mce(void)
 {
-	const size_t max = 320;
-	char buf[max];
+	char buf[EXCEPTION_MAX_STR];
 	size_t l;
 
 	prerror("***********************************************\n");
 	l = 0;
-	l += snprintf(buf + l, max - l,
+	l += snprintf(buf + l, EXCEPTION_MAX_STR - l,
 		"Fatal MCE in sleep");
 	prerror("%s\n", buf);
 	prerror("SRR0 : "REG" SRR1 : "REG"\n",