Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: xilinx-nwl: Simplify code and fix a memory leak

Allocate space for bitmap in struct nwl_msi at probe time instead of
dynamically allocating the memory at runtime.

This simplifies code (especially error handling paths) and avoid some
open-coded arithmetic in allocator arguments.

This also fixes a potential memory leak. The bitmap was never freed. It
is now part of a managed resource.

Link: https://lore.kernel.org/r/5483f10a44b06aad55728576d489adfa16c3be91.1636279388.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Krzysztof Wilczyński <kw@linux.com>

authored by

Christophe JAILLET and committed by
Lorenzo Pieralisi
61f0aa4d fa55b7dc

+7 -23
+7 -23
drivers/pci/controller/pcie-xilinx-nwl.c
··· 146 146 147 147 struct nwl_msi { /* MSI information */ 148 148 struct irq_domain *msi_domain; 149 - unsigned long *bitmap; 149 + DECLARE_BITMAP(bitmap, INT_PCI_MSI_NR); 150 150 struct irq_domain *dev_domain; 151 151 struct mutex lock; /* protect bitmap variable */ 152 152 int irq_msi0; ··· 335 335 336 336 static void nwl_pcie_handle_msi_irq(struct nwl_pcie *pcie, u32 status_reg) 337 337 { 338 - struct nwl_msi *msi; 338 + struct nwl_msi *msi = &pcie->msi; 339 339 unsigned long status; 340 340 u32 bit; 341 - 342 - msi = &pcie->msi; 343 341 344 342 while ((status = nwl_bridge_readl(pcie, status_reg)) != 0) { 345 343 for_each_set_bit(bit, &status, 32) { ··· 558 560 struct nwl_msi *msi = &pcie->msi; 559 561 unsigned long base; 560 562 int ret; 561 - int size = BITS_TO_LONGS(INT_PCI_MSI_NR) * sizeof(long); 562 563 563 564 mutex_init(&msi->lock); 564 565 565 - msi->bitmap = kzalloc(size, GFP_KERNEL); 566 - if (!msi->bitmap) 567 - return -ENOMEM; 568 - 569 566 /* Get msi_1 IRQ number */ 570 567 msi->irq_msi1 = platform_get_irq_byname(pdev, "msi1"); 571 - if (msi->irq_msi1 < 0) { 572 - ret = -EINVAL; 573 - goto err; 574 - } 568 + if (msi->irq_msi1 < 0) 569 + return -EINVAL; 575 570 576 571 irq_set_chained_handler_and_data(msi->irq_msi1, 577 572 nwl_pcie_msi_handler_high, pcie); 578 573 579 574 /* Get msi_0 IRQ number */ 580 575 msi->irq_msi0 = platform_get_irq_byname(pdev, "msi0"); 581 - if (msi->irq_msi0 < 0) { 582 - ret = -EINVAL; 583 - goto err; 584 - } 576 + if (msi->irq_msi0 < 0) 577 + return -EINVAL; 585 578 586 579 irq_set_chained_handler_and_data(msi->irq_msi0, 587 580 nwl_pcie_msi_handler_low, pcie); ··· 581 592 ret = nwl_bridge_readl(pcie, I_MSII_CAPABILITIES) & MSII_PRESENT; 582 593 if (!ret) { 583 594 dev_err(dev, "MSI not present\n"); 584 - ret = -EIO; 585 - goto err; 595 + return -EIO; 586 596 } 587 597 588 598 /* Enable MSII */ ··· 620 632 nwl_bridge_writel(pcie, MSGF_MSI_SR_LO_MASK, MSGF_MSI_MASK_LO); 621 633 622 634 return 0; 623 - err: 624 - kfree(msi->bitmap); 625 - msi->bitmap = NULL; 626 - return ret; 627 635 } 628 636 629 637 static int nwl_pcie_bridge_init(struct nwl_pcie *pcie)