From patchwork Tue Nov 13 12:17:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 997063 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42vRVF5Ykxz9s1c for ; Tue, 13 Nov 2018 23:18:12 +1100 (AEDT) Received: from localhost ([::1]:53422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMXdx-0006Lh-3Z for incoming@patchwork.ozlabs.org; Tue, 13 Nov 2018 07:18:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMXdU-0006K7-QW for qemu-devel@nongnu.org; Tue, 13 Nov 2018 07:17:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gMXdN-0003RK-GF for qemu-devel@nongnu.org; Tue, 13 Nov 2018 07:17:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46276) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gMXdF-0003Mr-6h; Tue, 13 Nov 2018 07:17:27 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9EE67307D963; Tue, 13 Nov 2018 12:17:20 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2C545C8A4; Tue, 13 Nov 2018 12:17:10 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Tue, 13 Nov 2018 13:17:10 +0100 Message-Id: <20181113121710.18490-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 13 Nov 2018 12:17:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] s390x/pci: properly fail if the zPCI device cannot be created X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , David Hildenbrand , Cornelia Huck , Collin Walling , Christian Borntraeger , qemu-s390x@nongnu.org, Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Right now, errors during realize()/pre_plug/plug of the zPCI device would result in QEMU crashing instead of failing nicely when creating a zPCI device for a PCI device. Reviewed-by: Thomas Huth Reviewed-by: Collin Walling Signed-off-by: David Hildenbrand --- v1 -> v2: - Fix setting of "target" property (key and value was inverted) hw/s390x/s390-pci-bus.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index e42e1b80d6..060ff062bc 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -780,17 +780,31 @@ static void s390_pci_msix_free(S390PCIBusDevice *pbdev) } static S390PCIBusDevice *s390_pci_device_new(S390pciState *s, - const char *target) + const char *target, Error **errp) { - DeviceState *dev = NULL; + Error *local_err = NULL; + DeviceState *dev; dev = qdev_try_create(BUS(s->bus), TYPE_S390_PCI_DEVICE); if (!dev) { + error_setg(errp, "zPCI device could not be created"); return NULL; } - qdev_prop_set_string(dev, "target", target); - qdev_init_nofail(dev); + object_property_set_str(OBJECT(dev), target, "target", &local_err); + if (local_err) { + object_unparent(OBJECT(dev)); + error_propagate_prepend(errp, local_err, + "zPCI device could not be created: "); + return NULL; + } + object_property_set_bool(OBJECT(dev), true, "realized", &local_err); + if (local_err) { + object_unparent(OBJECT(dev)); + error_propagate_prepend(errp, local_err, + "zPCI device could not be created: "); + return NULL; + } return S390_PCI_DEVICE(dev); } @@ -865,9 +879,8 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, pbdev = s390_pci_find_dev_by_target(s, dev->id); if (!pbdev) { - pbdev = s390_pci_device_new(s, dev->id); + pbdev = s390_pci_device_new(s, dev->id, errp); if (!pbdev) { - error_setg(errp, "create zpci device failed"); return; } }