[PATCH] bs_sheepdog.c: add missing initialization of read data length

Ryusuke Konishi <[email protected]>
Newsgroups org.kernel.vger.stgt
Message-ID <[email protected]>
In the sheepdog driver, the read data length argument of do_req
function is not initialized by some caller functions such as
sd_sync(), sd_close(), and create_branch().

This patch adds those missing initializations to prevent uncertain
behavior in do_req() and fixes the following warning of valgrind:

 ==1885== Conditional jump or move depends on uninitialised value(s)
 ==1885==    at 0x425994: do_req (bs_sheepdog.c:598)
 ==1885==    by 0x426A06: bs_sheepdog_close (bs_sheepdog.c:1100)
 ==1885==    by 0x4142B4: tgt_device_destroy (target.c:705)
 ==1885==    by 0x412335: tgt_mgmt (mgmt.c:222)
 ==1885==    by 0x412776: mtask_handler (mgmt.c:494)
 ==1885==    by 0x4106A8: event_loop (tgtd.c:411)
 ==1885==    by 0x410D64: main (tgtd.c:583)

Signed-off-by: Ryusuke Konishi <[email protected]>
Cc: Hitoshi Mitake <[email protected]>
---
 usr/bs_sheepdog.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/usr/bs_sheepdog.c b/usr/bs_sheepdog.c
index 07ad0de..f11b693 100644
--- a/usr/bs_sheepdog.c
+++ b/usr/bs_sheepdog.c
@@ -708,7 +708,7 @@ static int sd_sync(struct sheepdog_access_info *ai)
 	int ret;
 	struct sheepdog_obj_req hdr;
 	struct sheepdog_obj_rsp *rsp = (struct sheepdog_obj_rsp *)&hdr;
-	unsigned int wlen = 0, rlen;
+	unsigned int wlen = 0, rlen = 0;
 
 	memset(&hdr, 0, sizeof(hdr));
 
@@ -1087,7 +1087,7 @@ static void sd_close(struct sheepdog_access_info *ai)
 {
 	struct sheepdog_vdi_req hdr;
 	struct sheepdog_vdi_rsp *rsp = (struct sheepdog_vdi_rsp *)&hdr;
-	unsigned int wlen = 0, rlen;
+	unsigned int wlen = 0, rlen = 0;
 	int ret;
 
 	memset(&hdr, 0, sizeof(hdr));
@@ -1120,6 +1120,7 @@ static int create_branch(struct sheepdog_access_info *ai)
 	hdr.vdi_id = ai->inode.vdi_id;
 	hdr.flags = SD_FLAG_CMD_WRITE;
 	wlen = SD_MAX_VDI_LEN;
+	rlen = 0;
 	hdr.data_length = wlen;
 
 	ret = do_req(ai, (struct sheepdog_req *)&hdr, ai->inode.name,
@@ -1135,6 +1136,7 @@ static int create_branch(struct sheepdog_access_info *ai)
 
 	hdr.flags = SD_FLAG_CMD_WRITE;
 	wlen = SD_MAX_VDI_LEN;
+	rlen = 0;
 	hdr.data_length = wlen;
 	hdr.vdi_size = ai->inode.vdi_size;
 	ret = do_req(ai, (struct sheepdog_req *)&hdr, ai->inode.name,
-- 
1.7.9.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.