Received: from eggs.gnu.org ([2001:4830:134:3::10]:40405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apzu5-0000Nw-NO for qemu-devel@nongnu.org; Tue, 12 Apr 2016 11:07:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1apzu2-0005Nw-EV for qemu-devel@nongnu.org; Tue, 12 Apr 2016 11:06:57 -0400 Received: from mail-qg0-x22b.google.com ([2607:f8b0:400d:c04::22b]:33743) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apzu2-0005Nr-8m for qemu-devel@nongnu.org; Tue, 12 Apr 2016 11:06:54 -0400 Received: by mail-qg0-x22b.google.com with SMTP id j35so18263038qge.0 for ; Tue, 12 Apr 2016 08:06:54 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Tue, 12 Apr 2016 17:06:42 +0200 Message-Id: <1460473602-4830-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCHv2 for-2.6] ivshmem: fix ivshmem-{plain, doorbell} crash without arg List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau "qemu -device ivshmem-{plain,doorbell}" will crash, because the device doesn't check that the required argument is provided. Signed-off-by: Marc-André Lureau --- hw/misc/ivshmem.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 2eb8668..e40f23b 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -872,6 +872,8 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp) s->ivshmem_bar2 = host_memory_backend_get_memory(s->hostmem, &error_abort); } else { + assert(s->server_chr); + IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n", s->server_chr->filename); @@ -1051,10 +1053,24 @@ static void ivshmem_plain_init(Object *obj) &error_abort); } +static void ivshmem_plain_realize(PCIDevice *dev, Error **errp) +{ + IVShmemState *s = IVSHMEM_COMMON(dev); + + if (!s->hostmem) { + error_setg(errp, "You must specify a 'memdev'"); + return; + } + + ivshmem_common_realize(dev, errp); +} + static void ivshmem_plain_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + k->realize = ivshmem_plain_realize; dc->props = ivshmem_plain_properties; dc->vmsd = &ivshmem_plain_vmsd; } @@ -1099,10 +1115,24 @@ static void ivshmem_doorbell_init(Object *obj) s->legacy_size = SIZE_MAX; /* whatever the server sends */ } +static void ivshmem_doorbell_realize(PCIDevice *dev, Error **errp) +{ + IVShmemState *s = IVSHMEM_COMMON(dev); + + if (!s->server_chr) { + error_setg(errp, "You must specify a 'chardev'"); + return; + } + + ivshmem_common_realize(dev, errp); +} + static void ivshmem_doorbell_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + k->realize = ivshmem_doorbell_realize; dc->props = ivshmem_doorbell_properties; dc->vmsd = &ivshmem_doorbell_vmsd; } -- 2.5.5