[coreboot-gerrit] Change in coreboot[master]: arch/x86/ebda: Change memcpy() to endian wrappers

Ryan Salsamendi (Code Review) gerrit at coreboot.org
Fri Jun 16 22:20:15 CEST 2017


Ryan Salsamendi has uploaded this change for review. ( https://review.coreboot.org/20240


Change subject: arch/x86/ebda: Change memcpy() to endian wrappers
......................................................................

arch/x86/ebda: Change memcpy() to endian wrappers

Change memcpy()s and memset()s to endian.h wrappers for consistency
and safety. Add zero_n() wrapper to safely clear memory.

Change-Id: If155d82608c81992f05eae4d2223de6f506e98c5
Signed-off-by: Ryan Salsamendi <rsalsamendi at hotmail.com>
---
M src/arch/x86/ebda.c
M src/commonlib/include/commonlib/endian.h
2 files changed, 12 insertions(+), 5 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/20240/1

diff --git a/src/arch/x86/ebda.c b/src/arch/x86/ebda.c
index b5dfb41..c828aa4 100644
--- a/src/arch/x86/ebda.c
+++ b/src/arch/x86/ebda.c
@@ -19,6 +19,7 @@
 #include <arch/io.h>
 #include <arch/ebda.h>
 #include <arch/acpi.h>
+#include <commonlib/endian.h>
 
 void setup_ebda(u32 low_memory_size, u16 ebda_segment, u16 ebda_size)
 {
@@ -38,15 +39,15 @@
 	ebda = (void *)((uintptr_t)ebda_segment << 4);
 
 	/* clear BIOS DATA AREA */
-	memset(X86_BDA_BASE, 0, X86_BDA_SIZE);
+	zero_n(X86_BDA_BASE, X86_BDA_SIZE);
 
 	/* Avoid unaligned write16() since it's undefined behavior */
-	memcpy(X86_EBDA_LOWMEM, &low_memory_kb, sizeof(low_memory_kb));
-	memcpy(X86_EBDA_SEGMENT, &ebda_segment, sizeof(ebda_segment));
+	write_le16(X86_EBDA_LOWMEM, low_memory_kb);
+	write_le16(X86_EBDA_SEGMENT, ebda_segment);
 
 	/* Set up EBDA */
-	memset(ebda, 0, ebda_size);
-	memcpy(ebda, &ebda_kb, sizeof(ebda_kb));
+	zero_n(ebda, ebda_size);
+	write_le16(ebda, ebda_kb);
 }
 
 void setup_default_ebda(void)
diff --git a/src/commonlib/include/commonlib/endian.h b/src/commonlib/include/commonlib/endian.h
index 1ec472f..7b08eee 100644
--- a/src/commonlib/include/commonlib/endian.h
+++ b/src/commonlib/include/commonlib/endian.h
@@ -18,6 +18,7 @@
 
 #include <stddef.h>
 #include <stdint.h>
+#include <string.h>
 
 /* Endian agnostic functions working on single byte. */
 
@@ -254,4 +255,9 @@
 	write_le64(d, val);
 }
 
+static inline void zero_n(void *dest, size_t n)
+{
+	memset(dest, 0, n);
+}
+
 #endif

-- 
To view, visit https://review.coreboot.org/20240
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: If155d82608c81992f05eae4d2223de6f506e98c5
Gerrit-Change-Number: 20240
Gerrit-PatchSet: 1
Gerrit-Owner: Ryan Salsamendi <rsalsamendi at hotmail.com>



More information about the coreboot-gerrit mailing list