Skip to contentSkip to conversation

vhost/scsi: silence uninitialized variable warning

PATCH In review Dan Carpenter 2 participants 3 messages Jan 12, 2017 – Jan 13, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost/scsi: silence uninitialized variable warning

This is to silence an uninitialized variable warning in debug output. The problem is this line:

	pr_debug("vhost_get_vq_desc: head: %d, out: %u in: %u\n",
		 head, out, in);

If "head = vq->num" is true on the first iteration then "out" and "in" aren't initialized. We handle that a few lines after the printk. I was tempted to just delete the pr_debug() but I decided to just initialize them to zero instead.

Also checkpatch.pl complains if variables are declared as just "unsigned" without the "int".

drivers/vhost/scsi.c +1 -1
index 253310c..b98dac1 100644
@@ -843,7 +843,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
 	struct iov_iter out_iter, in_iter, prot_iter, data_iter;
 	u64 tag;
 	u32 exp_data_len, data_direction;
-	unsigned out, in;
+	unsigned int out = 0, in = 0;
 	int head, ret, prot_bytes;
 	size_t req_size, rsp_size = sizeof(struct virtio_scsi_cmd_resp);
 	size_t out_size, in_size;
Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines · Dan Carpenter

This is to silence an uninitialized variable warning in debug output. The problem is this line:

	pr_debug("vhost_get_vq_desc: head: %d, out: %u in: %u\n",
		 head, out, in);

If "head = vq->num" is true on the first iteration then "out" and "in" aren't initialized. We handle that a few lines after the printk. I was tempted to just delete the pr_debug() but I decided to just initialize them to zero instead.

Also checkpatch.pl complains if variables are declared as just "unsigned" without the "int".

drivers/vhost/scsi.c +0 -0
index 253310c..b98dac1 100644

drivers/vhost/scsi.c vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) · line 849

Quoted 8 lines
drivers/vhost/scsi.c +1 -1
@@ -843,7 +843,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
  	struct iov_iter out_iter, in_iter, prot_iter, data_iter;
  	u64 tag;
  	u32 exp_data_len, data_direction;
-	unsigned out, in;
+	unsigned int out = 0, in = 0;
  	int head, ret, prot_bytes;
  	size_t req_size, rsp_size = sizeof(struct virtio_scsi_cmd_resp);
  	size_t out_size, in_size;
Acked-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 21 lines · Dan Carpenter

This is to silence an uninitialized variable warning in debug output. The problem is this line:

	pr_debug("vhost_get_vq_desc: head: %d, out: %u in: %u\n",
		 head, out, in);

If "head == vq->num" is true on the first iteration then "out" and "in" aren't initialized. We handle that a few lines after the printk. I was tempted to just delete the pr_debug() but I decided to just initialize them to zero instead.

Also checkpatch.pl complains if variables are declared as just "unsigned" without the "int".

drivers/vhost/scsi.c +0 -0
index 253310c..b98dac1 100644

drivers/vhost/scsi.c vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) · line 849

Quoted 8 lines
drivers/vhost/scsi.c +1 -1
@@ -843,7 +843,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
  	struct iov_iter out_iter, in_iter, prot_iter, data_iter;
  	u64 tag;
  	u32 exp_data_len, data_direction;
-	unsigned out, in;
+	unsigned int out = 0, in = 0;
  	int head, ret, prot_bytes;
  	size_t req_size, rsp_size = sizeof(struct virtio_scsi_cmd_resp);
  	size_t out_size, in_size;

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization