Commit 28f6905d authored by Jan Kiszka's avatar Jan Kiszka

cobalt: Improve cobalt_copy_from/to_user

This aligns the definition of our user copy services with the kernel in
two aspects:
 - use unlikely to mark the fast path
 - memset the remaining bits of the target region if the copy fails;
   this avoids false-positive compiler warnings and reduces the risk to
   evaluate undefined data in case the return value is not checked
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent 4f0f067a
......@@ -46,15 +46,25 @@
static inline int cobalt_copy_from_user(void *dst, const void __user *src,
size_t size)
{
return (!access_rok(src, size) ||
__xn_copy_from_user(dst, src, size)) ? -EFAULT : 0;
size_t remaining = size;
if (likely(access_rok(src, size)))
remaining = __xn_copy_from_user(dst, src, size);
if (unlikely(remaining > 0)) {
memset(dst + (size - remaining), 0, remaining);
return -EFAULT;
}
return 0;
}
static inline int cobalt_copy_to_user(void __user *dst, const void *src,
size_t size)
{
return (!access_wok(dst, size) ||
__xn_copy_to_user(dst, src, size)) ? -EFAULT : 0;
if (unlikely(!access_wok(dst, size) ||
__xn_copy_to_user(dst, src, size)))
return -EFAULT;
return 0;
}
static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment