From nobody Thu Nov 13 20:39:59 2025 Delivered-To: importer@patchew.org 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582739484; cv=none; d=zohomail.com; s=zohoarc; b=KNiU5fbsGyXndyBbODjc7SpILZeYxn/5fsjoe+3cRMb6zFaqek1Wn7OrjnLUlTBwly4FPHdIi4xPz4a9gED6M5fXvFpi7YguXGBfsNJ/hEc3wzh8WNCrr4ld3tG0/02y+w/K5fam0qyNwEx2mknlmE+yWieeTjiDUVFjnF++4UQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582739484; 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=PVJimd7XWYvK/2lEtQ/c78Pe+KySLIgBIAvJuJi82nE=; b=eXqelGnaCJxhECMPKj/GPGJdvlreeQTZqqa0Oxsri+Tgcw2YICSKKn96ro98HhCljeJGO2qpCzxFtJgV/KM5gENsKfbHjbfBfD4Xy/TEDNF3chuSTovTEvrNgUWQC4sI/pi3ryAJPToJFGBRiWYeh6mQ9mFZ1VcIqx0YwG357e0= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582739484453911.2228887278354; Wed, 26 Feb 2020 09:51:24 -0800 (PST) Received: from localhost ([::1]:47958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j70qB-00008Y-9i for importer@patchew.org; Wed, 26 Feb 2020 12:51:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58551) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j70p8-0007Ii-3X for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:50:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j70p7-0006zD-2Z for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:50:18 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:31874 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j70p6-0006y0-UO for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:50:17 -0500 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-189-xgdWhHD5M8uLTEAz1OQ86g-1; Wed, 26 Feb 2020 12:50:14 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F89A1922961; Wed, 26 Feb 2020 17:50:12 +0000 (UTC) Received: from x1w.redhat.com (ovpn-205-195.brq.redhat.com [10.40.205.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E364890519; Wed, 26 Feb 2020 17:49:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582739416; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PVJimd7XWYvK/2lEtQ/c78Pe+KySLIgBIAvJuJi82nE=; b=ASpNK6sxHHDgqhYjsqIDwj7sDeC1Xqxs+EkIUquAoJk9cjwjEshSpne2nlj/RbF30ISVm+ oXomdi4SjLFW/3Ykcm+7I7HHG8J5oxJ1ZCpzZcglhtkpTxEa7SqAcz1F4K8lp0WqIrJbwC xpfbPzDPm7cdATq92M0EAgihnNL5VTk= X-MC-Unique: xgdWhHD5M8uLTEAz1OQ86g-1 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH] hw/i386/intel_iommu: Simplify vtd_find_as_from_bus_num() logic Date: Wed, 26 Feb 2020 18:49:56 +0100 Message-Id: <20200226174956.17018-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Liu Yi L , Yi Sun , Eduardo Habkost , "Michael S. Tsirkin" , qemu-trivial@nongnu.org, Peter Xu , Eric Auger , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson 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" Reorder the if() statement to simplify the function. This avoid bugs like the one fixed by commit a2e1cd41ccf. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/i386/intel_iommu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 6258c58ac9..e720a8939c 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -987,14 +987,17 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, ui= nt32_t level) static VTDBus *vtd_find_as_from_bus_num(IntelIOMMUState *s, uint8_t bus_nu= m) { VTDBus *vtd_bus =3D s->vtd_as_by_bus_num[bus_num]; - if (!vtd_bus) { + GHashTableIter iter; + + if (vtd_bus) { + return vtd_bus; + } + /* * Iterate over the registered buses to find the one which * currently hold this bus number, and update the bus_num * lookup table: */ - GHashTableIter iter; - g_hash_table_iter_init(&iter, s->vtd_as_by_busptr); while (g_hash_table_iter_next(&iter, NULL, (void **)&vtd_bus)) { if (pci_bus_num(vtd_bus->bus) =3D=3D bus_num) { @@ -1002,9 +1005,8 @@ static VTDBus *vtd_find_as_from_bus_num(IntelIOMMUSta= te *s, uint8_t bus_num) return vtd_bus; } } - vtd_bus =3D NULL; - } - return vtd_bus; + + return NULL; } =20 /* Given the @iova, get relevant @slptep. @slpte_level will be the last le= vel --=20 2.21.1