[dpdk-dev,v4,12/23] rte_mbuf.h: explicit cast for size type to uint32

Message ID 152627462791.53156.5271968691770807055.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
  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:53 a.m. UTC | #1
On Mon, May 14, 2018 at 01:10:27PM +0800, Andy Green wrote:
> 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 0580ec8a0..169f3d3b0 100644
> --- a/lib/librte_mbuf/rte_mbuf.h
> +++ b/lib/librte_mbuf/rte_mbuf.h
> @@ -1577,7 +1577,7 @@ static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
>  		__rte_pktmbuf_free_direct(m);
>  
>  	priv_size = rte_pktmbuf_priv_size(mp);
> -	mbuf_size = sizeof(struct rte_mbuf) + priv_size;
> +	mbuf_size = (uint32_t)sizeof(struct rte_mbuf) + priv_size;
>  	buf_len = rte_pktmbuf_data_room_size(mp);
>  
>  	m->priv_size = priv_size;
> 
It would be good to include the error message in the commit log.
Also, for safety, is it better to have extra braces to cast the whole
expression, not just the sizeof, i.e.

	mbuf_size = (uint32_t)(sizeof(...) + priv_size);

/Bruce
  
Andy Green May 17, 2018, 1:09 p.m. UTC | #2
On 05/17/2018 06:53 PM, Bruce Richardson wrote:
> On Mon, May 14, 2018 at 01:10:27PM +0800, Andy Green wrote:
>> 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 0580ec8a0..169f3d3b0 100644
>> --- a/lib/librte_mbuf/rte_mbuf.h
>> +++ b/lib/librte_mbuf/rte_mbuf.h
>> @@ -1577,7 +1577,7 @@ static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
>>   		__rte_pktmbuf_free_direct(m);
>>   
>>   	priv_size = rte_pktmbuf_priv_size(mp);
>> -	mbuf_size = sizeof(struct rte_mbuf) + priv_size;
>> +	mbuf_size = (uint32_t)sizeof(struct rte_mbuf) + priv_size;
>>   	buf_len = rte_pktmbuf_data_room_size(mp);
>>   
>>   	m->priv_size = priv_size;
>>
> It would be good to include the error message in the commit log.
> Also, for safety, is it better to have extra braces to cast the whole
> expression, not just the sizeof, i.e.
> 
> 	mbuf_size = (uint32_t)(sizeof(...) + priv_size);

OK I went back and captured the original error and added it back in, and 
adapted the scope of the cast as you suggested.

-Andy

> /Bruce
>
  

Patch

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index 0580ec8a0..169f3d3b0 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1577,7 +1577,7 @@  static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
 		__rte_pktmbuf_free_direct(m);
 
 	priv_size = rte_pktmbuf_priv_size(mp);
-	mbuf_size = sizeof(struct rte_mbuf) + priv_size;
+	mbuf_size = (uint32_t)sizeof(struct rte_mbuf) + priv_size;
 	buf_len = rte_pktmbuf_data_room_size(mp);
 
 	m->priv_size = priv_size;