Skip to contentSkip to conversation

net: cadence_gem: fix compilation error when debug is on

PATCH Superseded Ramon Fried 5 participants 8 messages Jun 11, 2019 – Jun 15, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: cadence_gem: fix compilation error when debug is on

defining CADENCE_GEM_ERR_DEBUG causes compilation
errors, fix that.

---
v2: change %lx to HWADDR_PRIx and %lx to %zdx

 hw/net/cadence_gem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +3 -3
index 7f63411430..e9b1b1e2eb 100644
@@ -982,8 +982,8 @@ 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]) +
@@ -1156,7 +1156,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%zdx\n", (unsigned)packet_desc_addr,
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;
Signature · 1 line
2.21.0
#1 lore raw

Le 11/06/2019 à 16:55, Ramon Fried a écrit :

Quoted 6 lines

defining CADENCE_GEM_ERR_DEBUG causes compilation
errors, fix that.

---
v2: change %lx to HWADDR_PRIx and %lx to %zdx

HWADDR_PRIx is to use with hwaddr type (packet_desc_addr). rx_desc_get_buffer() is uint64_t, you must use PRIx64. It may be better to remove also the cast to unsigned.

Thanks,
Laurent

Quoted 29 lines
 hw/net/cadence_gem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +3 -3
index 7f63411430..e9b1b1e2eb 100644
@@ -982,8 +982,8 @@ 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]) +
@@ -1156,7 +1156,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%zdx\n", (unsigned)packet_desc_addr,
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;
#2 lore raw
Quoted 4 lines · Laurent Vivier
Quoted 3 lines · Ramon Fried

defining CADENCE_GEM_ERR_DEBUG causes compilation
errors, fix that.

Quoted 8 lines
Quoted 3 lines

---
v2: change %lx to HWADDR_PRIx and %lx to %zdx

HWADDR_PRIx is to use with hwaddr type (packet_desc_addr). rx_desc_get_buffer() is uint64_t, you must use PRIx64. It may be better to remove also the cast to unsigned.

Other places in the code also use HWADDR_PRIx with rx_desc_get_buffer(). Should I change them also ?

Quoted 39 lines

Thanks,
Laurent

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const

Quoted 9 lines
 hw/net/cadence_gem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +0 -0
index 7f63411430..e9b1b1e2eb 100644
@@ -982,8 +982,8 @@ static ssize_t gem_receive(NetClientState *nc, const

uint8_t *buf, size_t size)

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

Quoted 4 lines
hw/net/cadence_gem.c +0 -1
             return -1;
         }
 
-        DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy,

rxbufsize),

