]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
PCI: brcmstb: Declare 'used' as bitmap, not unsigned long
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 7 Nov 2021 08:32:58 +0000 (09:32 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 12 Jan 2022 19:45:36 +0000 (13:45 -0600)
The 'used' field of 'struct brcm_msi' is used as a bitmap.  Declare it with
DECLARE_BITMAP() and adjust users accordingly.

This fixes a harmless Coverity warning about array vs singleton usage.

This bitmap can be used for either legacy or MSI interrupts, which require
a size of BRCM_INT_PCI_MSI_LEGACY_NR or BRCM_INT_PCI_MSI_NR respectively.
Add a BUILD_BUG_ON() to ensure it is large enough.

Suggested-by: Krzysztof Wilczynski <kw@linux.com>
Addresses-Coverity: "Out-of-bounds access (ARRAY_VS_SINGLETON)"
Link: https://lore.kernel.org/r/e6d9da2112aab2939d1507b90962d07bfd735b4c.1636273671.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
drivers/pci/controller/pcie-brcmstb.c

index 1fc7bd49a7ad344029ef882d3fdc889397265f48..b016e43628bb30370d658314f0a552875b5e4482 100644 (file)
@@ -266,8 +266,7 @@ 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;
+       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 +533,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 +542,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 +660,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;