public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI/MSI: add iounmap in msix_capability_init()
@ 2026-01-25 14:44 Haoxiang Li
  2026-02-06 22:37 ` Bjorn Helgaas
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Haoxiang Li @ 2026-01-25 14:44 UTC (permalink / raw)
  To: bhelgaas, tglx, jgross, hans.zhang, himanshu.madhani, roger.pau,
	chrisl
  Cc: linux-pci, linux-kernel, Haoxiang Li

In msix_capability_init(), if msix_setup_interrupts()
fails, call iounmap() to release the memory allocated
by msix_map_region().

Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
 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;
 
 	/* 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);
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] PCI/MSI: add iounmap in msix_capability_init()
  2026-01-25 14:44 [PATCH] PCI/MSI: add iounmap in msix_capability_init() Haoxiang Li
@ 2026-02-06 22:37 ` Bjorn Helgaas
  2026-03-10 14:38 ` Guenter Roeck
  2026-03-16 17:22 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2026-02-06 22:37 UTC (permalink / raw)
  To: Haoxiang Li
  Cc: bhelgaas, tglx, jgross, hans.zhang, himanshu.madhani, roger.pau,
	chrisl, linux-pci, linux-kernel

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().
> 
> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
> ---
>  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;
>  
>  	/* 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);

Maybe Thomas has already applied this, and if not, he should chime in.

Personally, I would prefer if msix_map_region() were renamed and made
to return the phys_addr instead of returning the ioremapped address.
That way both the ioremap() and the iounmap() on failure would be in
msix_capability_init() so it's easier to review.

>  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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PCI/MSI: add iounmap in msix_capability_init()
  2026-01-25 14:44 [PATCH] PCI/MSI: add iounmap in msix_capability_init() Haoxiang Li
  2026-02-06 22:37 ` Bjorn Helgaas
@ 2026-03-10 14:38 ` Guenter Roeck
  2026-03-16 17:22 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2026-03-10 14:38 UTC (permalink / raw)
  To: Haoxiang Li
  Cc: bhelgaas, tglx, jgross, hans.zhang, himanshu.madhani, roger.pau,
	chrisl, linux-pci, linux-kernel

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().
> 

AI review has the following feedback:

  In __msix_setup_interrupts(), `dev` is declared with the
  `__free(free_msi_irqs)` cleanup attribute. If an error is returned,
  pci_free_msi_irqs() is automatically called.

  pci_free_msi_irqs() already unmaps dev->msix_base and sets it to NULL:

  void pci_free_msi_irqs(struct pci_dev *dev)
  {
	...
	if (dev->msix_base) {
		iounmap(dev->msix_base);
		dev->msix_base = NULL;
	}
  }

  So if msix_setup_interrupts() fails, dev->msix_base has already been
  unmapped and is NULL by the time we reach this new error path.
  Is this extra iounmap() necessary?

I checked the code, and agree.

Thanks,
Guenter

> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
> ---
>  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;
>  
>  	/* 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);
>  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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PCI/MSI: add iounmap in msix_capability_init()
  2026-01-25 14:44 [PATCH] PCI/MSI: add iounmap in msix_capability_init() Haoxiang Li
  2026-02-06 22:37 ` Bjorn Helgaas
  2026-03-10 14:38 ` Guenter Roeck
@ 2026-03-16 17:22 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2026-03-16 17:22 UTC (permalink / raw)
  To: Haoxiang Li
  Cc: bhelgaas, tglx, jgross, hans.zhang, himanshu.madhani, roger.pau,
	chrisl, linux-pci, linux-kernel

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@isrc.iscas.ac.cn>
> ---
>  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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-16 17:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-25 14:44 [PATCH] PCI/MSI: add iounmap in msix_capability_init() Haoxiang Li
2026-02-06 22:37 ` Bjorn Helgaas
2026-03-10 14:38 ` Guenter Roeck
2026-03-16 17:22 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox