// SPDX-License-Identifier: GPL-2.0

/* Upstream Linux v6.0: lib/usercopy.c:10-21
 * Exact source lines; kernel context, not a standalone program or book restoration.
 */
unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n)
{
	unsigned long res = n;
	might_fault();
	if (!should_fail_usercopy() && likely(access_ok(from, n))) {
		instrument_copy_from_user(to, from, n);
		res = raw_copy_from_user(to, from, n);
	}
	if (unlikely(res))
		memset(to + (n - res), 0, res);
	return res;
}
