Skip to content

Commit bf73258

Browse files
tititiou36bjorn-helgaas
authored andcommitted
PCI: brcmstb: Declare 'used' as bitmap, not unsigned long
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>
1 parent fa55b7d commit bf73258

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

drivers/pci/controller/pcie-brcmstb.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ struct brcm_msi {
266266
struct mutex lock; /* guards the alloc/free operations */
267267
u64 target_addr;
268268
int irq;
269-
/* used indicates which MSI interrupts have been alloc'd */
270-
unsigned long used;
269+
DECLARE_BITMAP(used, BRCM_INT_PCI_MSI_NR);
271270
bool legacy;
272271
/* Some chips have MSIs in bits [31..24] of a shared register. */
273272
int legacy_shift;
@@ -534,7 +533,7 @@ static int brcm_msi_alloc(struct brcm_msi *msi)
534533
int hwirq;
535534

536535
mutex_lock(&msi->lock);
537-
hwirq = bitmap_find_free_region(&msi->used, msi->nr, 0);
536+
hwirq = bitmap_find_free_region(msi->used, msi->nr, 0);
538537
mutex_unlock(&msi->lock);
539538

540539
return hwirq;
@@ -543,7 +542,7 @@ static int brcm_msi_alloc(struct brcm_msi *msi)
543542
static void brcm_msi_free(struct brcm_msi *msi, unsigned long hwirq)
544543
{
545544
mutex_lock(&msi->lock);
546-
bitmap_release_region(&msi->used, hwirq, 0);
545+
bitmap_release_region(msi->used, hwirq, 0);
547546
mutex_unlock(&msi->lock);
548547
}
549548

@@ -661,6 +660,12 @@ static int brcm_pcie_enable_msi(struct brcm_pcie *pcie)
661660
msi->irq = irq;
662661
msi->legacy = pcie->hw_rev < BRCM_PCIE_HW_REV_33;
663662

663+
/*
664+
* Sanity check to make sure that the 'used' bitmap in struct brcm_msi
665+
* is large enough.
666+
*/
667+
BUILD_BUG_ON(BRCM_INT_PCI_MSI_LEGACY_NR > BRCM_INT_PCI_MSI_NR);
668+
664669
if (msi->legacy) {
665670
msi->intr_base = msi->base + PCIE_INTR2_CPU_BASE;
666671
msi->nr = BRCM_INT_PCI_MSI_LEGACY_NR;

0 commit comments

Comments
 (0)