From nobody Fri Dec 19 14:42:12 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=pass; 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583426373; cv=none; d=zohomail.com; s=zohoarc; b=JWObw0IPwL+UXHL1sewPjlLkjO3yGNF9Pmn7YheUVyPeAgFRMg11L3ManeaLWl16Evh1ZrqdBU8I7onFq08ykXeParyTThxbYgGx50EIHRomjDIMwYkkun06j6x6jkCM5rau3vAj1qVc9UZ67aLDD0MiDamKrsBjGBljHs1g//E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583426373; h=Content-Type:Content-Transfer-Encoding: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=x0koMjvwGuOCpGMER2fTln7XCO/uLklg3+AuMRzjjUc=; b=jTEVRq9Xuu+1ZOsowhuWPR2OawBRcJTuCTCVeGUgg5TYlulREB2qfgVkhYBCnLO7jmFlxhtJvoRWiaNzEqWQr7uKY1M/RN6PQeXWpZlBcrgX5oJ6/dPu9YfRIYnzcekzrfl35qT9CIJHlQ9wPJya/zxoLrmOJdYxwUxUseTbBjU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583426373277738.6037252866907; Thu, 5 Mar 2020 08:39:33 -0800 (PST) Received: from localhost ([::1]:52590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9tX2-0000v4-7k for importer@patchew.org; Thu, 05 Mar 2020 11:39:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59084) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9tOw-0003H4-Uu for qemu-devel@nongnu.org; Thu, 05 Mar 2020 11:31:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j9tOv-00027G-Ph for qemu-devel@nongnu.org; Thu, 05 Mar 2020 11:31:10 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:38078) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j9tOv-00026v-HK for qemu-devel@nongnu.org; Thu, 05 Mar 2020 11:31:09 -0500 Received: by mail-wr1-x429.google.com with SMTP id t11so7799183wrw.5 for ; Thu, 05 Mar 2020 08:31:09 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id w22sm10310729wmk.34.2020.03.05.08.31.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 08:31:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=x0koMjvwGuOCpGMER2fTln7XCO/uLklg3+AuMRzjjUc=; b=HfP+TOaRbmzoddCCUeVcHhPnJGYncpTcKZ10Un3bvQC/rBuQwAHWlqU5XwTEAPXImg Gm7Ywjuaw9qpf5RgfIsUJRBbU4HQX5/jiZvMl+elTIvcVz+eQbrS+cApGu+ETP71MXnx mU7Bzfns/YjJtw+HyAN1YlojqIpmEglD8HMykLXUhnwYsgWjVCIma+f3M+UJIaGhFG6R mLFUOs+E5bw33RnGBWRLGQ0SUUb2Z3TKhyFA24bm1NDb5W0rEI2h3HWUpP9PUOsqH2xe QDaDrbTpy/y2VcWzAkN2DZ0U25Ymie7h1gdzKCpV7chPZXDzWJVdtKZgQKvvsJnT+lxR igbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x0koMjvwGuOCpGMER2fTln7XCO/uLklg3+AuMRzjjUc=; b=OXNXCT1Td5iB5ooO95N0Ej0UJUIuQPlCyUlZ5SL92JEfKl/xqDSH8i0aYEw5o4+vno rNUFLNwr9c9AZitXSL6zjqU9F2+flC9RYh6oRhIdXAFD6zwa3nja75ELHvgM04XY/FjC XQTOkGJMFUIwvweVIjoEPaRUBHQr7a4LohpH15nRdrGzuMmRovM1yMXQsoZ+Enz3aff0 vgsgBHwwXHUrhG0zF+ekMiiZwgdWOrcxjEmfGCg6MBjH2A3rhspqOhesfrmQyGFmPXqe 2FjoafNlEZq7w60ComD+xRUU4IW0SQ7fHLDC16BROVuIELgnCj+HoSHxyQmCj5Pr7Pai Neog== X-Gm-Message-State: ANhLgQ1jt5fwcvO743T9ex7dYcJIX5q+5HDr5NF6NW6JKXRQBuYxXi/a uKyoojDvU7dxEQj2z3XBWJ2nX4FsRyMe2A== X-Google-Smtp-Source: ADFU+vtKEN049k1wqgfk2M71v5nr12+CTIgJ9F/ruXRIGc4rcIrJ2aYkdiwA0b8RB9yuzq3vGlLV2g== X-Received: by 2002:a5d:4b82:: with SMTP id b2mr11020968wrt.102.1583425868214; Thu, 05 Mar 2020 08:31:08 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 05/37] hw/arm/smmu-common: Simplify smmu_find_smmu_pcibus() logic Date: Thu, 5 Mar 2020 16:30:28 +0000 Message-Id: <20200305163100.22912-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200305163100.22912-1-peter.maydell@linaro.org> References: <20200305163100.22912-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::429 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) From: Philippe Mathieu-Daud=C3=A9 The smmu_find_smmu_pcibus() function was introduced (in commit cac994ef43b) in a code format that could return an incorrect pointer, which was then fixed by the previous commit. We could have avoided this by writing the if() statement differently. Do it now, in case this function is re-used. The code is easier to review (harder to miss bugs). Acked-by: Eric Auger Reviewed-by: Peter Xu Signed-off-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Maydell --- hw/arm/smmu-common.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 67d7b2d0fd9..e13a5f4a7cb 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -290,20 +290,21 @@ inline int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iov= a, IOMMUAccessFlags perm, SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, uint8_t bus_num) { SMMUPciBus *smmu_pci_bus =3D s->smmu_pcibus_by_bus_num[bus_num]; + GHashTableIter iter; =20 - if (!smmu_pci_bus) { - GHashTableIter iter; - - g_hash_table_iter_init(&iter, s->smmu_pcibus_by_busptr); - while (g_hash_table_iter_next(&iter, NULL, (void **)&smmu_pci_bus)= ) { - if (pci_bus_num(smmu_pci_bus->bus) =3D=3D bus_num) { - s->smmu_pcibus_by_bus_num[bus_num] =3D smmu_pci_bus; - return smmu_pci_bus; - } - } - smmu_pci_bus =3D NULL; + if (smmu_pci_bus) { + return smmu_pci_bus; } - return smmu_pci_bus; + + g_hash_table_iter_init(&iter, s->smmu_pcibus_by_busptr); + while (g_hash_table_iter_next(&iter, NULL, (void **)&smmu_pci_bus)) { + if (pci_bus_num(smmu_pci_bus->bus) =3D=3D bus_num) { + s->smmu_pcibus_by_bus_num[bus_num] =3D smmu_pci_bus; + return smmu_pci_bus; + } + } + + return NULL; } =20 static AddressSpace *smmu_find_add_as(PCIBus *bus, void *opaque, int devfn) --=20 2.20.1