[dpdk-dev,v4,11/23] rte_mbuf.h: explicit cast restricting ptrdiff to uint16

Message ID 152627462287.53156.1972221889368883834.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 14, 2018, 5:10 a.m. UTC
  /projects/lagopus/src/dpdk/build/include/rte_common.h:141:34:
warning: conversion from 'long unsigned int' to 'uint16_t'
{aka 'short unsigned int'} may change value [-Wconversion]
 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) -
(uintptr_t)(ptr2))
                                  ^
/projects/lagopus/src/dpdk/build/include/rte_mbuf.h:1360:13:
note: in expansion of macro 'RTE_PTR_DIFF'
  *buf_len = RTE_PTR_DIFF(shinfo, buf_addr);

Signed-off-by: Andy Green <andy@warmcat.com>
---
 lib/librte_mbuf/rte_mbuf.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Bruce Richardson May 17, 2018, 10:50 a.m. UTC | #1
On Mon, May 14, 2018 at 01:10:22PM +0800, Andy Green wrote:
> /projects/lagopus/src/dpdk/build/include/rte_common.h:141:34:
> warning: conversion from 'long unsigned int' to 'uint16_t'
> {aka 'short unsigned int'} may change value [-Wconversion]
>  #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) -
> (uintptr_t)(ptr2))
>                                   ^
> /projects/lagopus/src/dpdk/build/include/rte_mbuf.h:1360:13:
> note: in expansion of macro 'RTE_PTR_DIFF'
>   *buf_len = RTE_PTR_DIFF(shinfo, buf_addr);
> 
> Signed-off-by: Andy Green <andy@warmcat.com>
> ---
>  lib/librte_mbuf/rte_mbuf.h |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
> index a27dbb878..0580ec8a0 100644
> --- a/lib/librte_mbuf/rte_mbuf.h
> +++ b/lib/librte_mbuf/rte_mbuf.h
> @@ -1358,7 +1358,7 @@ rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
>  	shinfo->fcb_opaque = fcb_opaque;
>  	rte_mbuf_ext_refcnt_set(shinfo, 1);
>  
> -	*buf_len = RTE_PTR_DIFF(shinfo, buf_addr);
> +	*buf_len = (uint16_t)RTE_PTR_DIFF(shinfo, buf_addr);
>  	return shinfo;
>  }
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Ananyev, Konstantin May 17, 2018, 11:03 a.m. UTC | #2
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Bruce Richardson
> Sent: Thursday, May 17, 2018 11:51 AM
> To: Andy Green <andy@warmcat.com>
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v4 11/23] rte_mbuf.h: explicit cast restricting ptrdiff to uint16
> 
> On Mon, May 14, 2018 at 01:10:22PM +0800, Andy Green wrote:
> > /projects/lagopus/src/dpdk/build/include/rte_common.h:141:34:
> > warning: conversion from 'long unsigned int' to 'uint16_t'
> > {aka 'short unsigned int'} may change value [-Wconversion]
> >  #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) -
> > (uintptr_t)(ptr2))
> >                                   ^
> > /projects/lagopus/src/dpdk/build/include/rte_mbuf.h:1360:13:
> > note: in expansion of macro 'RTE_PTR_DIFF'
> >   *buf_len = RTE_PTR_DIFF(shinfo, buf_addr);
> >
> > Signed-off-by: Andy Green <andy@warmcat.com>
> > ---
> >  lib/librte_mbuf/rte_mbuf.h |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
> > index a27dbb878..0580ec8a0 100644
> > --- a/lib/librte_mbuf/rte_mbuf.h
> > +++ b/lib/librte_mbuf/rte_mbuf.h
> > @@ -1358,7 +1358,7 @@ rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
> >  	shinfo->fcb_opaque = fcb_opaque;
> >  	rte_mbuf_ext_refcnt_set(shinfo, 1);
> >
> > -	*buf_len = RTE_PTR_DIFF(shinfo, buf_addr);
> > +	*buf_len = (uint16_t)RTE_PTR_DIFF(shinfo, buf_addr);
> >  	return shinfo;
> >  }
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>


Just as a nit: if all such conversions are unavoidable - might be introduce:
RTE_PTR_DIFF_TYPE(.., type)	((type)(RTE_PTR_DIFF(...))
Might look a bit nicer.
Konstantin
  

Patch

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index a27dbb878..0580ec8a0 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1358,7 +1358,7 @@  rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
 	shinfo->fcb_opaque = fcb_opaque;
 	rte_mbuf_ext_refcnt_set(shinfo, 1);
 
-	*buf_len = RTE_PTR_DIFF(shinfo, buf_addr);
+	*buf_len = (uint16_t)RTE_PTR_DIFF(shinfo, buf_addr);
 	return shinfo;
 }