hw/net/cadence_gem.c static ssize_t gem_receive(NetClientState *nc, const · line 985

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

MIN(bytes_to_copy, rxbufsize),

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

Quoted 4 lines
hw/net/cadence_gem.c +1 -0
+                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 1158

Quoted 4 lines
hw/net/cadence_gem.c +0 -0
@@ -1156,7 +1156,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 " \

Quoted 6 lines
hw/net/cadence_gem.c +1 -1
-                         "0x%x\n", (unsigned)packet_desc_addr,
+                         "0x%zdx\n", (unsigned)packet_desc_addr,
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;
#3 lore raw

Le 12/06/2019 à 06:27, Ramon Fried a écrit :

Quoted 14 lines

On Tue, Jun 11, 2019 at 7:21 PM Laurent Vivier <[email protected] <mailto:[email protected]>> wrote:

Le 11/06/2019 à 16:55, Ramon Fried a écrit :
> defining CADENCE_GEM_ERR_DEBUG causes compilation > errors, fix that.
>
> Signed-off-by: Ramon Fried <[email protected] <mailto:[email protected]>>
> ---
> v2: change %lx to HWADDR_PRIx and %lx to %zdx

Quoted 6 lines

HWADDR_PRIx is to use with hwaddr type (packet_desc_addr). rx_desc_get_buffer() is uint64_t, you must use PRIx64. It may be better to remove also the cast to unsigned.

Other places in the code also use HWADDR_PRIx with  rx_desc_get_buffer(). Should I change them also ?

No, in fact you should change the return type of rx_desc_get_buffer() to hwaddr.

Thanks,
Laurent

#4 lore raw
Quoted 19 lines · Laurent Vivier
Quoted 18 lines · Ramon Fried

On Tue, Jun 11, 2019 at 7:21 PM Laurent Vivier <[email protected] <mailto:[email protected]>> wrote:

Le 11/06/2019 à 16:55, Ramon Fried a écrit :
> defining CADENCE_GEM_ERR_DEBUG causes compilation > errors, fix that.
>
> Signed-off-by: Ramon Fried <[email protected] <mailto:[email protected]>>
> ---
> v2: change %lx to HWADDR_PRIx and %lx to %zdx

HWADDR_PRIx is to use with hwaddr type (packet_desc_addr). rx_desc_get_buffer() is uint64_t, you must use PRIx64. It may be better to remove also the cast to unsigned.

Quoted 6 lines
Quoted 2 lines

Other places in the code also use HWADDR_PRIx with rx_desc_get_buffer(). Should I change them also ?

No, in fact you should change the return type of rx_desc_get_buffer() to hwaddr.

Make sense.
I'll do it in a different patch.

Quoted 4 lines

Thanks,
Laurent

#5 lore raw
In reply to Ramon Fried
Quoted 26 lines · Ramon Fried

defining CADENCE_GEM_ERR_DEBUG causes compilation
errors, fix that.

---
v2: change %lx to HWADDR_PRIx and %lx to %zdx

 hw/net/cadence_gem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +2 -2
index 7f63411430..e9b1b1e2eb 100644
@@ -982,8 +982,8 @@ 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 1159

Quoted 5 lines
hw/net/cadence_gem.c +1 -1
@@ -1156,7 +1156,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%zdx\n", (unsigned)packet_desc_addr,

The format is either "zd" or "zx". I misunderstood how you want to print it, if you want hexadecimal, it should be "zx" then.

Quoted 4 lines
hw/net/cadence_gem.c +0 -0
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;
#6 lore raw
In reply to Ramon Fried
Quoted 2 lines · Ramon Fried

defining CADENCE_GEM_ERR_DEBUG causes compilation
errors, fix that.

It would be worth doing something like:

#ifdef CADENCE_GEM_ERR_DEBUG
#define CADENCE_GEM_GATE 1
#else
#define CADENCE_GEM_GATE 0
#endif

#define DB_PRINT(...) do { \
    if (CADENCE_GEM_GATE) { \
        fprintf(stderr,  ": %s: ", __func__); \
        fprintf(stderr, ## __VA_ARGS__); \
    } \
} while (0)

So these format strings don't go stale in and only get detected on --debug builds.

While your at it I suspect the fprintf debug would be better of as:

  qemu_log("%s: " fmt, __func__, ## args);
Quoted 24 lines

---
v2: change %lx to HWADDR_PRIx and %lx to %zdx

 hw/net/cadence_gem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/net/cadence_gem.c +2 -2
index 7f63411430..e9b1b1e2eb 100644
@@ -982,8 +982,8 @@ 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 1162

Quoted 8 lines
hw/net/cadence_gem.c +1 -1
@@ -1156,7 +1156,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%zdx\n", (unsigned)packet_desc_addr,
                          (unsigned)tx_desc_get_length(desc),
                          sizeof(tx_packet) - (p - tx_packet));
                 break;

--
Alex Bennée

#7 lore raw
Quoted 21 lines · Alex Bennée
Quoted 2 lines · Ramon Fried

defining CADENCE_GEM_ERR_DEBUG causes compilation
errors, fix that.

It would be worth doing something like:

#ifdef CADENCE_GEM_ERR_DEBUG
#define CADENCE_GEM_GATE 1
#else
#define CADENCE_GEM_GATE 0
#endif

#define DB_PRINT(...) do { \
    if (CADENCE_GEM_GATE) { \
        fprintf(stderr,  ": %s: ", __func__); \
        fprintf(stderr, ## __VA_ARGS__); \
    } \
} while (0)
Quoted 6 lines

So these format strings don't go stale in and only get detected on --debug builds.

While your at it I suspect the fprintf debug would be better of as:

  qemu_log("%s: " fmt, __func__, ## args);

Indeed, or even see if it is worth converting to full-on trace points for dynamic control of whether to catch these things without having to recompile debug on or off.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org