aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-08-04 13:07:02 +0100
committerPeter Maydell <peter.maydell@linaro.org>2014-08-04 13:07:02 +0100
commit924c09db51b147881d51d8102deb4f285305c1b7 (patch)
treee93c98fc182fc367a98e60bed7b206dd47354dd2
parent7b13ff3f156b98c3183dfa30edfd6473e8660374 (diff)
parentc617dd3b7e8e82511060b8f7a9c51e46c5c1e87a (diff)
Merge remote-tracking branch 'remotes/amit-virtio-rng/for-2.2' into staging
* remotes/amit-virtio-rng/for-2.2: virtio-rng: replace error_set calls with error_setg virtio-rng: Move error-checking forward to prevent memory leak Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--hw/virtio/virtio-rng.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 7c5a675674..03fd04a1e5 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -142,8 +142,15 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
Error *local_err = NULL;
if (!vrng->conf.period_ms > 0) {
- error_set(errp, QERR_INVALID_PARAMETER_VALUE, "period",
- "a positive number");
+ error_setg(errp, "'period' parameter expects a positive integer");
+ return;
+ }
+
+ /* Workaround: Property parsing does not enforce unsigned integers,
+ * So this is a hack to reject such numbers. */
+ if (vrng->conf.max_bytes > INT64_MAX) {
+ error_setg(errp, "'max-bytes' parameter must be non-negative, "
+ "and less than 2^63");
return;
}
@@ -171,23 +178,15 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
"rng", NULL);
}
- virtio_init(vdev, "virtio-rng", VIRTIO_ID_RNG, 0);
-
vrng->rng = vrng->conf.rng;
if (vrng->rng == NULL) {
- error_set(errp, QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
+ error_setg(errp, "'rng' parameter expects a valid object");
return;
}
- vrng->vq = virtio_add_queue(vdev, 8, handle_input);
+ virtio_init(vdev, "virtio-rng", VIRTIO_ID_RNG, 0);
- /* Workaround: Property parsing does not enforce unsigned integers,
- * So this is a hack to reject such numbers. */
- if (vrng->conf.max_bytes > INT64_MAX) {
- error_set(errp, QERR_INVALID_PARAMETER_VALUE, "max-bytes",
- "a non-negative integer below 2^63");
- return;
- }
+ vrng->vq = virtio_add_queue(vdev, 8, handle_input);
vrng->quota_remaining = vrng->conf.max_bytes;
vrng->rate_limit_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,