uaccess.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_UACCESS_H
  3. #define _ASM_UACCESS_H
  4. #include <linux/string.h>
  5. static inline __must_check unsigned long
  6. raw_copy_from_user(void *to, const void __user * from, unsigned long n)
  7. {
  8. if (__builtin_constant_p(n)) {
  9. switch(n) {
  10. case 1:
  11. *(u8 *)to = *(u8 __force *)from;
  12. return 0;
  13. case 2:
  14. *(u16 *)to = *(u16 __force *)from;
  15. return 0;
  16. case 4:
  17. *(u32 *)to = *(u32 __force *)from;
  18. return 0;
  19. }
  20. }
  21. memcpy(to, (const void __force *)from, n);
  22. return 0;
  23. }
  24. static inline __must_check unsigned long
  25. raw_copy_to_user(void __user *to, const void *from, unsigned long n)
  26. {
  27. if (__builtin_constant_p(n)) {
  28. switch(n) {
  29. case 1:
  30. *(u8 __force *)to = *(u8 *)from;
  31. return 0;
  32. case 2:
  33. *(u16 __force *)to = *(u16 *)from;
  34. return 0;
  35. case 4:
  36. *(u32 __force *)to = *(u32 *)from;
  37. return 0;
  38. default:
  39. break;
  40. }
  41. }
  42. memcpy((void __force *)to, from, n);
  43. return 0;
  44. }
  45. #define INLINE_COPY_FROM_USER
  46. #define INLINE_COPY_TO_USER
  47. #include <asm-generic/uaccess.h>
  48. #endif