Skip to contentSkip to conversation

fix debug macro pattern for vmxnet3

PATCH In review Miao Yan 3 participants 7 messages Dec 8, 2015 – Dec 14, 2015

lore
Share & tools
lore

Miao Yan

author
#0 lore raw

v3 cover fix debug macro pattern for vmxnet3

This patchset fixes debug macro pattern for vmxnet3. The old style uses
#ifdef...#else...#endif to define debug macros, as a result
the format string inside the macro will never be checked (debug not turned on by default) and is likely to cause build errors in the future when enabled.

Changes in v3:
- fix a build error on 32 bit platforms

Changes in v2:
- fix grammar errors in commit log

Miao Yan (4):
net/vmxnet3: fix a build error when enabling debug output net/vmxnet3: use %zu for size_t in printf net/vmxnet3: fix debug macro pattern for vmxnet3 net/vmxnet3: remove redundant VMW_SHPRN(...) definition

 hw/net/vmware_utils.h |   5 +-
 hw/net/vmxnet3.c      |   8 +--
 hw/net/vmxnet_debug.h | 139 +++++++++++++++++++++++++++++++-------------------
 3 files changed, 91 insertions(+), 61 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v3 1/4 net/vmxnet3: fix a build error when enabling debug output

Macro MAC_FMT and MAC_ARG are not defined, but used in vmxnet3_net_init(). This will cause build error when debug level is raised in vmxnet3_debug.h (enable all VMXNET3_DEBUG_xxx).

Use VMXNET_MF and VXMNET_MA instead.

---
Changes in v3:
- add Reviewed-by tag
- align subject line with others

 hw/net/vmxnet3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/vmxnet3.c +1 -1
index 5e3a233..ea3d9b7 100644
@@ -2044,7 +2044,7 @@ static void vmxnet3_net_init(VMXNET3State *s)
 
     s->link_status_and_speed = VMXNET3_LINK_SPEED | VMXNET3_LINK_STATUS_UP;
 
