diff mbox series

[v5,1/3] helper: chksum: calculate checksum in network byte order

Message ID 1503576008-15890-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v5,1/3] helper: chksum: calculate checksum in network byte order | expand

Commit Message

Github ODP bot Aug. 24, 2017, noon UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


All examples and usecases assumed network byte order for odph_chksum()
return value. Instead of changing this convention, rather document that
odph_chksum returns value in network byte order.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 132 (lumag:fix-checksum)
 ** https://github.com/Linaro/odp/pull/132
 ** Patch: https://github.com/Linaro/odp/pull/132.patch
 ** Base sha: 8705e548f330d23173283fcca62f4afb835a6380
 ** Merge commit sha: e256e0810a3feee8b1b91b8d61f21bdfdd339dff
 **/
 helper/include/odp/helper/chksum.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/helper/include/odp/helper/chksum.h b/helper/include/odp/helper/chksum.h
index 520e9275..2da0303e 100644
--- a/helper/include/odp/helper/chksum.h
+++ b/helper/include/odp/helper/chksum.h
@@ -40,16 +40,16 @@  typedef enum {
  * @param buffer calculate chksum for buffer
  * @param len    buffer length
  *
- * @return checksum value in host cpu order
+ * @return checksum value in network order
  */
 static inline odp_u16sum_t odph_chksum(void *buffer, int len)
 {
-	uint16_t *buf = (uint16_t *)buffer;
+	odp_u16be_t *buf = (odp_u16be_t *)buffer;
 	uint32_t sum = 0;
 	uint16_t result;
 
 	for (sum = 0; len > 1; len -= 2)
-		sum += *buf++;
+		sum += odp_be_to_cpu_16(*buf++);
 
 	if (len == 1)
 		sum += *(unsigned char *)buf;
@@ -58,7 +58,7 @@  static inline odp_u16sum_t odph_chksum(void *buffer, int len)
 	sum += (sum >> 16);
 	result = ~sum;
 
-	return  (__odp_force odp_u16sum_t) result;
+	return odp_cpu_to_be_16(result);
 }
 
 /**