Skip to contentSkip to conversation

hw: net: cadence_gem: Fix build errors in DB_PRINT()

PATCH Superseded Bin Meng 4 participants 9 messages Aug 5, 2019 – Aug 8, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/1 hw: net: cadence_gem: Fix build errors in DB_PRINT()

When CADENCE_GEM_ERR_DEBUG is turned on, there are several compilation errors in DB_PRINT(). Fix them.

---

 hw/net/cadence_gem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +4 -3
index d412085..7516e8f 100644
@@ -983,8 +983,9 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
             return -1;
         }
 
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
-                rx_desc_get_buffer(s->rx_desc[q]));
+        DB_PRINT("copy %d bytes to " TARGET_FMT_plx "\n",
+                 MIN(bytes_to_copy, rxbufsize),
+                 rx_desc_get_buffer(s, s->rx_desc[q]));
 
         /* Copy packet data to emulated DMA buffer */
         address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +
@@ -1157,7 +1158,7 @@ static void gem_transmit(CadenceGEMState *s)
             if (tx_desc_get_length(desc) > sizeof(tx_packet) -
                                                (p - tx_packet)) {
                 DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space " \
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%lx\n", (unsigned)packet_desc_addr,
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 26 lines · Bin Meng

When CADENCE_GEM_ERR_DEBUG is turned on, there are several compilation errors in DB_PRINT(). Fix them.

---

 hw/net/cadence_gem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +3 -2
index d412085..7516e8f 100644
@@ -983,8 +983,9 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
             return -1;
         }
 
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
-                rx_desc_get_buffer(s->rx_desc[q]));
+        DB_PRINT("copy %d bytes to " TARGET_FMT_plx "\n",
+                 MIN(bytes_to_copy, rxbufsize),
+                 rx_desc_get_buffer(s, s->rx_desc[q]));
 
         /* Copy packet data to emulated DMA buffer */
         address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +

hw/net/cadence_gem.c static void gem_transmit(CadenceGEMState *s) · line 1161

Quoted 5 lines
hw/net/cadence_gem.c +1 -1
@@ -1157,7 +1158,7 @@ static void gem_transmit(CadenceGEMState *s)
             if (tx_desc_get_length(desc) > sizeof(tx_packet) -
                                                (p - tx_packet)) {
                 DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space " \
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%lx\n", (unsigned)packet_desc_addr,

What about using 'z' modifier? I mean "0x%zx" to print sizeof(..).

Thanks,
Stefano

author
#2 lore raw
Quoted 25 lines · Stefano Garzarella
Quoted 23 lines · Bin Meng

When CADENCE_GEM_ERR_DEBUG is turned on, there are several compilation errors in DB_PRINT(). Fix them.

---

 hw/net/cadence_gem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +3 -2
index d412085..7516e8f 100644
@@ -983,8 +983,9 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
             return -1;
         }
 
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
-                rx_desc_get_buffer(s->rx_desc[q]));
+        DB_PRINT("copy %d bytes to " TARGET_FMT_plx "\n",
+                 MIN(bytes_to_copy, rxbufsize),
+                 rx_desc_get_buffer(s, s->rx_desc[q]));
 
Quoted 10 lines

hw/net/cadence_gem.c static void gem_transmit(CadenceGEMState *s) · line 1161

Quoted 8 lines
hw/net/cadence_gem.c +1 -1
         /* Copy packet data to emulated DMA buffer */
         address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +
@@ -1157,7 +1158,7 @@ static void gem_transmit(CadenceGEMState *s)
             if (tx_desc_get_length(desc) > sizeof(tx_packet) -
                                                (p - tx_packet)) {
                 DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space " \
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%lx\n", (unsigned)packet_desc_addr,

What about using 'z' modifier? I mean "0x%zx" to print sizeof(..).

Yes, good idea. Will do in v2. Thanks!

Regards,
Bin

author
#3 lore raw

PATCH v2 1/1 hw: net: cadence_gem: Fix build errors in DB_PRINT()

In reply to Bin Meng

When CADENCE_GEM_ERR_DEBUG is turned on, there are several compilation errors in DB_PRINT(). Fix them.

---

Changes in v2:
- use HWADDR_PRIx instead of TARGET_FMT_plx for consistency
- use 'z' modifier to print sizeof(..)

 hw/net/cadence_gem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +4 -3
index d412085..b6ff2c1 100644
@@ -983,8 +983,9 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
             return -1;
         }
 
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
-                rx_desc_get_buffer(s->rx_desc[q]));
+        DB_PRINT("copy %d bytes to 0x%" HWADDR_PRIx "\n",
+                 MIN(bytes_to_copy, rxbufsize),
+                 rx_desc_get_buffer(s, s->rx_desc[q]));
 
         /* Copy packet data to emulated DMA buffer */
         address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +
