Skip to contentSkip to conversation

mlx5: fix __mlx5_bit_off macro warning for Windows

PATCH Superseded Tal Shnaiderman 4 participants 6 messages Jan 6, 2021 – Jan 12, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlx5: fix __mlx5_bit_off macro warning for Windows

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")
---
 drivers/common/mlx5/mlx5_prm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/common/mlx5/mlx5_prm.h +1 -1
index 8c9b53ce10..2cb3bf6005 100644
@@ -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))
Signature · 1 line
2.16.1.windows.4
#1 lore raw
Quoted 9 lines · Tal Shnaiderman

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.

#2 lore raw
Quoted 11 lines

Subject: Re: [dpdk-dev] [PATCH] mlx5: fix __mlx5_bit_off macro warning for Windows

External email: Use caution opening links or attachments

Quoted 4 lines · Tal Shnaiderman

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.

Quoted 7 lines
Quoted 5 lines

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.

#3 lore raw

PATCH v2 1/1 mlx5: fix __mlx5_bit_off macro warning for Windows

In reply to Tal Shnaiderman

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 uintptr_t to be compatible for both Linux and Windows.

Fixes 865a0c15672c ("net/mlx5: add Direct Verbs prepare function")

---
v2: change type to uintptr_t [DmitryK]

---
 drivers/common/mlx5/mlx5_prm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/common/mlx5/mlx5_prm.h +1 -1
index 8c9b53ce10..b6a3a3cfcb 100644
@@ -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)(uintptr_t) \
 				  (&(__mlx5_nullp(typ)->fld)))
 #define __mlx5_dw_bit_off(typ, fld) (32 - __mlx5_bit_sz(typ, fld) - \
 				    (__mlx5_bit_off(typ, fld) & 0x1f))
Signature · 1 line
2.16.1.windows.4
Acked-by on v2 1/1
#4 lore raw

From: Tal Shnaiderman

Quoted 6 lines

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]

Quoted 7 lines

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

Fixes 865a0c15672c ("net/mlx5: add Direct Verbs prepare function")
#5 lore raw

07/01/2021 13:59, Matan Azrad:

Quoted 7 lines

From: Tal Shnaiderman

Quoted 6 lines

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]

Quoted 8 lines
Quoted 7 lines

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

Fixes 865a0c15672c ("net/mlx5: add Direct Verbs prepare function")

Applied to next-net-mlx, thanks.