From 0e328dce774690e72b5a61d52c2e53625025ed24 Mon Sep 17 00:00:00 2001
From: Amos Kong <akong@redhat.com>
Date: Wed, 15 Jan 2014 09:58:04 +0100
Subject: [PATCH 35/39] virtio-rng: add check of period

RH-Author: Amos Kong <akong@redhat.com>
Message-id: <1389779886-26583-2-git-send-email-akong@redhat.com>
Patchwork-id: 56724
O-Subject: [RHEL-6.6 qemu-kvm PATCH 1/3] virtio-rng: add check of period
Bugzilla: 786407
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>

If period is assigned to 0, limit timer will expire immediately.
It causes a qemu warning:

"main-loop: WARNING: I/O thread spun for 1000 iterations"

This limit is meaningless. This patch forbids to assign 0 to period.

Reviewed-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Amos Kong <akong@redhat.com>
Message-id: 1385031203-23790-1-git-send-email-akong@redhat.com
Signed-off-by: Anthony Liguori <aliguori@amazon.com>
(backported from commit d44bb8604e87ecd3823f12f0c92d5e56d613de0d)
---
 hw/virtio-rng.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 hw/virtio-rng.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index 74de086..da539e2 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -160,6 +160,12 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
 
     vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
 
+    if (!conf->period_ms > 0) {
+        qerror_report(QERR_INVALID_PARAMETER_VALUE, "period",
+                      "a positive number");
+        return NULL;
+    }
+
     vrng->rng = conf->rng;
     if (vrng->rng == NULL) {
         qerror_report(QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
-- 
1.7.1

