From nobody Sat Nov 15 13:22:24 2025 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 ARC-Seal: i=1; a=rsa-sha256; t=1595007706; cv=none; d=zohomail.com; s=zohoarc; b=Jtyw6dMv2J2gHk5Hy6Rtn8wGzzFzQE72y/wn6Cw+DF/hQoVLIXWcGmOEq/ohOdsgbs7VLWcslQNLE8sZzhYgLvDuI7Yubjt+yEKZ/VfirnaltD1l5tGVv652XMpxBsQsRBDTzLfBEK5B3AwemcavwbNriOjIFDPbyME9V8yNn0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595007706; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=4dCf56XIjgaWQeXFlJmm0xSrKiD/3ddGyb2WCZwChiI=; b=AMnigbGhU6+xuU9x+IOvhkXtePb5cgvuW7OOovNc3+rFMLgvdmEGXbncfmVjLgENKYDmOYJDrVf3OVRsg4P0TR+MYXE6pOSTE3rxye9/PQIG+3fUiBbDzSnnHJ97j21pZxBXTybox1fJ4Pe3njDoXzkDoaBAsDnEkaezYDTSAIk= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595007706170189.48417971465642; Fri, 17 Jul 2020 10:41:46 -0700 (PDT) Received: from localhost ([::1]:33888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwUMi-0003Ga-2d for importer@patchew.org; Fri, 17 Jul 2020 13:41:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwULP-0002dx-14 for qemu-devel@nongnu.org; Fri, 17 Jul 2020 13:40:23 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:48919 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jwULN-0001sz-Ic for qemu-devel@nongnu.org; Fri, 17 Jul 2020 13:40:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-419-sq4Ls5n3MhS_HQk96JGEcg-1; Fri, 17 Jul 2020 13:40:08 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F1B1108E; Fri, 17 Jul 2020 17:40:07 +0000 (UTC) Received: from bahia.lan (ovpn-113-187.ams2.redhat.com [10.36.113.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D8FB619C4; Fri, 17 Jul 2020 17:40:06 +0000 (UTC) X-MC-Unique: sq4Ls5n3MhS_HQk96JGEcg-1 Subject: [PATCH for-5.2] spapr: Simplify error handling in spapr_phb_realize() From: Greg Kurz To: David Gibson Date: Fri, 17 Jul 2020 19:40:05 +0200 Message-ID: <159500760539.383731.10928308889360009122.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable 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: softfail client-ip=207.211.31.81; envelope-from=groug@kaod.org; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/17 05:27:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The spapr_phb_realize() function has a local_err variable which is used to: 1) check failures of spapr_irq_findone() and spapr_irq_claim() 2) prepend extra information to the error message Recent work from Markus Armbruster highlighted we get better code when testing the return value of a function, rather than setting up all the local_err boiler plate. For similar reasons, it is now preferred to use ERRP_GUARD() and error_prepend() rather than error_propagate_prepend(). Since spapr_irq_findone() and spapr_irq_claim() return negative values in case of failure, do both changes. This is just cleanup, no functional impact. Signed-off-by: Greg Kurz Reviewed-by: Markus Armbruster --- Since we add ERRP_GUARD(), we could theoretically check *errp rather than the return value, and thus avoid the uint32_t to int32_t change but I personally find it clearer the other way. --- hw/ppc/spapr_pci.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 21681215d405..b1ce51327db4 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1796,6 +1796,7 @@ static void spapr_phb_destroy_msi(gpointer opaque) =20 static void spapr_phb_realize(DeviceState *dev, Error **errp) { + ERRP_GUARD(); /* We don't use SPAPR_MACHINE() in order to exit gracefully if the user * tries to add a sPAPR PHB to a non-pseries machine. */ @@ -1813,7 +1814,6 @@ static void spapr_phb_realize(DeviceState *dev, Error= **errp) uint64_t msi_window_size =3D 4096; SpaprTceTable *tcet; const unsigned windows_supported =3D spapr_phb_windows_supported(sphb); - Error *local_err =3D NULL; =20 if (!spapr) { error_setg(errp, TYPE_SPAPR_PCI_HOST_BRIDGE " needs a pseries mach= ine"); @@ -1964,13 +1964,12 @@ static void spapr_phb_realize(DeviceState *dev, Err= or **errp) =20 /* Initialize the LSI table */ for (i =3D 0; i < PCI_NUM_PINS; i++) { - uint32_t irq =3D SPAPR_IRQ_PCI_LSI + sphb->index * PCI_NUM_PINS + = i; + int32_t irq =3D SPAPR_IRQ_PCI_LSI + sphb->index * PCI_NUM_PINS + i; =20 if (smc->legacy_irq_allocation) { - irq =3D spapr_irq_findone(spapr, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "can't allocate LSIs: "); + irq =3D spapr_irq_findone(spapr, errp); + if (irq < 0) { + error_prepend(errp, "can't allocate LSIs: "); /* * Older machines will never support PHB hotplug, ie, this= is an * init only path and QEMU will terminate. No need to roll= back. @@ -1979,9 +1978,8 @@ static void spapr_phb_realize(DeviceState *dev, Error= **errp) } } =20 - spapr_irq_claim(spapr, irq, true, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, "can't allocate LSIs:= "); + if (spapr_irq_claim(spapr, irq, true, errp) < 0) { + error_prepend(errp, "can't allocate LSIs: "); goto unrealize; } =20