From patchwork Fri Oct 11 12:13:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13832503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0ADD0D0D788 for ; Fri, 11 Oct 2024 12:25:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EcDK0lPOVEdyNaJdF9TiZ8KwI6K8qzQBpiFg524sPS4=; b=w8ultsS7sPxGAD UNFLyekTKgcIf28IOpYDeDMGjp1dI92vA3uyh5dP2Uq8NP/iImGbXcJ6Y2wPQb+r/+fcwlQAUYEUs A7QzWe1pRHfk17s9CR4pMxpqdf1ZZuzxDcwYECQZoVXD927sVbkKzMvAbJEpuar7z89fIDoLpeazP t/lykPnj08rEtRpU0kMz/Oxnj+jZi7yXme0B4jT2UrPN60EW/KhQLAxihTWermHEYpy42xEzIP/p1 NstBd+kGUGg0U05PnbgKw1dQvWJ6SqZAyXpMmdYQ01iKJLN4GADXsyQy9SxKhL0K7iejTfgAwKgDc CLzDxRACmss6KQaBnZgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1szEhd-0000000GHsD-1Wz1; Fri, 11 Oct 2024 12:25:05 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1szEXD-0000000GFoJ-2BSp for linux-rockchip@lists.infradead.org; Fri, 11 Oct 2024 12:14:21 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 1108BA43D7B; Fri, 11 Oct 2024 12:14:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73B74C4CECF; Fri, 11 Oct 2024 12:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728648858; bh=pSHsBhnbjSj04jRr4dxkMJFuwUPFncYPKlMS7obkf/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KgxeAgujYv4rm3bDl1R7Fvbzoc4H5oYIlF+lb9GR4mtydmMCSGzyNNoYaNH1t4hOr scY43kZuCt1LoAfMyEFawxrNnVyWT83E/e6nYQqNM3iZUAfKVMNwQPAtuhDFpyJsdd KwNohLGhz2f8t6+aPTizVrlqGWTm3kFG4lpZyfTh4Hy+sfampwIG5JM2TCqYM/il7R W/gbiaTvbdJpD/uX+JPJ5WuChL86jif2LXZJho9zzgs8grIojVP608RIE3i7/x3EhZ 97Cpq6+1YPClo/2yRnMJPePmA3ps5V5/z8o26AdMVvpLO1ZICRdr6YbHUHt9N+hkdK Vmt0lW3UO7d+Q== From: Damien Le Moal To: Manivannan Sadhasivam , Lorenzo Pieralisi , Kishon Vijay Abraham I , Shawn Lin , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , Heiko Stuebner , linux-pci@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: linux-rockchip@lists.infradead.org, Rick Wertenbroek , Niklas Cassel Subject: [PATCH v4 03/12] PCI: rockchip-ep: Improve rockchip_pcie_ep_unmap_addr() Date: Fri, 11 Oct 2024 21:13:59 +0900 Message-ID: <20241011121408.89890-4-dlemoal@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241011121408.89890-1-dlemoal@kernel.org> References: <20241011121408.89890-1-dlemoal@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241011_051419_677337_6070E6B1 X-CRM114-Status: GOOD ( 11.71 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org From: Damien Le Moal There is no need to loop over all regions to find the memory window used to map an address. We can use rockchip_ob_region() to determine the region index, together with a check that the address passed as argument is the address used to create the mapping. Furthermore, the ob_region_map bitmap should also be checked to ensure that we are not attempting to unmap an address that is not mapped. Signed-off-by: Damien Le Moal --- drivers/pci/controller/pcie-rockchip-ep.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/pci/controller/pcie-rockchip-ep.c b/drivers/pci/controller/pcie-rockchip-ep.c index 5a07084fb7c4..89ebdf3e4737 100644 --- a/drivers/pci/controller/pcie-rockchip-ep.c +++ b/drivers/pci/controller/pcie-rockchip-ep.c @@ -256,13 +256,9 @@ static void rockchip_pcie_ep_unmap_addr(struct pci_epc *epc, u8 fn, u8 vfn, { struct rockchip_pcie_ep *ep = epc_get_drvdata(epc); struct rockchip_pcie *rockchip = &ep->rockchip; - u32 r; - - for (r = 0; r < ep->max_regions; r++) - if (ep->ob_addr[r] == addr) - break; + u32 r = rockchip_ob_region(addr); - if (r == ep->max_regions) + if (addr != ep->ob_addr[r] || !test_bit(r, &ep->ob_region_map)) return; rockchip_pcie_clear_ep_ob_atu(rockchip, r);