mlx5: fix __mlx5_bit_off macro warning for Windows

Message ID 20210106134221.12896-1-talshn@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series mlx5: fix __mlx5_bit_off macro warning for Windows |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Tal Shnaiderman Jan. 6, 2021, 1:42 p.m. UTC
  While compiling with clang 11 the callers of the
__mlx5_bit_off macro warns on the cast of pointers to
unsigned long which is a smaller int type in Windows.

warning: cast to smaller integer type 'unsigned long'
from 'u8 (*)[16]' [-Wpointer-to-int-cast]

To resolve it the type is changed to size_t to be
compatible for both Linux and Windows.

Fixes: 865a0c15672c ("net/mlx5: add Direct Verbs prepare function")
Cc: stable@dpdk.org

Signed-off-by: Tal Shnaiderman <talshn@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/common/mlx5/mlx5_prm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Dmitry Kozlyuk Jan. 6, 2021, 2:22 p.m. UTC | #1
On Wed,  6 Jan 2021 15:42:21 +0200, Tal Shnaiderman wrote:
> While compiling with clang 11 the callers of the
> __mlx5_bit_off macro warns on the cast of pointers to
> unsigned long which is a smaller int type in Windows.
> 
> warning: cast to smaller integer type 'unsigned long'
> from 'u8 (*)[16]' [-Wpointer-to-int-cast]
> 
> To resolve it the type is changed to size_t to be
> compatible for both Linux and Windows.

uintptr_t is the type for integers storing pointer values, not size_t.
  
Tal Shnaiderman Jan. 7, 2021, 11:40 a.m. UTC | #2
> Subject: Re: [dpdk-dev] [PATCH] mlx5: fix __mlx5_bit_off macro warning for
> Windows
> 
> External email: Use caution opening links or attachments
> 
> 
> On Wed,  6 Jan 2021 15:42:21 +0200, Tal Shnaiderman wrote:
> > While compiling with clang 11 the callers of the __mlx5_bit_off macro
> > warns on the cast of pointers to unsigned long which is a smaller int
> > type in Windows.
> >
> > warning: cast to smaller integer type 'unsigned long'
> > from 'u8 (*)[16]' [-Wpointer-to-int-cast]
> >
> > To resolve it the type is changed to size_t to be compatible for both
> > Linux and Windows.
> 
> uintptr_t is the type for integers storing pointer values, not size_t.

Correct, thanks.
  

Patch

diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index 8c9b53ce10..2cb3bf6005 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -601,7 +601,7 @@  typedef uint8_t u8;
 
 #define __mlx5_nullp(typ) ((struct mlx5_ifc_##typ##_bits *)0)
 #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld)
-#define __mlx5_bit_off(typ, fld) ((unsigned int)(unsigned long) \
+#define __mlx5_bit_off(typ, fld) ((unsigned int)(size_t) \
 				  (&(__mlx5_nullp(typ)->fld)))
 #define __mlx5_dw_bit_off(typ, fld) (32 - __mlx5_bit_sz(typ, fld) - \
 				    (__mlx5_bit_off(typ, fld) & 0x1f))