uaccess.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  4. */
  5. /*
  6. * Support for user memory access from kernel. This will
  7. * probably be inlined for performance at some point, but
  8. * for ease of debug, and to a lesser degree for code size,
  9. * we implement here as subroutines.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/uaccess.h>
  13. #include <linux/pgtable.h>
  14. /*
  15. * For clear_user(), exploit previously defined copy_to_user function
  16. * and the fact that we've got a handy zero page defined in kernel/head.S
  17. *
  18. * dczero here would be even faster.
  19. */
  20. __kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count)
  21. {
  22. long uncleared;
  23. while (count > PAGE_SIZE) {
  24. uncleared = raw_copy_to_user(dest, &empty_zero_page, PAGE_SIZE);
  25. if (uncleared)
  26. return count - (PAGE_SIZE - uncleared);
  27. count -= PAGE_SIZE;
  28. dest += PAGE_SIZE;
  29. }
  30. if (count)
  31. count = raw_copy_to_user(dest, &empty_zero_page, count);
  32. return count;
  33. }
  34. unsigned long clear_user_hexagon(void __user *dest, unsigned long count)
  35. {
  36. if (!access_ok(dest, count))
  37. return count;
  38. else
  39. return __clear_user_hexagon(dest, count);
  40. }