]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - lib/usercopy.c
treewide: add checks for the return value of memblock_alloc*()
[thirdparty/kernel/stable.git] / lib / usercopy.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
d597580d
AV
2#include <linux/uaccess.h>
3
4/* out-of-line parts */
5
6#ifndef INLINE_COPY_FROM_USER
7unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n)
8{
9 unsigned long res = n;
9c5f6908 10 might_fault();
96d4f267 11 if (likely(access_ok(from, n))) {
9c5f6908 12 kasan_check_write(to, n);
d597580d 13 res = raw_copy_from_user(to, from, n);
9c5f6908 14 }
d597580d
AV
15 if (unlikely(res))
16 memset(to + (n - res), 0, res);
17 return res;
18}
19EXPORT_SYMBOL(_copy_from_user);
20#endif
21
22#ifndef INLINE_COPY_TO_USER
a0e94598 23unsigned long _copy_to_user(void __user *to, const void *from, unsigned long n)
d597580d 24{
9c5f6908 25 might_fault();
96d4f267 26 if (likely(access_ok(to, n))) {
9c5f6908 27 kasan_check_read(from, n);
d597580d 28 n = raw_copy_to_user(to, from, n);
9c5f6908 29 }
d597580d
AV
30 return n;
31}
32EXPORT_SYMBOL(_copy_to_user);
33#endif