[dpdk-dev,v6,3/8] rte_ip.h: cast type decided by sizeof to uint32

Message ID 152686806834.58694.15827888464125197583.stgit@localhost.localdomain (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andy Green May 21, 2018, 2:01 a.m. UTC
  /projects/lagopus/src/dpdk/build/include/rte_ip.h:
In function 'rte_ipv4_udptcp_cksum':
/projects/lagopus/src/dpdk/build/include/rte_byteorder.h:
51:24: warning: conversion from 'long unsigned int' to
'uint32_t' {aka 'unsigned int'} may change value
[-Wconversion]
 #define rte_bswap16(x) ((uint16_t)
(__builtin_constant_p(x) ?  \
                        ^
/projects/lagopus/src/dpdk/build/include/rte_byteorder.h:
85:29: note: in expansion of macro 'rte_bswap16'
 #define rte_be_to_cpu_16(x) rte_bswap16(x)
                             ^~~~~~~~~~~
/projects/lagopus/src/dpdk/build/include/rte_ip.h:321:11:
note: in expansion of macro 'rte_be_to_cpu_16'
  l4_len = rte_be_to_cpu_16(ipv4_hdr->total_length) -
           ^~~~~~~~~~~~~~~~

Also with this one, it is a cast that always occurred
and is just being done explicitly, with no changes to
the generated code.

The warning stack is misleading, it points to the last
element in the macro that produced the lhs of the subtraction
above.  But the only "unsigned long int" in the expression is
the result of the sizeof() on the rhs, it promotes the
subtraction result to unsigned long.  So the error actually
relates to the result of the outer subtraction.

The actual error is "you are trying to put an unsigned long
into a uint32_t".  We always did so, the fix is just to inform
the compiler it is intentional with an explicit cast.

Fixes: 6006818cfb ("net: new checksum functions")
Signed-off-by: Andy Green <andy@warmcat.com>
---
 lib/librte_net/rte_ip.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Bruce Richardson May 21, 2018, 12:13 p.m. UTC | #1
On Mon, May 21, 2018 at 10:01:08AM +0800, Andy Green wrote:
> /projects/lagopus/src/dpdk/build/include/rte_ip.h:
> In function 'rte_ipv4_udptcp_cksum':
> /projects/lagopus/src/dpdk/build/include/rte_byteorder.h:
> 51:24: warning: conversion from 'long unsigned int' to
> 'uint32_t' {aka 'unsigned int'} may change value
> [-Wconversion]
>  #define rte_bswap16(x) ((uint16_t)
> (__builtin_constant_p(x) ?  \
>                         ^
> /projects/lagopus/src/dpdk/build/include/rte_byteorder.h:
> 85:29: note: in expansion of macro 'rte_bswap16'
>  #define rte_be_to_cpu_16(x) rte_bswap16(x)
>                              ^~~~~~~~~~~
> /projects/lagopus/src/dpdk/build/include/rte_ip.h:321:11:
> note: in expansion of macro 'rte_be_to_cpu_16'
>   l4_len = rte_be_to_cpu_16(ipv4_hdr->total_length) -
>            ^~~~~~~~~~~~~~~~
> 
> Also with this one, it is a cast that always occurred
> and is just being done explicitly, with no changes to
> the generated code.
> 
> The warning stack is misleading, it points to the last
> element in the macro that produced the lhs of the subtraction
> above.  But the only "unsigned long int" in the expression is
> the result of the sizeof() on the rhs, it promotes the
> subtraction result to unsigned long.  So the error actually
> relates to the result of the outer subtraction.
> 
> The actual error is "you are trying to put an unsigned long
> into a uint32_t".  We always did so, the fix is just to inform
> the compiler it is intentional with an explicit cast.
> 
> Fixes: 6006818cfb ("net: new checksum functions")
> Signed-off-by: Andy Green <andy@warmcat.com>
> ---
>  lib/librte_net/rte_ip.h |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  

Patch

diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index c924aca7f..72dc2456a 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -318,8 +318,8 @@  rte_ipv4_udptcp_cksum(const struct ipv4_hdr *ipv4_hdr, const void *l4_hdr)
 	uint32_t cksum;
 	uint32_t l4_len;
 
-	l4_len = rte_be_to_cpu_16(ipv4_hdr->total_length) -
-		sizeof(struct ipv4_hdr);
+	l4_len = (uint32_t)(rte_be_to_cpu_16(ipv4_hdr->total_length) -
+		sizeof(struct ipv4_hdr));
 
 	cksum = rte_raw_cksum(l4_hdr, l4_len);
 	cksum += rte_ipv4_phdr_cksum(ipv4_hdr, 0);