csum_partial_copy.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 <net/checksum.h>
  21. #include <asm/byteorder.h>
  22. #include <asm/string.h>
  23. #include <asm/uaccess.h>
  24. /*
  25. * Copy while checksumming, otherwise like csum_partial
  26. */
  27. unsigned int
  28. csum_partial_copy_nocheck (const unsigned char *src, unsigned char *dst,
  29. int len, unsigned int sum)
  30. {
  31. sum = csum_partial(src, len, sum);
  32. memcpy(dst, src, len);
  33. return sum;
  34. }
  35. EXPORT_SYMBOL(csum_partial_copy_nocheck);
  36. /*
  37. * Copy from userspace and compute checksum. If we catch an exception
  38. * then zero the rest of the buffer.
  39. */
  40. unsigned int
  41. csum_partial_copy_from_user (const unsigned char __user *src,
  42. unsigned char *dst,
  43. int len, unsigned int sum, int *err_ptr)
  44. {
  45. int missing;
  46. missing = copy_from_user(dst, src, len);
  47. if (missing) {
  48. memset(dst + len - missing, 0, missing);
  49. *err_ptr = -EFAULT;
  50. }
  51. return csum_partial(dst, len-missing, sum);
  52. }
  53. EXPORT_SYMBOL(csum_partial_copy_from_user);
  54. EXPORT_SYMBOL(csum_partial);