-    VMW_CFPRN("Permanent MAC: " MAC_FMT, MAC_ARG(s->perm_mac.a));
+    VMW_CFPRN("Permanent MAC: " VMXNET_MF, VMXNET_MA(s->perm_mac.a));
 
     s->nic = qemu_new_nic(&net_vmxnet3_info, &s->conf,
                           object_get_typename(OBJECT(s)),
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH v3 2/4 net/vmxnet3: use %zu for size_t in printf

In reply to Miao Yan

Use %zu specifier for size_t in printf, otherwise build would fail on platforms where size_t is not unsigned long

---
 hw/net/vmxnet3.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/net/vmxnet3.c +3 -3
index ea3d9b7..e168285 100644
@@ -138,7 +138,7 @@ static inline void vmxnet3_ring_init(Vmxnet3Ring *ring,
 }
 
 #define VMXNET3_RING_DUMP(macro, ring_name, ridx, r)                         \
-    macro("%s#%d: base %" PRIx64 " size %lu cell_size %lu gen %d next %lu",  \
+    macro("%s#%d: base %" PRIx64 " size %zu cell_size %zu gen %d next %zu",  \
           (ring_name), (ridx),                                               \
           (r)->pa, (r)->size, (r)->cell_size, (r)->gen, (r)->next)
 
@@ -925,7 +925,7 @@ static void vmxnet3_rx_need_csum_calculate(struct VmxnetRxPkt *pkt,
 
     /* Validate packet len: csum_start + scum_offset + length of csum field */
     if (pkt_len < (vhdr->csum_start + vhdr->csum_offset + 2)) {
-        VMW_PKPRN("packet len:%lu < csum_start(%d) + csum_offset(%d) + 2, "
+        VMW_PKPRN("packet len:%zu < csum_start(%d) + csum_offset(%d) + 2, "
                   "cannot calculate checksum",
                   pkt_len, vhdr->csum_start, vhdr->csum_offset);
         return;
@@ -1974,7 +1974,7 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size)
         vmxnet_rx_pkt_attach_data(s->rx_pkt, buf, size, s->rx_vlan_stripping);
         bytes_indicated = vmxnet3_indicate_packet(s) ? size : -1;
         if (bytes_indicated < size) {
-            VMW_PKPRN("RX: %lu of %lu bytes indicated", bytes_indicated, size);
+            VMW_PKPRN("RX: %zu of %zu bytes indicated", bytes_indicated, size);
         }
     } else {
         VMW_PKPRN("Packet dropped by RX filter");
Signature · 1 line
1.9.1
author
#3 lore raw

PATCH v3 3/4 net/vmxnet3: fix debug macro pattern for vmxnet3

In reply to Miao Yan

Vmxnet3 uses the following debug macro style:

#ifdef SOME_DEBUG
# define debug(...) do{ printf(...); } while (0)

 # else
 #  define debug(...) do{ } while (0)
 #endif

If SOME_DEBUG is undefined, then format string inside the debug macro will never be checked by compiler. Code is likely to break in the future when SOME_DEBUG is enabled
because of lack of testing. This patch changes this
to the following:

#define debug(...) \
do { if (SOME_DEBUG_ENABLED) printf(...); } while (0)

---
 hw/net/vmxnet_debug.h | 139 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 86 insertions(+), 53 deletions(-)
hw/net/vmxnet_debug.h +86 -53
index 96dae0f..96495db 100644
@@ -20,94 +20,127 @@
 
 #define VMXNET_DEVICE_NAME "vmxnet3"
 
-/* #define VMXNET_DEBUG_CB */
 #define VMXNET_DEBUG_WARNINGS
 #define VMXNET_DEBUG_ERRORS
-/* #define VMXNET_DEBUG_INTERRUPTS */
-/* #define VMXNET_DEBUG_CONFIG */
-/* #define VMXNET_DEBUG_RINGS */
-/* #define VMXNET_DEBUG_PACKETS */
-/* #define VMXNET_DEBUG_SHMEM_ACCESS */
+
+#undef VMXNET_DEBUG_CB
+#undef VMXNET_DEBUG_INTERRUPTS
+#undef VMXNET_DEBUG_CONFIG
+#undef VMXNET_DEBUG_RINGS
+#undef VMXNET_DEBUG_PACKETS
+#undef VMXNET_DEBUG_SHMEM_ACCESS
+
+#ifdef VMXNET_DEBUG_CB
+#  define VMXNET_DEBUG_CB_ENABLED 1
+#else
+#  define VMXNET_DEBUG_CB_ENABLED 0
+#endif
+
+#ifdef VMXNET_DEBUG_WARNINGS
+#  define VMXNET_DEBUG_WARNINGS_ENABLED 1
+#else
+#  define VMXNET_DEBUG_WARNINGS_ENABLED 0
+#endif
+
+#ifdef VMXNET_DEBUG_ERRORS
+#  define VMXNET_DEBUG_ERRORS_ENABLED 1
+#else
+#  define VMXNET_DEBUG_ERRORS_ENABLED 0
+#endif
+
+#ifdef VMXNET_DEBUG_CONFIG
+#  define VMXNET_DEBUG_CONFIG_ENABLED 1
+#else
+#  define VMXNET_DEBUG_CONFIG_ENABLED 0
+#endif
+
+#ifdef VMXNET_DEBUG_RINGS
+#  define VMXNET_DEBUG_RINGS_ENABLED 1
+#else
+#  define VMXNET_DEBUG_RINGS_ENABLED 0
+#endif
+
+#ifdef VMXNET_DEBUG_PACKETS
+#  define VMXNET_DEBUG_PACKETS_ENABLED 1
+#else
+#  define VMXNET_DEBUG_PACKETS_ENABLED 0
+#endif
+
+#ifdef VMXNET_DEBUG_INTERRUPTS
+#  define VMXNET_DEBUG_INTERRUPTS_ENABLED 1
+#else
+#  define VMXNET_DEBUG_INTERRUPTS_ENABLED 0
+#endif
 
 #ifdef VMXNET_DEBUG_SHMEM_ACCESS
+#  define VMXNET_DEBUG_SHMEM_ACCESS_ENABLED 1
+#else
+#  define VMXNET_DEBUG_SHMEM_ACCESS_ENABLED 0
+#endif
+
 #define VMW_SHPRN(fmt, ...)                                                   \
     do {                                                                      \
-        printf("[%s][SH][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,       \
-            ## __VA_ARGS__);                                                  \
+        if (VMXNET_DEBUG_SHMEM_ACCESS_ENABLED) {                              \
+            printf("[%s][SH][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+                ## __VA_ARGS__);                                              \
+       }                                                                      \
     } while (0)
-#else
-#define VMW_SHPRN(fmt, ...) do {} while (0)
-#endif
 
-#ifdef VMXNET_DEBUG_CB
 #define VMW_CBPRN(fmt, ...)                                                   \
     do {                                                                      \
-        printf("[%s][CB][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,       \
-            ## __VA_ARGS__);                                                  \
+        if (VMXNET_DEBUG_CB_ENABLED) {                                        \
+            printf("[%s][CB][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+                ## __VA_ARGS__);                                              \
+        }                                                                     \
     } while (0)
-#else
-#define VMW_CBPRN(fmt, ...) do {} while (0)
-#endif
 
-#ifdef VMXNET_DEBUG_PACKETS
 #define VMW_PKPRN(fmt, ...)                                                   \
     do {                                                                      \
-        printf("[%s][PK][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,       \
-            ## __VA_ARGS__);                                                  \
+        if (VMXNET_DEBUG_PACKETS_ENABLED) {                                   \
+            printf("[%s][PK][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+                ## __VA_ARGS__);                                              \
+        }                                                                     \
     } while (0)
-#else
-#define VMW_PKPRN(fmt, ...) do {} while (0)
-#endif
 
-#ifdef VMXNET_DEBUG_WARNINGS
 #define VMW_WRPRN(fmt, ...)                                                   \
     do {                                                                      \
-        printf("[%s][WR][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,       \
-            ## __VA_ARGS__);                                                  \
+        if (VMXNET_DEBUG_WARNINGS_ENABLED) {                                  \
+            printf("[%s][WR][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+                ## __VA_ARGS__);                                              \
+        }                                                                     \
     } while (0)
-#else
-#define VMW_WRPRN(fmt, ...) do {} while (0)
-#endif
 
-#ifdef VMXNET_DEBUG_ERRORS
 #define VMW_ERPRN(fmt, ...)                                                   \
     do {                                                                      \
-        printf("[%s][ER][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,       \
-            ## __VA_ARGS__);                                                  \
+        if (VMXNET_DEBUG_ERRORS_ENABLED) {                                    \
+            printf("[%s][ER][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+                ## __VA_ARGS__);                                              \
+        }                                                                     \
     } while (0)
-#else
-#define VMW_ERPRN(fmt, ...) do {} while (0)
-#endif
 
-#ifdef VMXNET_DEBUG_INTERRUPTS
 #define VMW_IRPRN(fmt, ...)                                                   \
     do {                                                                      \
-        printf("[%s][IR][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,       \
-            ## __VA_ARGS__);                                                  \
+        if (VMXNET_DEBUG_INTERRUPTS_ENABLED) {                                \
+            printf("[%s][IR][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+                ## __VA_ARGS__);                                              \
+        }                                                                     \
     } while (0)
-#else
-#define VMW_IRPRN(fmt, ...) do {} while (0)
-#endif
 
-#ifdef VMXNET_DEBUG_CONFIG
 #define VMW_CFPRN(fmt, ...)                                                   \
     do {                                                                      \
-        printf("[%s][CF][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,       \
-            ## __VA_ARGS__);                                                  \
+        if (VMXNET_DEBUG_CONFIG_ENABLED) {                                    \
+            printf("[%s][CF][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+                ## __VA_ARGS__);                                              \
+        }                                                                     \
     } while (0)
-#else
-#define VMW_CFPRN(fmt, ...) do {} while (0)
-#endif
 
-#ifdef VMXNET_DEBUG_RINGS
 #define VMW_RIPRN(fmt, ...)                                                   \
     do {                                                                      \
-        printf("[%s][RI][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,       \
-            ## __VA_ARGS__);                                                  \
+        if (VMXNET_DEBUG_RINGS_ENABLED) {                                     \
+            printf("[%s][RI][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+                ## __VA_ARGS__);                                              \
+        }                                                                     \
     } while (0)
-#else
-#define VMW_RIPRN(fmt, ...) do {} while (0)
-#endif
 
 #define VMXNET_MF       "%02X:%02X:%02X:%02X:%02X:%02X"
 #define VMXNET_MA(a)    (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
Signature · 1 line
1.9.1
author
#4 lore raw

PATCH v3 4/4 net/vmxnet3: remove redundant VMW_SHPRN(...) definition

In reply to Miao Yan

Macro VMW_SHPRN(...) is already defined vmxnet3_debug.h, so remove the duplication

---
 hw/net/vmware_utils.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/net/vmware_utils.h +1 -4
index 1099df6..c2c2f90 100644
@@ -18,10 +18,7 @@
 #define VMWARE_UTILS_H
 
 #include "qemu/range.h"
-
-#ifndef VMW_SHPRN
-#define VMW_SHPRN(fmt, ...) do {} while (0)
-#endif
+#include "vmxnet_debug.h"
 
 /*
  * Shared memory access functions with byte swap support
Signature · 1 line
1.9.1
Reviewed-by on the v3 series
#5 lore raw
In reply to Miao Yan
Reviewed-by Dmitry Fleytman <[email protected] <mailto:[email protected]>>
Quoted 28 lines · Miao Yan

This patchset fixes debug macro pattern for vmxnet3. The old style uses #ifdef...#else...#endif to define debug macros, as a result the format string inside the macro will never be checked (debug not turned on by default) and is likely to cause build errors in the future when enabled.

Changes in v3:
- fix a build error on 32 bit platforms

Changes in v2:
- fix grammar errors in commit log

Miao Yan (4):
net/vmxnet3: fix a build error when enabling debug output net/vmxnet3: use %zu for size_t in printf net/vmxnet3: fix debug macro pattern for vmxnet3 net/vmxnet3: remove redundant VMW_SHPRN(...) definition

hw/net/vmware_utils.h |   5 +-
hw/net/vmxnet3.c      |   8 +--
hw/net/vmxnet_debug.h | 139 +++++++++++++++++++++++++++++++-------------------
3 files changed, 91 insertions(+), 61 deletions(-)
Signature · 1 line
1.9.1
#6 lore raw
Quoted 35 lines · Dmitry Fleytman

<mailto:[email protected]>>

Quoted 30 lines

On 8 Dec 2015, at 07:28 AM, Miao Yan <[email protected] <mailto:[email protected]>> wrote:

This patchset fixes debug macro pattern for vmxnet3. The old style uses #ifdef...#else...#endif to define debug macros, as a result the format string inside the macro will never be checked (debug not turned on by default) and is likely to cause build errors in the future when enabled.

Changes in v3:
- fix a build error on 32 bit platforms

Changes in v2:
- fix grammar errors in commit log

Miao Yan (4):
net/vmxnet3: fix a build error when enabling debug output net/vmxnet3: use %zu for size_t in printf net/vmxnet3: fix debug macro pattern for vmxnet3 net/vmxnet3: remove redundant VMW_SHPRN(...) definition

hw/net/vmware_utils.h |   5 +-
hw/net/vmxnet3.c      |   8 +--
hw/net/vmxnet_debug.h | 139
+++++++++++++++++++++++++++++++-------------------
3 files changed, 91 insertions(+), 61 deletions(-)
Signature · 1 line
1.9.1

Queued for 2.6.

Thanks