From nobody Sat Nov 23 23:24:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728908590; cv=none; d=zohomail.com; s=zohoarc; b=KrttiDBBSUTHYSPXQ7/+9E1T2haQWpH7tiqxVwQFXqFRw4az6CwK0Ya00gHOWTAa6BcPOQ/8yU7jwAHZgdrOaH+NrtHrAkMnc/ieC96Uy7XLS2ZyIcfbvX8UzBW7NGZ67WGDBgDU/YtakslHfkIkBZ4RRmJqnlBC2uBILvt/R7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728908590; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=ehRD8bRJGO1blmbuDqOD01dBVabzYbJtzYYPUhjUKJE=; b=Y1eYFPnQBPmYaFRRfFb3TNhN4/p0CMsh9hIqOOaXZVWNsx4HV+zOevFfqwTYOTIw7v5in/o8sFTvufaK74ej1NDXhn886KRVMPuj3I+guF63XuBRWQf7I4120XgMV9/QUL4qOQDOzUpUYOOXFFQ5wbO8F+y6x7mbZ0cA5pDrovw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728908590353404.05792329099927; Mon, 14 Oct 2024 05:23:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0K6E-0007ML-GH; Mon, 14 Oct 2024 08:22:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0K60-0007KB-Ev for qemu-devel@nongnu.org; Mon, 14 Oct 2024 08:22:44 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0K5y-0001rv-Un for qemu-devel@nongnu.org; Mon, 14 Oct 2024 08:22:44 -0400 Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XRxDx3XwGz6K9L5; Mon, 14 Oct 2024 20:22:09 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 304ED140445; Mon, 14 Oct 2024 20:22:41 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 14 Oct 2024 14:22:40 +0200 To: , CC: Dmitry Frolov , Ajay Joshi , Yao Xingtao , Fan Ni , Shiju Jose , , Subject: [PATCH qemu 7/7] hw/pci-bridge: Make pxb_dev_realize_common() return if it succeeded Date: Mon, 14 Oct 2024 13:19:02 +0100 Message-ID: <20241014121902.2146424-8-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241014121902.2146424-1-Jonathan.Cameron@huawei.com> References: <20241014121902.2146424-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100005.china.huawei.com (7.191.160.25) To frapeml500008.china.huawei.com (7.182.85.71) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1728908591913116600 Content-Type: text/plain; charset="utf-8" For the CXL PXB there is additional code after pxb_dev_realize_common() is called. If that realize failed (e.g. due to an out of range numa_node) we will get a segfault. Return a bool so the caller can check if the pxb_dev_realize_common() succeeded or not without having to poke around in the errp. Fixes: 4f8db8711cbd ("hw/pxb: Allow creation of a CXL PXB (host bridge)") Signed-off-by: Jonathan Cameron --- hw/pci-bridge/pci_expander_bridge.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expand= er_bridge.c index 4578e03024..07d411cff5 100644 --- a/hw/pci-bridge/pci_expander_bridge.c +++ b/hw/pci-bridge/pci_expander_bridge.c @@ -330,7 +330,7 @@ static gint pxb_compare(gconstpointer a, gconstpointer = b) 0; } =20 -static void pxb_dev_realize_common(PCIDevice *dev, enum BusType type, +static bool pxb_dev_realize_common(PCIDevice *dev, enum BusType type, Error **errp) { PXBDev *pxb =3D PXB_DEV(dev); @@ -342,13 +342,13 @@ static void pxb_dev_realize_common(PCIDevice *dev, en= um BusType type, =20 if (ms->numa_state =3D=3D NULL) { error_setg(errp, "NUMA is not supported by this machine-type"); - return; + return false; } =20 if (pxb->numa_node !=3D NUMA_NODE_UNASSIGNED && pxb->numa_node >=3D ms->numa_state->num_nodes) { error_setg(errp, "Illegal numa node %d", pxb->numa_node); - return; + return false; } =20 if (dev->qdev.id && *dev->qdev.id) { @@ -394,12 +394,13 @@ static void pxb_dev_realize_common(PCIDevice *dev, en= um BusType type, pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_HOST); =20 pxb_dev_list =3D g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare); - return; + return true; =20 err_register_bus: object_unref(OBJECT(bds)); object_unparent(OBJECT(bus)); object_unref(OBJECT(ds)); + return false; } =20 static void pxb_dev_realize(PCIDevice *dev, Error **errp) @@ -500,7 +501,9 @@ static void pxb_cxl_dev_realize(PCIDevice *dev, Error *= *errp) return; } =20 - pxb_dev_realize_common(dev, CXL, errp); + if (!pxb_dev_realize_common(dev, CXL, errp)) { + return; + } pxb_cxl_dev_reset(DEVICE(dev)); } =20 --=20 2.43.0