[dpdk-dev,v3,36/40] rte_ethdev.h: explicit cast for return type

Message ID 152592056030.119328.10575471783991783458.stgit@localhost.localdomain (mailing list archive)
State Superseded, archived
Headers

Checks

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

Commit Message

Andy Green May 10, 2018, 2:49 a.m. UTC
  /projects/lagopus/src/dpdk/build/include/rte_ethdev.h:3860:10:
warning: conversion to 'int' from 'uint32_t' {aka 'unsigned int'}
may change the sign of the result [-Wsign-conversion]
  return (*dev->dev_ops->rx_queue_count)(dev, queue_id);

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

Comments

Stephen Hemminger May 10, 2018, 7:18 p.m. UTC | #1
On Thu, 10 May 2018 10:49:20 +0800
Andy Green <andy@warmcat.com> wrote:

> /projects/lagopus/src/dpdk/build/include/rte_ethdev.h:3860:10:
> warning: conversion to 'int' from 'uint32_t' {aka 'unsigned int'}
> may change the sign of the result [-Wsign-conversion]
>   return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
> 
> Signed-off-by: Andy Green <andy@warmcat.com>
> ---
>  lib/librte_ethdev/rte_ethdev.h |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
> index 2487e1d2d..c84dc44b8 100644
> --- a/lib/librte_ethdev/rte_ethdev.h
> +++ b/lib/librte_ethdev/rte_ethdev.h
> @@ -3857,7 +3857,7 @@ rte_eth_rx_queue_count(uint16_t port_id, uint16_t queue_id)
>  	if (queue_id >= dev->data->nb_rx_queues)
>  		return -EINVAL;
>  
> -	return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
> +	return (int)(*dev->dev_ops->rx_queue_count)(dev, queue_id);
>  }
>  
>  /**
> 

Why not change rx_queue_count to int to allow drivers to return an error?
  
Andy Green May 10, 2018, 11:48 p.m. UTC | #2
On 05/11/2018 03:18 AM, Stephen Hemminger wrote:
> On Thu, 10 May 2018 10:49:20 +0800
> Andy Green <andy@warmcat.com> wrote:
> 
>> /projects/lagopus/src/dpdk/build/include/rte_ethdev.h:3860:10:
>> warning: conversion to 'int' from 'uint32_t' {aka 'unsigned int'}
>> may change the sign of the result [-Wsign-conversion]
>>    return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
>>
>> Signed-off-by: Andy Green <andy@warmcat.com>
>> ---
>>   lib/librte_ethdev/rte_ethdev.h |    2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
>> index 2487e1d2d..c84dc44b8 100644
>> --- a/lib/librte_ethdev/rte_ethdev.h
>> +++ b/lib/librte_ethdev/rte_ethdev.h
>> @@ -3857,7 +3857,7 @@ rte_eth_rx_queue_count(uint16_t port_id, uint16_t queue_id)
>>   	if (queue_id >= dev->data->nb_rx_queues)
>>   		return -EINVAL;
>>   
>> -	return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
>> +	return (int)(*dev->dev_ops->rx_queue_count)(dev, queue_id);
>>   }
>>   
>>   /**
>>
> 
> Why not change rx_queue_count to int to allow drivers to return an error?

OK.  I have done it and will push it later.  I left the few related apis 
in ./lib/ like rte_vhost_rx_queue_count() alone, they still return a 
uint32_t.

Naturally, I want to call that patch something like "eth_dev_ops: change 
rx_queue_count to return an int"...

-Andy
  

Patch

diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 2487e1d2d..c84dc44b8 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -3857,7 +3857,7 @@  rte_eth_rx_queue_count(uint16_t port_id, uint16_t queue_id)
 	if (queue_id >= dev->data->nb_rx_queues)
 		return -EINVAL;
 
-	return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
+	return (int)(*dev->dev_ops->rx_queue_count)(dev, queue_id);
 }
 
 /**