diff options
author | Sanrio Alvares <salvares@codeaurora.org> | 2016-02-08 18:42:08 -0800 |
---|---|---|
committer | David Keitel <dkeitel@codeaurora.org> | 2016-03-23 21:21:28 -0700 |
commit | ae3950d6238c828de10ed8c66e4b9dd9e27ecad0 (patch) | |
tree | dcf01b7b588c76a07a3a7c51d4d3c0ac2601a9ae /lib | |
parent | 566b301bfe49fbee1c6b56a1bbe4316fd33a6eed (diff) |
lib: align source before using optimized implementation
If the source is at the boundary of the VMA, loading one word at a
time can cause an alignment fault when the adjacent VMA is IO mapped.
Do byte-by-byte copy until source aligns to 8 bytes and then continue
with optimized version.
CRs-Fixed: 973724
Change-Id: I05e085597c58169fc6e275508a907029b9c7ec64
Signed-off-by: Sanrio Alvares <salvares@codeaurora.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/strncpy_from_user.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c index e0af6ff73d14..9d2683b521ae 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -14,6 +14,8 @@ (((long) dst | (long) src) & (sizeof(long) - 1)) #endif +#define CHECK_ALIGN(v, a) ((((unsigned long)(v)) & ((a) - 1)) == 0) + /* * Do a strncpy, return length of string without final '\0'. * 'count' is the user-supplied count (return 'count' if we @@ -35,6 +37,21 @@ static inline long do_strncpy_from_user(char *dst, const char __user *src, long if (IS_UNALIGNED(src, dst)) goto byte_at_a_time; + /* Copy a byte at a time until we align to 8 bytes */ + while (max && (!CHECK_ALIGN(src + res, 8))) { + char c; + int ret; + + ret = __get_user(c, src + res); + if (ret) + return -ret; + dst[res] = c; + if (!c) + return res; + res++; + max--; + } + while (max >= sizeof(unsigned long)) { unsigned long c, data; |