From nobody Tue Feb 10 02:54:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1597725353; cv=none; d=zohomail.com; s=zohoarc; b=GaLcjn1lhwB/MUGsf9qdBZimS7UN+vuStPXSN3znDtwlj+lPjLS+DmtlX21EWCwA/zQwehRWxmKlwjfnm3j1YRG5NbKcuy5vkiQo/nZtjAQd1uIGh2XKTcI8E3WYfceQ+9IPeCjzZ2KIwURXHMpzKLSIMq9BtSaTAJzgDIdMX+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597725353; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uR1KE+HQn0Nmw3s/n710vdteJLo4kaWwow8ItGqY380=; b=U7PFmdmmptfOCZ5r3TRQZiPeM8kyGn+uRTMiKGVWnXc+Rne1XCAim/SFKZvyi6BO1h9sIu1iD296afZFxMSUFZiSzBcTjN8eLRO4zlD83XZh34ZXQdR53RLIyr3nXyrmg2AVUlUoT6ld2tgZJ/z0O1108I4z8ZtnJEpxMxEhqnQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1597725353835332.8037850496597; Mon, 17 Aug 2020 21:35:53 -0700 (PDT) Received: from localhost ([::1]:37330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7tLk-0002Ja-H0 for importer@patchew.org; Tue, 18 Aug 2020 00:35:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7t6d-00005g-Mz; Tue, 18 Aug 2020 00:20:15 -0400 Received: from bilbo.ozlabs.org ([2401:3900:2:1::2]:44891 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7t6b-0006P4-Ub; Tue, 18 Aug 2020 00:20:15 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BVyNg1tCZz9sVs; Tue, 18 Aug 2020 14:19:30 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1597724371; bh=mzYaBhcj7sVVdZGDz5/VrsQHJfRajhepE23JXYXmoLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ht+Chm5508kAIwgGjaSS8/cwvMDPqI505vxTzMjSVQeibEjb2Od+vV6zrByXt+rWr 1R0LnQrpGcJqeV7545rBeDGGlKGCCrvt7/UAjvGHyrsko67gAkU64HatcWBRIMZD98 8BkdLQbfw+iTymBO7WGq4ORrhQgPPgTc1sM//rx8= From: David Gibson To: peter.maydell@linaro.org, groug@kaod.org Subject: [PULL 28/40] spapr/xive: Rework error handling of kvmppc_xive_mmap() Date: Tue, 18 Aug 2020 14:19:10 +1000 Message-Id: <20200818041922.251708-29-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200818041922.251708-1-david@gibson.dropbear.id.au> References: <20200818041922.251708-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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: pass client-ip=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 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, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz Callers currently check failures of kvmppc_xive_mmap() through the @errp argument, which isn't a recommanded practice. It is preferred to use a return value when possible. Since NULL isn't an invalid address in theory, it seems better to return MAP_FAILED and to teach callers to handle it. Signed-off-by: Greg Kurz Message-Id: <159707845972.1489912.719896767746375765.stgit@bahia.lan> Signed-off-by: David Gibson --- hw/intc/spapr_xive_kvm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c index d801bf5cd1..b2a36fd59d 100644 --- a/hw/intc/spapr_xive_kvm.c +++ b/hw/intc/spapr_xive_kvm.c @@ -698,6 +698,7 @@ int kvmppc_xive_post_load(SpaprXive *xive, int version_= id) return 0; } =20 +/* Returns MAP_FAILED on error and sets errno */ static void *kvmppc_xive_mmap(SpaprXive *xive, int pgoff, size_t len, Error **errp) { @@ -708,7 +709,6 @@ static void *kvmppc_xive_mmap(SpaprXive *xive, int pgof= f, size_t len, pgoff << page_shift); if (addr =3D=3D MAP_FAILED) { error_setg_errno(errp, errno, "XIVE: unable to set memory mapping"= ); - return NULL; } =20 return addr; @@ -728,6 +728,7 @@ int kvmppc_xive_connect(SpaprInterruptController *intc,= uint32_t nr_servers, size_t tima_len =3D 4ull << TM_SHIFT; CPUState *cs; int fd; + void *addr; =20 /* * The KVM XIVE device already in use. This is the case when @@ -763,11 +764,12 @@ int kvmppc_xive_connect(SpaprInterruptController *int= c, uint32_t nr_servers, /* * 1. Source ESB pages - KVM mapping */ - xsrc->esb_mmap =3D kvmppc_xive_mmap(xive, KVM_XIVE_ESB_PAGE_OFFSET, es= b_len, - &local_err); - if (local_err) { + addr =3D kvmppc_xive_mmap(xive, KVM_XIVE_ESB_PAGE_OFFSET, esb_len, + &local_err); + if (addr =3D=3D MAP_FAILED) { goto fail; } + xsrc->esb_mmap =3D addr; =20 memory_region_init_ram_device_ptr(&xsrc->esb_mmio_kvm, OBJECT(xsrc), "xive.esb-kvm", esb_len, xsrc->esb_m= map); @@ -781,11 +783,13 @@ int kvmppc_xive_connect(SpaprInterruptController *int= c, uint32_t nr_servers, /* * 3. TIMA pages - KVM mapping */ - xive->tm_mmap =3D kvmppc_xive_mmap(xive, KVM_XIVE_TIMA_PAGE_OFFSET, ti= ma_len, - &local_err); - if (local_err) { + addr =3D kvmppc_xive_mmap(xive, KVM_XIVE_TIMA_PAGE_OFFSET, tima_len, + &local_err); + if (addr =3D=3D MAP_FAILED) { goto fail; } + xive->tm_mmap =3D addr; + memory_region_init_ram_device_ptr(&xive->tm_mmio_kvm, OBJECT(xive), "xive.tima", tima_len, xive->tm_mmap= ); memory_region_add_subregion_overlap(&xive->tm_mmio, 0, --=20 2.26.2