csum_partial_copy.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * M32R specific IP/TCP/UDP checksumming routines
  7. * (Some code taken from MIPS architecture)
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. *
  13. * Copyright (C) 1994, 1995 Waldorf Electronics GmbH
  14. * Copyright (C) 1998, 1999 Ralf Baechle
  15. * Copyright (C) 2001-2005 Hiroyuki Kondo, Hirokazu Takata
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/string.h>
  21. #include <net/checksum.h>
  22. #include <asm/byteorder.h>
  23. #include <asm/uaccess.h>
  24. /*
  25. * Copy while checksumming, otherwise like csum_partial
  26. */
  27. __wsum
  28. csum_partial_copy_nocheck (const void *src, void *dst, int len, __wsum sum)
  29. {
  30. sum = csum_partial(src, len, sum);
  31. memcpy(dst, src, len);
  32. return sum;
  33. }
  34. EXPORT_SYMBOL(csum_partial_copy_nocheck);
  35. /*
  36. * Copy from userspace and compute checksum. If we catch an exception
  37. * then zero the rest of the buffer.
  38. */
  39. __wsum
  40. csum_partial_copy_from_user (const void __user *src, void *dst,
  41. int len, __wsum sum, int *err_ptr)
  42. {
  43. int missing;
  44. missing = copy_from_user(dst, src, len);
  45. if (missing) {
  46. memset(dst + len - missing, 0, missing);
  47. *err_ptr = -EFAULT;
  48. }
  49. return csum_partial(dst, len-missing, sum);
  50. }
  51. EXPORT_SYMBOL(csum_partial_copy_from_user);
  52. EXPORT_SYMBOL(csum_partial);