summaryrefslogtreecommitdiffstats
path: root/hw/scsi/virtio-scsi.c
diff options
context:
space:
mode:
authorFam Zheng2014-10-31 04:04:31 +0100
committerPaolo Bonzini2014-10-31 11:29:02 +0100
commit0ba1f53191221b541b938df86a39eeccfb87f996 (patch)
treee930a80d0cbbf94d2d40eb8e20488b855607d1cc /hw/scsi/virtio-scsi.c
parentscsi: devirtualize unrealize of SCSI devices (diff)
downloadqemu-0ba1f53191221b541b938df86a39eeccfb87f996.tar.gz
qemu-0ba1f53191221b541b938df86a39eeccfb87f996.tar.xz
qemu-0ba1f53191221b541b938df86a39eeccfb87f996.zip
virtio-scsi: Fix num_queue input validation
We need to count the ctrlq and eventq, and also cleanup before returning. Besides, the format string should be unsigned. The number could never be less than zero. Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/scsi/virtio-scsi.c')
-rw-r--r--hw/scsi/virtio-scsi.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 235c2053da..fdcacfd79a 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -804,10 +804,11 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI,
sizeof(VirtIOSCSIConfig));
- if (s->conf.num_queues <= 0 || s->conf.num_queues > VIRTIO_PCI_QUEUE_MAX) {
- error_setg(errp, "Invalid number of queues (= %" PRId32 "), "
+ if (s->conf.num_queues == 0 ||
+ s->conf.num_queues > VIRTIO_PCI_QUEUE_MAX - 2) {
+ error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
"must be a positive integer less than %d.",
- s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX);
+ s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX - 2);
virtio_cleanup(vdev);
return;
}