From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=57646 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OZlit-0006sR-0L for qemu-devel@nongnu.org; Fri, 16 Jul 2010 10:17:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OZlir-0003Xq-TO for qemu-devel@nongnu.org; Fri, 16 Jul 2010 10:17:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38770) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OZlir-0003Xa-Mq for qemu-devel@nongnu.org; Fri, 16 Jul 2010 10:17:05 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6GEH4vO026021 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 16 Jul 2010 10:17:04 -0400 Date: Fri, 16 Jul 2010 17:11:46 +0300 From: "Michael S. Tsirkin" Message-ID: <20100716141146.GA4325@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] vhost: fix miration during device start List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org We need to know ring layout to allocate log buffer. So init rings first. Also fixes a theoretical memory-leak-on-error. https://bugzilla.redhat.com/show_bug.cgi?id=615228 Signed-off-by: Michael S. Tsirkin --- diff --git a/hw/vhost.c b/hw/vhost.c index d37a66e..25cb9f5 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -659,6 +659,16 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) r = -errno; goto fail; } + for (i = 0; i < hdev->nvqs; ++i) { + r = vhost_virtqueue_init(hdev, + vdev, + hdev->vqs + i, + i); + if (r < 0) { + goto fail_vq; + } + } + if (hdev->log_enabled) { hdev->log_size = vhost_get_log_size(hdev); hdev->log = hdev->log_size ? @@ -671,15 +681,6 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) } } - for (i = 0; i < hdev->nvqs; ++i) { - r = vhost_virtqueue_init(hdev, - vdev, - hdev->vqs + i, - i); - if (r < 0) { - goto fail_vq; - } - } hdev->started = true; return 0;