drivers: use common container_of macro

Message ID 20240213153741.2133915-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series drivers: use common container_of macro |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

David Marchand Feb. 13, 2024, 3:37 p.m. UTC
  rte_common.h provides container_of if none is defined.

The drivers headers touched by this commit either already include
rte_common.h or use some other common macro defined in rte_common.h.
As a consequence, it seems safe to assume that container_of is always
available for includers of those headers.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/cxgbe/cxgbe_compat.h      | 6 ------
 drivers/net/i40e/i40e_rxtx.h          | 5 -----
 drivers/raw/ifpga/base/ifpga_compat.h | 5 -----
 3 files changed, 16 deletions(-)
  

Comments

Tyler Retzlaff Feb. 13, 2024, 4:57 p.m. UTC | #1
On Tue, Feb 13, 2024 at 04:37:41PM +0100, David Marchand wrote:
> rte_common.h provides container_of if none is defined.
> 
> The drivers headers touched by this commit either already include
> rte_common.h or use some other common macro defined in rte_common.h.
> As a consequence, it seems safe to assume that container_of is always
> available for includers of those headers.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---

Reviewed-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  
fengchengwen Feb. 14, 2024, 2:18 a.m. UTC | #2
Acked-by: Chengwen Feng <fengchengwen@huawei.com>

On 2024/2/13 23:37, David Marchand wrote:
> rte_common.h provides container_of if none is defined.
>
> The drivers headers touched by this commit either already include
> rte_common.h or use some other common macro defined in rte_common.h.
> As a consequence, it seems safe to assume that container_of is always
> available for includers of those headers.
>
> Signed-off-by: David Marchand<david.marchand@redhat.com>
> ---
>   drivers/net/cxgbe/cxgbe_compat.h      | 6 ------
>   drivers/net/i40e/i40e_rxtx.h          | 5 -----
>   drivers/raw/ifpga/base/ifpga_compat.h | 5 -----
>   3 files changed, 16 deletions(-)
>
> diff --git a/drivers/net/cxgbe/cxgbe_compat.h b/drivers/net/cxgbe/cxgbe_compat.h
> index 0b02eb62a9..e74d476f6d 100644
> --- a/drivers/net/cxgbe/cxgbe_compat.h
> +++ b/drivers/net/cxgbe/cxgbe_compat.h
> @@ -135,12 +135,6 @@ typedef uint64_t  dma_addr_t;
>    */
>   #define cxgbe_roundup(_p, _s) (((unsigned long)(_p) + (_s - 1)) & ~(_s - 1))
>   
> -#ifndef container_of
> -#define container_of(ptr, type, member) ({ \
> -		typeof(((type *)0)->member)(*__mptr) = (ptr); \
> -		(type *)((char *)__mptr - offsetof(type, member)); })
> -#endif
> -
>   #define ARRAY_SIZE(arr) RTE_DIM(arr)
>   
>   #define cpu_to_be16(o) rte_cpu_to_be_16(o)
> diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h
> index b191f23e1f..a3a53ffce4 100644
> --- a/drivers/net/i40e/i40e_rxtx.h
> +++ b/drivers/net/i40e/i40e_rxtx.h
> @@ -45,11 +45,6 @@
>   #define I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK   0x03
>   #define I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX   0x01
>   
> -#undef container_of
> -#define container_of(ptr, type, member) ({ \
> -		typeof(((type *)0)->member)(*__mptr) = (ptr); \
> -		(type *)((char *)__mptr - offsetof(type, member)); })
> -
>   #define I40E_TD_CMD (I40E_TX_DESC_CMD_ICRC |\
>   		     I40E_TX_DESC_CMD_EOP)
>   
> diff --git a/drivers/raw/ifpga/base/ifpga_compat.h b/drivers/raw/ifpga/base/ifpga_compat.h
> index cdeca70ca5..8a624d174f 100644
> --- a/drivers/raw/ifpga/base/ifpga_compat.h
> +++ b/drivers/raw/ifpga/base/ifpga_compat.h
> @@ -7,11 +7,6 @@
>   
>   #include "opae_osdep.h"
>   
> -#undef container_of
> -#define container_of(ptr, type, member) ({ \
> -		typeof(((type *)0)->member)(*__mptr) = (ptr); \
> -		(type *)((char *)__mptr - offsetof(type, member)); })
> -
>   #define IFPGA_PAGE_SHIFT       12
>   #define IFPGA_PAGE_SIZE        (1 << IFPGA_PAGE_SHIFT)
>   #define IFPGA_PAGE_MASK        (~(IFPGA_PAGE_SIZE - 1))
  
David Marchand Feb. 14, 2024, 12:20 p.m. UTC | #3
On Tue, Feb 13, 2024 at 4:38 PM David Marchand
<david.marchand@redhat.com> wrote:
>
> rte_common.h provides container_of if none is defined.
>
> The drivers headers touched by this commit either already include
> rte_common.h or use some other common macro defined in rte_common.h.
> As a consequence, it seems safe to assume that container_of is always
> available for includers of those headers.
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Applied, thanks.
  

Patch

diff --git a/drivers/net/cxgbe/cxgbe_compat.h b/drivers/net/cxgbe/cxgbe_compat.h
index 0b02eb62a9..e74d476f6d 100644
--- a/drivers/net/cxgbe/cxgbe_compat.h
+++ b/drivers/net/cxgbe/cxgbe_compat.h
@@ -135,12 +135,6 @@  typedef uint64_t  dma_addr_t;
  */
 #define cxgbe_roundup(_p, _s) (((unsigned long)(_p) + (_s - 1)) & ~(_s - 1))
 
-#ifndef container_of
-#define container_of(ptr, type, member) ({ \
-		typeof(((type *)0)->member)(*__mptr) = (ptr); \
-		(type *)((char *)__mptr - offsetof(type, member)); })
-#endif
-
 #define ARRAY_SIZE(arr) RTE_DIM(arr)
 
 #define cpu_to_be16(o) rte_cpu_to_be_16(o)
diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h
index b191f23e1f..a3a53ffce4 100644
--- a/drivers/net/i40e/i40e_rxtx.h
+++ b/drivers/net/i40e/i40e_rxtx.h
@@ -45,11 +45,6 @@ 
 #define I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK   0x03
 #define I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX   0x01
 
-#undef container_of
-#define container_of(ptr, type, member) ({ \
-		typeof(((type *)0)->member)(*__mptr) = (ptr); \
-		(type *)((char *)__mptr - offsetof(type, member)); })
-
 #define I40E_TD_CMD (I40E_TX_DESC_CMD_ICRC |\
 		     I40E_TX_DESC_CMD_EOP)
 
diff --git a/drivers/raw/ifpga/base/ifpga_compat.h b/drivers/raw/ifpga/base/ifpga_compat.h
index cdeca70ca5..8a624d174f 100644
--- a/drivers/raw/ifpga/base/ifpga_compat.h
+++ b/drivers/raw/ifpga/base/ifpga_compat.h
@@ -7,11 +7,6 @@ 
 
 #include "opae_osdep.h"
 
-#undef container_of
-#define container_of(ptr, type, member) ({ \
-		typeof(((type *)0)->member)(*__mptr) = (ptr); \
-		(type *)((char *)__mptr - offsetof(type, member)); })
-
 #define IFPGA_PAGE_SHIFT       12
 #define IFPGA_PAGE_SIZE        (1 << IFPGA_PAGE_SHIFT)
 #define IFPGA_PAGE_MASK        (~(IFPGA_PAGE_SIZE - 1))