Re: [PATCH] PCI/MSI: add iounmap in msix_capability_init()
From: Guenter Roeck
Date: Mon Mar 16 2026 - 13:26:20 EST
Hi,
On Sun, Jan 25, 2026 at 10:44:52PM +0800, Haoxiang Li wrote:
> In msix_capability_init(), if msix_setup_interrupts()
> fails, call iounmap() to release the memory allocated
> by msix_map_region().
>
Really ? AI review provided the following feedback. Looking into the code,
I think it has a point.
Thanks,
Guenter
> Signed-off-by: Haoxiang Li <lihaoxiang@xxxxxxxxxxxxxxxx>
> ---
> drivers/pci/msi/msi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
> index 34d664139f48..e010ecd9f90d 100644
> --- a/drivers/pci/msi/msi.c
> +++ b/drivers/pci/msi/msi.c
> @@ -737,7 +737,7 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
>
> ret = msix_setup_interrupts(dev, entries, nvec, affd);
> if (ret)
> - goto out_disable;
> + goto out_unmap;
Does msix_setup_interrupts() already unmap this region? If it fails,
msix_setup_interrupts() calls pci_free_msi_irqs(), which appears to already
call iounmap(dev->msix_base) and sets dev->msix_base to NULL.
>
> /* Disable INTX */
> pci_intx_for_msi(dev, 0);
> @@ -758,6 +758,8 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
> pcibios_free_irq(dev);
> return 0;
>
> +out_unmap:
> + iounmap(dev->msix_base);
If dev->msix_base was already set to NULL by pci_free_msi_irqs() during the
msix_setup_interrupts() error path, does this result in iounmap(NULL)?
> out_disable:
> dev->msix_enabled = 0;
> pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE, 0);
> --
> 2.25.1
>