@@ -1157,7 +1158,7 @@ static void gem_transmit(CadenceGEMState *s)
             if (tx_desc_get_length(desc) > sizeof(tx_packet) -
                                                (p - tx_packet)) {
                 DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space " \
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%zx\n", (unsigned)packet_desc_addr,
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;
Signature · 1 line
2.7.4
#4 lore raw

Hi,

Quoted 8 lines · Bin Meng

When CADENCE_GEM_ERR_DEBUG is turned on, there are several compilation errors in DB_PRINT(). Fix them.

---

Changes in v2:

Please don't reply to previous version, post as a new thread (it is harder to notice your new versions in a emails threaded view).

Quoted 11 lines

- use HWADDR_PRIx instead of TARGET_FMT_plx for consistency
- use 'z' modifier to print sizeof(..)

 hw/net/cadence_gem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +0 -0
index d412085..b6ff2c1 100644

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) · line 986

Quoted 6 lines
hw/net/cadence_gem.c +1 -2
@@ -983,8 +983,9 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
             return -1;
         }
 
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
-                rx_desc_get_buffer(s->rx_desc[q]));
+        DB_PRINT("copy %d bytes to 0x%" HWADDR_PRIx "\n",

rx_desc_get_buffer() returns a uint64_t, shouldn't you use a PRIx64 format here?

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) · line 987

Quoted 1 line
hw/net/cadence_gem.c +1 -0
+                 MIN(bytes_to_copy, rxbufsize),

Nitpick #1: since you are cleaning this file up, bytes_to_copy and rxbufsize are both unsigned, so the first format should be %u instead of %d.

hw/net/cadence_gem.c static void gem_transmit(CadenceGEMState *s) · line 1161

Quoted 10 lines
hw/net/cadence_gem.c +2 -1
+                 rx_desc_get_buffer(s, s->rx_desc[q]));
 
         /* Copy packet data to emulated DMA buffer */
         address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +
@@ -1157,7 +1158,7 @@ static void gem_transmit(CadenceGEMState *s)
             if (tx_desc_get_length(desc) > sizeof(tx_packet) -
                                                (p - tx_packet)) {
                 DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space " \
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%zx\n", (unsigned)packet_desc_addr,

Nitpick #2: packet_desc_addr is of type hwaddr, so removing the cast the 1st format is HWADDR_PRIx, also removing the 2nd cast the 2nd format is PRIx64.

Then the 3rd format is now correct.

Quoted 4 lines
hw/net/cadence_gem.c +0 -0
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;
author
#5 lore raw
Quoted 7 lines · Philippe Mathieu-Daudé

Hi,

Quoted 3 lines · Bin Meng

When CADENCE_GEM_ERR_DEBUG is turned on, there are several compilation errors in DB_PRINT(). Fix them.

Quoted 9 lines
Quoted 5 lines

---

Changes in v2:

Please don't reply to previous version, post as a new thread (it is harder to notice your new versions in a emails threaded view).

OK.

Quoted 14 lines
Quoted 14 lines

- use HWADDR_PRIx instead of TARGET_FMT_plx for consistency
- use 'z' modifier to print sizeof(..)

 hw/net/cadence_gem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +0 -0
index d412085..b6ff2c1 100644
@@ -983,8 +983,9 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
             return -1;
         }
 
Quoted 6 lines

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) · line 986

Quoted 3 lines
hw/net/cadence_gem.c +1 -2
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
-                rx_desc_get_buffer(s->rx_desc[q]));
+        DB_PRINT("copy %d bytes to 0x%" HWADDR_PRIx "\n",

rx_desc_get_buffer() returns a uint64_t, shouldn't you use a PRIx64 format here?

HWADDR_PRIx expands to PRIx64. I got your point that since it does not return hwaddr, so we should use PRIx64 directly. Correct?

Quoted 5 lines

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) · line 987

Quoted 2 lines
hw/net/cadence_gem.c +1 -0
+                 MIN(bytes_to_copy, rxbufsize),

Nitpick #1: since you are cleaning this file up, bytes_to_copy and rxbufsize are both unsigned, so the first format should be %u instead of %d.

Sure, will do in v3.

Quoted 15 lines

