[U-Boot] [PATCH] Do not copy to same address

Matthias Weisser weisserm at arcor.de
Tue Apr 12 08:58:40 CEST 2011


In some cases (e.g. bootm with a elf payload) there is a in place copy of
data to the same address. Catching this saves some ms while booting.

Signed-off-by: Matthias Weisser <weisserm at arcor.de>
---
 lib/string.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/lib/string.c b/lib/string.c
index b375b81..b8a9203 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -445,6 +445,9 @@ char * bcopy(const char * src, char * dest, int count)
 {
 	char *tmp = dest;
 
+	if (src == dest)
+		return dest;
+
 	while (count--)
 		*tmp++ = *src++;
 
@@ -467,6 +470,9 @@ void * memcpy(void *dest, const void *src, size_t count)
 	unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
 	char *d8, *s8;
 
+	if (src == dest)
+		return dest;
+
 	/* while all data is aligned (common case), copy a word at a time */
 	if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) {
 		while (count >= sizeof(*dl)) {
@@ -497,6 +503,9 @@ void * memmove(void * dest,const void *src,size_t count)
 {
 	char *tmp, *s;
 
+	if (src == dest)
+		return dest;
+
 	if (dest <= src) {
 		tmp = (char *) dest;
 		s = (char *) src;
-- 
1.7.0.4



More information about the U-Boot mailing list