lib/string.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/lib/string.c b/lib/string.c index 64a9e33f1daa..25a3c200307e 100644 --- a/lib/string.c +++ b/lib/string.c @@ -177,33 +177,18 @@ EXPORT_SYMBOL(strlcpy); */ ssize_t strscpy(char *dest, const char *src, size_t count) { - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; - size_t max = count; long res = 0; if (count == 0) return -E2BIG; -#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS - /* - * If src is unaligned, don't cross a page boundary, - * since we don't know if the next page is mapped. - */ - if ((long)src & (sizeof(long) - 1)) { - size_t limit = PAGE_SIZE - ((long)src & (PAGE_SIZE - 1)); - if (limit < max) - max = limit; - } -#else - /* If src or dest is unaligned, don't do word-at-a-time. */ - if (((long) dest | (long) src) & (sizeof(long) - 1)) - max = 0; -#endif - - while (max >= sizeof(unsigned long)) { +#if CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS && CONFIG_DCACHE_WORD_ACCESS +{ + const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; + while (count >= sizeof(unsigned long)) { unsigned long c, data; - c = *(unsigned long *)(src+res); + c = load_unaligned_zeropad(src+res); if (has_zero(c, &data, &constants)) { data = prep_zero_mask(c, data, &constants); data = create_zero_mask(data); @@ -213,8 +198,9 @@ ssize_t strscpy(char *dest, const char *src, size_t count) *(unsigned long *)(dest+res) = c; res += sizeof(unsigned long); count -= sizeof(unsigned long); - max -= sizeof(unsigned long); } +} +#endif while (count) { char c;