Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Philipp Stanner <phasta@mailbox.org>
To: Shawn Lin <shawn.lin@rock-chips.com>,
	Bjorn Helgaas <bhelgaas@google.com>
Cc: Nirmal Patel <nirmal.patel@linux.intel.com>,
	Jonathan Derrick <jonathan.derrick@linux.dev>,
	Kurt Schwemmer <kurt.schwemmer@microsemi.com>,
	 Logan Gunthorpe <logang@deltatee.com>,
	Philipp Stanner <phasta@kernel.org>,
	linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 3/7] PCI/MSI: Introduce __pcim_enable_msi_range()
Date: Tue, 12 May 2026 15:22:44 +0200	[thread overview]
Message-ID: <c7894396253909ee7db94ca18eaef4420f7f9595.camel@mailbox.org> (raw)
In-Reply-To: <1777017460-243543-4-git-send-email-shawn.lin@rock-chips.com>

On Fri, 2026-04-24 at 15:57 +0800, Shawn Lin wrote:
> Introduce __pcim_enable_msi_range(), a devres-managed variant of
> __pci_enable_msi_range(). The new function provides automatic cleanup
> of MSI interrupts via devres, reducing the risk of resource leaks and
> simplifying driver error handling.
> 
> This function is particularly useful for drivers that already use
> pcim_enable_device() and want consistent devres management for all
> PCI resources, including MSI interrupts.
> 
> Drivers can replace calls to __pci_enable_msi_range() with
> __pcim_enable_msi_range() to benefit from automatic cleanup without
> changing their core logic.
> 
> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>

Reviewed-by: Philipp Stanner <phasta@kernel.org>

> ---
> 
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
> 
>  drivers/pci/msi/msi.c | 20 ++++++++++++++++++++
>  drivers/pci/msi/msi.h |  1 +
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
> index 5c196c2..0aaff57 100644
> --- a/drivers/pci/msi/msi.c
> +++ b/drivers/pci/msi/msi.c
> @@ -499,6 +499,26 @@ int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
>  	return pci_msi_range_init(dev, minvec, maxvec, nvec, affd);
>  }
>  
> +int __pcim_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
> +			    struct irq_affinity *affd)
> +{
> +	int nvec, rc;
> +
> +	nvec = pci_msi_range_alloc(dev, minvec, maxvec);
> +	if (nvec < 0)
> +		return nvec;
> +
> +	rc = msi_setup_device_data(&dev->dev);
> +	if (rc)
> +		return rc;
> +
> +	rc = devm_add_action(&dev->dev, pcim_msi_release, dev);

OK I guess. But pcim_msi_release also sets the is_msi_managed boolean,
which I think will not be needed anymore long-term? If you agree, I'd
add a TODO for removing that boolean at an appropriate place and patch,
too.


P.

> +	if (rc)
> +		return rc;
> +
> +	return pci_msi_range_init(dev, minvec, maxvec, nvec, affd);
> +}
> +
>  /**
>   * pci_msi_vec_count - Return the number of MSI vectors a device can send
>   * @dev: device to report about
> diff --git a/drivers/pci/msi/msi.h b/drivers/pci/msi/msi.h
> index 0b420b3..81c6b099 100644
> --- a/drivers/pci/msi/msi.h
> +++ b/drivers/pci/msi/msi.h
> @@ -94,6 +94,7 @@ void pci_msi_shutdown(struct pci_dev *dev);
>  void pci_msix_shutdown(struct pci_dev *dev);
>  void pci_free_msi_irqs(struct pci_dev *dev);
>  int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec, struct irq_affinity *affd);
> +int __pcim_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec, struct irq_affinity *affd);
>  int __pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int minvec,
>  			    int maxvec,  struct irq_affinity *affd, int flags);
>  void __pci_restore_msi_state(struct pci_dev *dev);


  reply	other threads:[~2026-05-12 13:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-24  7:57 [PATCH v4 0/7] Add Devres managed IRQ vectors allocation Shawn Lin
2026-04-24  7:57 ` [PATCH v4 1/7] PCI/MSI: Split __pci_enable_msi_range() for reuse Shawn Lin
2026-05-12 13:08   ` Philipp Stanner
2026-05-12 13:09     ` Philipp Stanner
2026-04-24  7:57 ` [PATCH v4 2/7] PCI/MSI: Split __pci_enable_msix_range() " Shawn Lin
2026-05-12 13:20   ` Philipp Stanner
2026-04-24  7:57 ` [PATCH v4 3/7] PCI/MSI: Introduce __pcim_enable_msi_range() Shawn Lin
2026-05-12 13:22   ` Philipp Stanner [this message]
2026-04-24  7:57 ` [PATCH v4 4/7] PCI/MSI: Introduce __pcim_enable_msix_range() Shawn Lin
2026-05-12 13:26   ` Philipp Stanner
2026-04-24  7:57 ` [PATCH v4 5/7] PCI/MSI: Add Devres managed IRQ vectors allocation Shawn Lin
2026-05-12 13:28   ` Philipp Stanner
2026-04-24  7:57 ` [PATCH v4 6/7] PCI: switchtec: Replace pci_alloc_irq_vectors() with pcim_alloc_irq_vectors() Shawn Lin
2026-04-24  7:57 ` [PATCH v4 7/7] PCI: vmd: " Shawn Lin
2026-05-12 12:57   ` Manivannan Sadhasivam
2026-04-24 11:48 ` [PATCH v4 0/7] Add Devres managed IRQ vectors allocation Philipp Stanner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c7894396253909ee7db94ca18eaef4420f7f9595.camel@mailbox.org \
    --to=phasta@mailbox.org \
    --cc=bhelgaas@google.com \
    --cc=jonathan.derrick@linux.dev \
    --cc=kurt.schwemmer@microsemi.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=nirmal.patel@linux.intel.com \
    --cc=phasta@kernel.org \
    --cc=shawn.lin@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox