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>
This commit is contained in:
Fam Zheng 2014-10-31 11:04:31 +08:00 committed by Paolo Bonzini
parent fb7b5c0df6
commit 0ba1f53191

View File

@ -804,10 +804,11 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI, virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI,
sizeof(VirtIOSCSIConfig)); sizeof(VirtIOSCSIConfig));
if (s->conf.num_queues <= 0 || s->conf.num_queues > VIRTIO_PCI_QUEUE_MAX) { if (s->conf.num_queues == 0 ||
error_setg(errp, "Invalid number of queues (= %" PRId32 "), " 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.", "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); virtio_cleanup(vdev);
return; return;
} }