Skip to contentSkip to conversation

net/gve: replace typedefs with macros in gve osdep

PATCH In review Joshua Washington 3 participants 3 messages Oct 17, 2024 – Oct 18, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/gve: replace typedefs with macros in gve osdep

Currently, a number of integer types are typedef'd to their corresponding upserspace or RTE values. This can be problematic if these types are already defined somewhere else, as it would cause type collisions. This patch changes the typedefs to #define macros which are only defined if the types are not defined already.

Fixes c9ba2caf6302 ("net/gve/base: add OS-specific implementation")
Fixes abf1242fbb84 ("net/gve: add struct members and typedefs for DQO")
---
 drivers/net/gve/base/gve_osdep.h | 48 ++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 12 deletions(-)
drivers/net/gve/base/gve_osdep.h +36 -12
index c0ee0d567c..64181cebd6 100644
@@ -29,22 +29,46 @@
 #include <sys/utsname.h>
 #endif
 
-typedef uint8_t u8;
-typedef uint16_t u16;
-typedef uint32_t u32;
-typedef uint64_t u64;
+#ifndef u8
+#define u8 uint8_t
+#endif
+#ifndef u16
+#define u16 uint16_t
+#endif
+#ifndef u32
+#define u32 uint32_t
+#endif
+#ifndef u64
+#define u64 uint64_t
+#endif
 
-typedef rte_be16_t __sum16;
+#ifndef __sum16
+#define __sum16 rte_be16_t
+#endif
 
-typedef rte_be16_t __be16;
-typedef rte_be32_t __be32;
-typedef rte_be64_t __be64;
+#ifndef __be16
+#define __be16 rte_be16_t
+#endif
+#ifndef __be32
+#define __be32 rte_be32_t
+#endif
+#ifndef __be64
+#define __be64 rte_be64_t
+#endif
 
-typedef rte_le16_t __le16;
-typedef rte_le32_t __le32;
-typedef rte_le64_t __le64;
+#ifndef __le16
+#define __le16 rte_le16_t
+#endif
+#ifndef __le32
+#define __le32 rte_le32_t
+#endif
+#ifndef __le64
+#define __le64 rte_le64_t
+#endif
 
-typedef rte_iova_t dma_addr_t;
+#ifndef dma_addr_t
+#define dma_addr_t rte_iova_t
+#endif
 
 #define ETH_MIN_MTU	RTE_ETHER_MIN_MTU
 #define ETH_ALEN	RTE_ETHER_ADDR_LEN
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
#1 lore raw
Quoted 6 lines · Joshua Washington

Currently, a number of integer types are typedef'd to their corresponding upserspace or RTE values. This can be problematic if these types are already defined somewhere else, as it would cause type collisions. This patch changes the typedefs to #define macros which are only defined if the types are not defined already.

Quoted 8 lines
Fixes c9ba2caf6302 ("net/gve/base: add OS-specific implementation")
Fixes abf1242fbb84 ("net/gve: add struct members and typedefs for DQO")

Thanks Joshua, probably better to get this fix directly to main for -rc1, in patchwork assigned it to David.

#2 lore raw
In reply to Joshua Washington

Hello Joshua,

Quoted 7 lines · Joshua Washington

Currently, a number of integer types are typedef'd to their corresponding upserspace or RTE values. This can be problematic if these types are already defined somewhere else, as it would cause type collisions. This patch changes the typedefs to #define macros which are only defined if the types are not defined already.

Quoted 6 lines
Fixes c9ba2caf6302 ("net/gve/base: add OS-specific implementation")
Fixes abf1242fbb84 ("net/gve: add struct members and typedefs for DQO")

Re-reading /usr/include/linux/types.h, I suspect the #ifndef on each type is unneeded (since always true: those types are not #define'd in the first place).
But in any case, this looks ok to me.

Thanks for the fix, applied in main.

Signature · 1 line
David Marchand