From patchwork Sun Nov 7 08:32:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12606757 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FF60C433F5 for ; Sun, 7 Nov 2021 08:34:52 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D77CA61352 for ; Sun, 7 Nov 2021 08:34:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D77CA61352 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=wanadoo.fr Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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: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:In-Reply-To:References: List-Owner; bh=0WUw9NhfgF2HhSVrsDjVjfLI2rDHHJdvBHNZPutglg8=; b=4po0zAR1yRLwwo 3b5Qdzjuk4+Hk5sNCHj8vfsxiq9jbEsrAt9UfjAprkz/GWLeITLCxVz+zX6DKqSYeuh5h8IhrBw/u t8rPh+psvYF/G/Nvuo0/m+eGWyQM1e8xxVp13ODMOo6zJEIZmIUz4BbZYyeBP6kGnk/PgfBnpOpAj gp1vEAZpmcQu4kFrYhFtr2dcfiAt496RxpY4dgEeCUcW79BIgpSFyHdpI5cIKgYYVWel1ZfpPOo03 sX/r1Qd3qkmvIk/XQJg2ePNenzpLpZt/U8rCouG3rEEnb/ugLKVPsKce9OmWs+shfzi4iKPQw/sOQ PJfThJcX2uoh4XOmCLQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mjdc8-00E9VA-7A; Sun, 07 Nov 2021 08:33:20 +0000 Received: from smtp04.smtpout.orange.fr ([80.12.242.126] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mjdc3-00E9Tv-VR for linux-arm-kernel@lists.infradead.org; Sun, 07 Nov 2021 08:33:17 +0000 Received: from pop-os.home ([86.243.171.122]) by smtp.orange.fr with ESMTPA id jdbymh7FXsoWhjdbym9Yyc; Sun, 07 Nov 2021 09:33:12 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sun, 07 Nov 2021 09:33:12 +0100 X-ME-IP: 86.243.171.122 From: Christophe JAILLET To: nsaenz@kernel.org, jim2101024@gmail.com, f.fainelli@gmail.com, bcm-kernel-feedback-list@broadcom.com, lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, bhelgaas@google.com Cc: linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] PCI: brcmstb: Declare a bitmap as a bitmap, not as a plain 'unsigned long' Date: Sun, 7 Nov 2021 09:32:58 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211107_013316_187254_1A08CADC X-CRM114-Status: GOOD ( 15.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The 'used' field of 'struct brcm_msi' is used as a bitmap. So it should be declared as so (i.e. unsigned long *). This fixes an harmless Coverity warning about array vs singleton usage. This bitmap can be BRCM_INT_PCI_MSI_LEGACY_NR or BRCM_INT_PCI_MSI_NR long. So, while at it, document it, should it help someone in the future. Addresses-Coverity: "Out-of-bounds access (ARRAY_VS_SINGLETON)" Suggested-by: Krzysztof Wilczynski Signed-off-by: Christophe JAILLET Reviewed-by: Florian Fainelli --- The BUILD_BUG_ON is surely a bit to much of paranoia :) I'm also not really pleased about the layout of the DECLARE_BITMAP. This looks odd, but I couldn't find something nicer :( --- drivers/pci/controller/pcie-brcmstb.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 1fc7bd49a7ad..15d394ac7478 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -266,8 +266,9 @@ struct brcm_msi { struct mutex lock; /* guards the alloc/free operations */ u64 target_addr; int irq; - /* used indicates which MSI interrupts have been alloc'd */ - unsigned long used; + /* Used indicates which MSI interrupts have been alloc'd. 'nr' bellow is + the real size of the bitmap. It depends on the chip. */ + DECLARE_BITMAP (used, BRCM_INT_PCI_MSI_NR); bool legacy; /* Some chips have MSIs in bits [31..24] of a shared register. */ int legacy_shift; @@ -534,7 +535,7 @@ static int brcm_msi_alloc(struct brcm_msi *msi) int hwirq; mutex_lock(&msi->lock); - hwirq = bitmap_find_free_region(&msi->used, msi->nr, 0); + hwirq = bitmap_find_free_region(msi->used, msi->nr, 0); mutex_unlock(&msi->lock); return hwirq; @@ -543,7 +544,7 @@ static int brcm_msi_alloc(struct brcm_msi *msi) static void brcm_msi_free(struct brcm_msi *msi, unsigned long hwirq) { mutex_lock(&msi->lock); - bitmap_release_region(&msi->used, hwirq, 0); + bitmap_release_region(msi->used, hwirq, 0); mutex_unlock(&msi->lock); } @@ -661,6 +662,12 @@ static int brcm_pcie_enable_msi(struct brcm_pcie *pcie) msi->irq = irq; msi->legacy = pcie->hw_rev < BRCM_PCIE_HW_REV_33; + /* + * Sanity check to make sure that the 'used' bitmap in struct brcm_msi + * is large enough. + */ + BUILD_BUG_ON(BRCM_INT_PCI_MSI_LEGACY_NR > BRCM_INT_PCI_MSI_NR); + if (msi->legacy) { msi->intr_base = msi->base + PCIE_INTR2_CPU_BASE; msi->nr = BRCM_INT_PCI_MSI_LEGACY_NR;