Skip to contentSkip to conversation

spapr_vscsi: Set uninitialized variable

PATCH In review Stefan Weil 4 participants 5 messages Apr 3, 2011 – Apr 5, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr_vscsi: Set uninitialized variable

cppcheck reports this error:

hw/spapr_vscsi.c:274: error: Uninitialized variable: rc

If llen == 0, rc was indeed used without being initialized.

---
 hw/spapr_vscsi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/spapr_vscsi.c +1 -1
index e142dae..9928334 100644
@@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s, vscsi_req *req,
 {
     struct srp_direct_buf *md = req->cur_desc;
     uint32_t llen;
-    int rc;
+    int rc = 0;
 
     dprintf("VSCSI: direct segment 0x%x bytes, va=0x%llx desc len=0x%x\n",
             len, (unsigned long long)md->va, md->len);
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 16 lines · Stefan Weil

cppcheck reports this error:

hw/spapr_vscsi.c:274: error: Uninitialized variable: rc

If llen == 0, rc was indeed used without being initialized.

---
  hw/spapr_vscsi.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
hw/spapr_vscsi.c +0 -0
index e142dae..9928334 100644

hw/spapr_vscsi.c static int vscsi_srp_direct_data(VSCSIState *s, vscsi_req *req, · line 258

Quoted 5 lines
hw/spapr_vscsi.c +1 -1
@@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s, vscsi_req *req,
  {
      struct srp_direct_buf *md = req->cur_desc;
      uint32_t llen;
-    int rc;
+    int rc = 0;

David, is this correct? Or would rc be -1 when !llen?

Alex

#2 lore raw
Quoted 12 lines · Alexander Graf
Quoted 11 lines · Stefan Weil

cppcheck reports this error:

hw/spapr_vscsi.c:274: error: Uninitialized variable: rc

If llen == 0, rc was indeed used without being initialized.

---
 hw/spapr_vscsi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 12 lines

hw/spapr_vscsi.c static int vscsi_srp_direct_data(VSCSIState *s, vscsi_req *req, · line 258

Quoted 10 lines
hw/spapr_vscsi.c +1 -1
index e142dae..9928334 100644
@@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s, vscsi_req *req,
 {
     struct srp_direct_buf *md = req->cur_desc;
     uint32_t llen;
-    int rc;
+    int rc = 0;

David, is this correct? Or would rc be -1 when !llen?

I talked to Ben, who wrote this code - apparently his mail server blew up. This patch should be correct, AFAWCT. It's not totally clear what the right return value should be in thie case, or indeed that this case ever actually happens, but we think 0 is right.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw
Quoted 8 lines · David Gibson
Quoted 1 line

Review static int vscsi_srp_direct_data(VSCSIState *s,

Quoted 1 line
(quoted diff) +0 -0
@@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s,

vscsi_req *req,

Quoted 6 lines
Quoted 5 lines
hw/spapr_vscsi.c +1 -1
 {
     struct srp_direct_buf *md = req->cur_desc;
     uint32_t llen;
-    int rc;
+    int rc = 0;
Quoted 6 lines
Quoted 1 line

David, is this correct? Or would rc be -1 when !llen?

I talked to Ben, who wrote this code - apparently his mail server blew up. This patch should be correct, AFAWCT. It's not totally clear what the right return value should be in thie case, or indeed that this case ever actually happens, but we think 0 is right.

Just double checked and we never call that function if len is 0

Cheers,
Ben.

#4 lore raw
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 8 lines · David Gibson
Quoted 1 line

Review static int vscsi_srp_direct_data(VSCSIState *s,

Quoted 1 line
(quoted diff) +0 -0
@@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s,

vscsi_req *req,

Quoted 6 lines
Quoted 5 lines
hw/spapr_vscsi.c +1 -1
 {
    struct srp_direct_buf *md = req->cur_desc;
    uint32_t llen;
-    int rc;
+    int rc = 0;
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

David, is this correct? Or would rc be -1 when !llen?

I talked to Ben, who wrote this code - apparently his mail server blew up. This patch should be correct, AFAWCT. It's not totally clear what the right return value should be in thie case, or indeed that this case ever actually happens, but we think 0 is right.

Just double checked and we never call that function if len is 0

That's probably the reason gcc didn't complain before. So I'll just take Stefan's patch.

Alex