hw/net/cadence_gem.c static void gem_transmit(CadenceGEMState *s) · line 1161

Quoted 11 lines
hw/net/cadence_gem.c +2 -1
+                 rx_desc_get_buffer(s, s->rx_desc[q]));
 
         /* Copy packet data to emulated DMA buffer */
         address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +
@@ -1157,7 +1158,7 @@ static void gem_transmit(CadenceGEMState *s)
             if (tx_desc_get_length(desc) > sizeof(tx_packet) -
                                                (p - tx_packet)) {
                 DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space " \
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%zx\n", (unsigned)packet_desc_addr,

Nitpick #2: packet_desc_addr is of type hwaddr, so removing the cast the 1st format is HWADDR_PRIx, also removing the 2nd cast the 2nd format is PRIx64.

packet_desc_addr() return unsigned, so %x should be OK.

Quoted 7 lines

Then the 3rd format is now correct.

Quoted 4 lines
hw/net/cadence_gem.c +0 -0
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;

Regards,
Bin

#6 lore raw
Quoted 68 lines · Bin Meng
Quoted 7 lines · Philippe Mathieu-Daudé

Hi,

Quoted 3 lines · Bin Meng

When CADENCE_GEM_ERR_DEBUG is turned on, there are several compilation errors in DB_PRINT(). Fix them.

Quoted 9 lines
Quoted 5 lines

---

Changes in v2:

Please don't reply to previous version, post as a new thread (it is harder to notice your new versions in a emails threaded view).

OK.

Quoted 14 lines
Quoted 14 lines

- use HWADDR_PRIx instead of TARGET_FMT_plx for consistency
- use 'z' modifier to print sizeof(..)

 hw/net/cadence_gem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +0 -0
index d412085..b6ff2c1 100644
@@ -983,8 +983,9 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
             return -1;
         }
 
Quoted 6 lines

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) · line 986

Quoted 3 lines
hw/net/cadence_gem.c +1 -2
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
-                rx_desc_get_buffer(s->rx_desc[q]));
+        DB_PRINT("copy %d bytes to 0x%" HWADDR_PRIx "\n",

rx_desc_get_buffer() returns a uint64_t, shouldn't you use a PRIx64 format here?

HWADDR_PRIx expands to PRIx64. I got your point that since it does not return hwaddr, so we should use PRIx64 directly. Correct?

Quoted 5 lines

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) · line 987

Quoted 2 lines
hw/net/cadence_gem.c +1 -0
+                 MIN(bytes_to_copy, rxbufsize),

Nitpick #1: since you are cleaning this file up, bytes_to_copy and rxbufsize are both unsigned, so the first format should be %u instead of %d.

Sure, will do in v3.

Quoted 15 lines

hw/net/cadence_gem.c static void gem_transmit(CadenceGEMState *s) · line 1161

Quoted 11 lines
hw/net/cadence_gem.c +2 -1
+                 rx_desc_get_buffer(s, s->rx_desc[q]));
 
         /* Copy packet data to emulated DMA buffer */
         address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +
@@ -1157,7 +1158,7 @@ static void gem_transmit(CadenceGEMState *s)
             if (tx_desc_get_length(desc) > sizeof(tx_packet) -
                                                (p - tx_packet)) {
                 DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space " \
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%zx\n", (unsigned)packet_desc_addr,

Nitpick #2: packet_desc_addr is of type hwaddr, so removing the cast the 1st format is HWADDR_PRIx, also removing the 2nd cast the 2nd format is PRIx64.

Quoted 1 line

packet_desc_addr() return unsigned, so %x should be OK.

'packet_desc_addr' is of type hwaddr, '(unsigned)packet_desc_addr' is casted to type unsigned.

Anyhow I now remember I already reviewed this patch:
https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg03263.html

Quoted 7 lines
Quoted 7 lines

Then the 3rd format is now correct.

Quoted 4 lines
hw/net/cadence_gem.c +0 -0
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;
author
#7 lore raw
Quoted 70 lines · Philippe Mathieu-Daudé
Quoted 68 lines · Bin Meng
Quoted 7 lines · Philippe Mathieu-Daudé

Hi,

Quoted 3 lines · Bin Meng

When CADENCE_GEM_ERR_DEBUG is turned on, there are several compilation errors in DB_PRINT(). Fix them.

Quoted 9 lines
Quoted 5 lines

---

Changes in v2:

Please don't reply to previous version, post as a new thread (it is harder to notice your new versions in a emails threaded view).

OK.

Quoted 14 lines
Quoted 14 lines

- use HWADDR_PRIx instead of TARGET_FMT_plx for consistency
- use 'z' modifier to print sizeof(..)

 hw/net/cadence_gem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +0 -0
index d412085..b6ff2c1 100644
@@ -983,8 +983,9 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
             return -1;
         }
 
