[dpdk-dev,v2,6/6] ethdev: return named opaque type instead of void pointer

Message ID 20180109162317.18183-6-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers

Checks

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

Commit Message

Ferruh Yigit Jan. 9, 2018, 4:23 p.m. UTC
  "struct rte_eth_rxtx_callback" is defined as internal data structure and
used as named opaque type.

So the functions that are adding callbacks can return objects in this
type instead of void pointer.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
v2:
* keep using struct * in parameters, instead add callback functions
return struct rte_eth_rxtx_callback pointer.
---
 lib/librte_ether/rte_ethdev.c | 6 +++---
 lib/librte_ether/rte_ethdev.h | 9 ++++++---
 2 files changed, 9 insertions(+), 6 deletions(-)
  

Comments

Stephen Hemminger Jan. 9, 2018, 6:55 p.m. UTC | #1
On Tue,  9 Jan 2018 16:23:17 +0000
Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> "struct rte_eth_rxtx_callback" is defined as internal data structure and
> used as named opaque type.
> 
> So the functions that are adding callbacks can return objects in this
> type instead of void pointer.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> v2:
> * keep using struct * in parameters, instead add callback functions
> return struct rte_eth_rxtx_callback pointer.
> ---
>  lib/librte_ether/rte_ethdev.c | 6 +++---
>  lib/librte_ether/rte_ethdev.h | 9 ++++++---
>  2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
> index b3918b77a..184245880 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -3115,7 +3115,7 @@ rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
>  	return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
>  }
>  
> -void *
> +struct rte_eth_rxtx_callback *
>  rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
>  		rte_rx_callback_fn fn, void *user_param)
>  {
> @@ -3157,7 +3157,7 @@ rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
>  	return cb;
>  }
>  
> -void *
> +struct rte_eth_rxtx_callback *
>  rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
>  		rte_rx_callback_fn fn, void *user_param)
>  {
> @@ -3192,7 +3192,7 @@ rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
>  	return cb;
>  }
>  
> -void *
> +struct rte_eth_rxtx_callback *
>  rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
>  		rte_tx_callback_fn fn, void *user_param)
>  {
> diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
> index a61a97c6a..2877a455c 100644
> --- a/lib/librte_ether/rte_ethdev.h
> +++ b/lib/librte_ether/rte_ethdev.h
> @@ -2846,7 +2846,8 @@ int rte_eth_dev_get_dcb_info(uint16_t port_id,
>   *   NULL on error.
>   *   On success, a pointer value which can later be used to remove the callback.
>   */
> -void *rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
> +struct rte_eth_rxtx_callback *
> +rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
>  		rte_rx_callback_fn fn, void *user_param);
>  
>  /**
> @@ -2874,7 +2875,8 @@ void *rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
>   *   NULL on error.
>   *   On success, a pointer value which can later be used to remove the callback.
>   */
> -void *rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
> +struct rte_eth_rxtx_callback *
> +rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
>  		rte_rx_callback_fn fn, void *user_param);
>  
>  /**
> @@ -2901,7 +2903,8 @@ void *rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
>   *   NULL on error.
>   *   On success, a pointer value which can later be used to remove the callback.
>   */
> -void *rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
> +struct rte_eth_rxtx_callback *
> +rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
>  		rte_tx_callback_fn fn, void *user_param);
>  
>  /**

I would prefer that the public API keep a typed (but opaque pointer).
Use of void * is problematic and likely to cause bugs.
  
Stephen Hemminger Jan. 9, 2018, 6:58 p.m. UTC | #2
On Tue,  9 Jan 2018 16:23:17 +0000
Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> "struct rte_eth_rxtx_callback" is defined as internal data structure and
> used as named opaque type.
> 
> So the functions that are adding callbacks can return objects in this
> type instead of void pointer.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

My  comment was "yes I agree pointer should have opaque type"

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index b3918b77a..184245880 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3115,7 +3115,7 @@  rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
 	return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
 }
 
-void *
+struct rte_eth_rxtx_callback *
 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
 		rte_rx_callback_fn fn, void *user_param)
 {
@@ -3157,7 +3157,7 @@  rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
 	return cb;
 }
 
-void *
+struct rte_eth_rxtx_callback *
 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
 		rte_rx_callback_fn fn, void *user_param)
 {
@@ -3192,7 +3192,7 @@  rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
 	return cb;
 }
 
-void *
+struct rte_eth_rxtx_callback *
 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
 		rte_tx_callback_fn fn, void *user_param)
 {
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index a61a97c6a..2877a455c 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -2846,7 +2846,8 @@  int rte_eth_dev_get_dcb_info(uint16_t port_id,
  *   NULL on error.
  *   On success, a pointer value which can later be used to remove the callback.
  */
-void *rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
+struct rte_eth_rxtx_callback *
+rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
 		rte_rx_callback_fn fn, void *user_param);
 
 /**
@@ -2874,7 +2875,8 @@  void *rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
  *   NULL on error.
  *   On success, a pointer value which can later be used to remove the callback.
  */
-void *rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
+struct rte_eth_rxtx_callback *
+rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
 		rte_rx_callback_fn fn, void *user_param);
 
 /**
@@ -2901,7 +2903,8 @@  void *rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
  *   NULL on error.
  *   On success, a pointer value which can later be used to remove the callback.
  */
-void *rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
+struct rte_eth_rxtx_callback *
+rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
 		rte_tx_callback_fn fn, void *user_param);
 
 /**