--- a/lib/string.c
+++ b/lib/string.c
@@ -23,6 +23,7 @@
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/module.h>
+#include <linux/memcopy.h>
#ifndef __HAVE_ARCH_STRNICMP
/**
@@ -596,11 +597,11 @@ EXPORT_SYMBOL(memset);
*/
void *memcpy(void *dest, const void *src, size_t count)
{
- char *tmp = dest;
- const char *s = src;
+ unsigned long dstp = (unsigned long)dest;
+ unsigned long srcp = (unsigned long)src;
- while (count--)
- *tmp++ = *s++;
+ /* Copy from the beginning to the end */
+ mem_copy_fwd(dstp, srcp, count);
return dest;
}
EXPORT_SYMBOL(memcpy);
@@ -617,21 +618,15 @@ EXPORT_SYMBOL(memcpy);
*/
void *memmove(void *dest, const void *src, size_t count)
{
- char *tmp;
- const char *s;
+ unsigned long dstp = (unsigned long)dest;
+ unsigned long srcp = (unsigned long)src;
- if (dest <= src) {
- tmp = dest;
- s = src;
- while (count--)
- *tmp++ = *s++;
+ if (dest - src >= count) {
+ /* Copy from the beginning to the end */
+ mem_copy_fwd(dstp, srcp, count);
} else {
- tmp = dest;
- tmp += count;
- s = src;
- s += count;
- while (count--)
- *--tmp = *--s;
+ /* Copy from the end to the beginning */
+ mem_copy_bwd(dstp, srcp, count);
}
return dest;
}