Quoted 6 lines

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) · line 986

Quoted 3 lines
hw/net/cadence_gem.c +1 -2
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
-                rx_desc_get_buffer(s->rx_desc[q]));
+        DB_PRINT("copy %d bytes to 0x%" HWADDR_PRIx "\n",

rx_desc_get_buffer() returns a uint64_t, shouldn't you use a PRIx64 format here?

HWADDR_PRIx expands to PRIx64. I got your point that since it does not return hwaddr, so we should use PRIx64 directly. Correct?

Quoted 5 lines

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) · line 987

Quoted 2 lines
hw/net/cadence_gem.c +1 -0
+                 MIN(bytes_to_copy, rxbufsize),

Nitpick #1: since you are cleaning this file up, bytes_to_copy and rxbufsize are both unsigned, so the first format should be %u instead of %d.

Sure, will do in v3.

Quoted 15 lines

hw/net/cadence_gem.c static void gem_transmit(CadenceGEMState *s) · line 1161

Quoted 11 lines
hw/net/cadence_gem.c +2 -1
+                 rx_desc_get_buffer(s, s->rx_desc[q]));
 
         /* Copy packet data to emulated DMA buffer */
         address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +
@@ -1157,7 +1158,7 @@ static void gem_transmit(CadenceGEMState *s)
             if (tx_desc_get_length(desc) > sizeof(tx_packet) -
                                                (p - tx_packet)) {
                 DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space " \
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%zx\n", (unsigned)packet_desc_addr,

Nitpick #2: packet_desc_addr is of type hwaddr, so removing the cast the 1st format is HWADDR_PRIx, also removing the 2nd cast the 2nd format is PRIx64.

Quoted 3 lines
Quoted 1 line

packet_desc_addr() return unsigned, so %x should be OK.

'packet_desc_addr' is of type hwaddr,

Ah, a typo! I meant to say: tx_desc_get_length() returns unsigned, so just removing the 2nd cast is correct. But you wanted to change to PRIx64 which I don't understand.

Quoted 5 lines

'(unsigned)packet_desc_addr' is casted to type unsigned.

Anyhow I now remember I already reviewed this patch:
https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg03263.html

OK, looks the same issue was discovered by someone else :)

Regards,
Bin

#8 lore raw
In reply to Bin Meng
Quoted 2 lines · Bin Meng

When CADENCE_GEM_ERR_DEBUG is turned on, there are several compilation errors in DB_PRINT(). Fix them.

The first fix should be to ensure the format strings are validated in normal compilation. This can be achieved by allowing the compiler to optimise away debug strings with constant folding... for example:

  #define tlb_debug(fmt, ...) do { \
      if (DEBUG_TLB_LOG_GATE) { \
          qemu_log_mask(CPU_LOG_MMU, "%s: " fmt, __func__, \
                        ## __VA_ARGS__); \
      } else if (DEBUG_TLB_GATE) { \
          fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); \
      } \
  } while (0)

However ultimately most debug printfs are either a) stale leftovers from original development or b) could be considered for conversion to tracepoints.

Quoted 29 lines

---

Changes in v2:
- use HWADDR_PRIx instead of TARGET_FMT_plx for consistency
- use 'z' modifier to print sizeof(..)

 hw/net/cadence_gem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +3 -2
index d412085..b6ff2c1 100644
@@ -983,8 +983,9 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
             return -1;
         }
 
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
-                rx_desc_get_buffer(s->rx_desc[q]));
+        DB_PRINT("copy %d bytes to 0x%" HWADDR_PRIx "\n",
+                 MIN(bytes_to_copy, rxbufsize),
+                 rx_desc_get_buffer(s, s->rx_desc[q]));
 
         /* Copy packet data to emulated DMA buffer */
         address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +

hw/net/cadence_gem.c static void gem_transmit(CadenceGEMState *s) · line 1164

Quoted 8 lines
hw/net/cadence_gem.c +1 -1
@@ -1157,7 +1158,7 @@ static void gem_transmit(CadenceGEMState *s)
             if (tx_desc_get_length(desc) > sizeof(tx_packet) -
                                                (p - tx_packet)) {
                 DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space " \
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%zx\n", (unsigned)packet_desc_addr,
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;

--
Alex Bennée