Skip to contentSkip to conversation

VMXNET3: initialize rx_ridx to eliminate compile warning

PATCH Applied Wenchao Xia 4 participants 5 messages Mar 26, 2013 – Apr 2, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VMXNET3: initialize rx_ridx to eliminate compile warning

Gcc report "hw/vmxnet3.c:972: error: ‘rx_ridx’ may be used
uninitialized in this function", so fix it.

---
 hw/vmxnet3.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/vmxnet3.c +1 -1
index 925be80..bdd256e 100644
@@ -969,7 +969,7 @@ vmxnet3_indicate_packet(VMXNET3State *s)
     struct Vmxnet3_RxDesc rxd;
     bool is_head = true;
     uint32_t rxd_idx;
-    uint32_t rx_ridx;
+    uint32_t rx_ridx = 0;
 
     struct Vmxnet3_RxCompDesc rxcd;
     uint32_t new_rxcd_gen = VMXNET3_INIT_GEN;
Signature · 1 line
1.7.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Wenchao Xia

Gcc report "hw/vmxnet3.c:972: error: ‘rx_ridx’ may be used
uninitialized in this function", so fix it.

---
 hw/vmxnet3.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/vmxnet3.c +0 -0
index 925be80..bdd256e 100644

hw/vmxnet3.c vmxnet3_indicate_packet(VMXNET3State *s) · line 972

Quoted 5 lines
hw/vmxnet3.c +1 -1
@@ -969,7 +969,7 @@ vmxnet3_indicate_packet(VMXNET3State *s)
     struct Vmxnet3_RxDesc rxd;
     bool is_head = true;
     uint32_t rxd_idx;
-    uint32_t rx_ridx;
+    uint32_t rx_ridx = 0;

This seems to be a gcc weakness in some versions.

No warnings here with gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8).

I manually checked the code and there is no path which can use uninitialized rx_ridx:

static bool
vmxnet3_indicate_packet(VMXNET3State *s)

{
    struct Vmxnet3_RxDesc rxd;
    bool is_head = true;
    uint32_t rxd_idx;
    uint32_t rx_ridx;
[...]
    while (bytes_left > 0) {
[...]
        if (!vmxnet3_get_next_rx_descr(s, is_head, &rxd, &rxd_idx, &rx_ridx)) {
            break;
        }

rx_ridx is assigned by vmxnet3_get_next_rx_descr() unless it returns false.

Quoted 1 line

From now on rx_ridx is initialized.

[...]

        rxcd.rqID = RXQ_IDX + rx_ridx * s->rxq_num;

Used here, fine since we initialized it above.

[...]
VMW_RIPRN("RX Completion descriptor: rxRing: %lu rxIdx %lu len %lu "
"sop %d csum_correct %lu",
(unsigned long) rx_ridx,

Used here, fine since we initialized it above.

[...]

    }

Not used outside the while loop.

#2 lore raw
In reply to Wenchao Xia
Quoted 7 lines · Wenchao Xia

Gcc report "hw/vmxnet3.c:972: error: ‘rx_ridx’ may be used
uninitialized in this function", so fix it.

---
 hw/vmxnet3.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Anthony: Please apply this fix directly. I think there's no need to go through the net tree.

Stefan

#3 lore raw
In reply to Wenchao Xia

Hi, Wenchao

Thanks for fixing this!

Dmitry.

Quoted 26 lines · Wenchao Xia

Gcc report "hw/vmxnet3.c:972: error: ‘rx_ridx’ may be used
uninitialized in this function", so fix it.

---
 hw/vmxnet3.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/vmxnet3.c +1 -2
index 925be80..bdd256e 100644
@@ -969,7 +969,7 @@ vmxnet3_indicate_packet(VMXNET3State *s)
     struct Vmxnet3_RxDesc rxd;
     bool is_head = true;
     uint32_t rxd_idx;
-    uint32_t rx_ridx;
+    uint32_t rx_ridx = 0;
 
     struct Vmxnet3_RxCompDesc rxcd;
     uint32_t new_rxcd_gen = VMXNET3_INIT_GEN;
--

1.7.1