* [PATCH v2 1/3] PCI: Deprecate public devres reversal functions
2026-12-03 12:53 [PATCH v2 0/3] PCI: Improve devres documentation Philipp Stanner
@ 2026-12-03 12:53 ` Philipp Stanner
2026-12-03 13:11 ` sashiko-bot
2026-12-03 12:53 ` [PATCH v2 2/3] PCI: Better document pcim_enable_device() Philipp Stanner
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Philipp Stanner @ 2026-12-03 12:53 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, Philipp Stanner
The PCI devres API has become a bit inconsistent. Devres is intended to
fully manage the device resources automatically, i.e., they get released
on driver unbind.
However, APIs were added to PCI devres that allow to revert another's
actions. For example, pcim_iomap() creates an automatically released
mapping, and yet pcim_iounmap() exists to *manually* release it.
This has confused users in the past. Some ended up freeing resources
with said interfaces manually in their remove() implementation, despite
the entire point being that exactly this is done automatically by
devres.
Nevertheless, sometimes users want or need manual resource management,
for example in suspend() and resume() paths. In these cases, they should
fully manage their resources manually.
Mark all manual release functions as deprecated and tell users what they
should do instead.
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
drivers/pci/devres.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index f075e7881c3a..48451581516a 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -522,8 +522,7 @@ static void pcim_remove_bar_from_legacy_table(struct pci_dev *pdev, int bar)
*
* Returns: __iomem pointer on success, NULL on failure.
*
- * Managed pci_iomap(). Map is automatically unmapped on driver detach. If
- * desired, unmap manually only with pcim_iounmap().
+ * Managed pci_iomap(). Map is automatically unmapped on driver detach.
*
* This SHOULD only be used once per BAR.
*
@@ -565,12 +564,16 @@ void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen)
EXPORT_SYMBOL(pcim_iomap);
/**
- * pcim_iounmap - Managed pci_iounmap()
+ * pcim_iounmap - Managed pci_iounmap() (DEPRECATED)
* @pdev: PCI device to iounmap for
* @addr: Address to unmap
*
* Managed pci_iounmap(). @addr must have been mapped using a pcim_* mapping
* function.
+ *
+ * This function is deprecated (at least for external users). If you're ever in
+ * a position where it seems useful, you should manage your IO-mappings fully
+ * manually, e.g., with pci_iomap().
*/
void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr)
{
@@ -640,12 +643,16 @@ void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,
EXPORT_SYMBOL(pcim_iomap_region);
/**
- * pcim_iounmap_region - Unmap and release a PCI BAR
+ * pcim_iounmap_region - Unmap and release a PCI BAR (DEPRECATED)
* @pdev: PCI device to operate on
* @bar: Index of BAR to unmap and release
*
* Unmap a BAR and release its region manually. Only pass BARs that were
* previously mapped by pcim_iomap_region().
+ *
+ * This function is deprecated (at least for external users). If you're ever in
+ * a position where it seems useful, you should manage your regions fully
+ * manually with unmanaged pci_ interfaces.
*/
void pcim_iounmap_region(struct pci_dev *pdev, int bar)
{
@@ -825,8 +832,7 @@ EXPORT_SYMBOL(pcim_request_all_regions);
* Creates a new IO-Mapping within the specified @bar, ranging from @offset to
* @offset + @len.
*
- * The mapping will automatically get unmapped on driver detach. If desired,
- * release manually only with pcim_iounmap().
+ * The mapping will automatically get unmapped on driver detach.
*/
void __iomem *pcim_iomap_range(struct pci_dev *pdev, int bar,
unsigned long offset, unsigned long len)
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 2/3] PCI: Better document pcim_enable_device()
2026-12-03 12:53 [PATCH v2 0/3] PCI: Improve devres documentation Philipp Stanner
2026-12-03 12:53 ` [PATCH v2 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
@ 2026-12-03 12:53 ` Philipp Stanner
2026-12-03 12:53 ` [PATCH v2 3/3] PCI: Deprecate pcim_pin_device() Philipp Stanner
2026-12-03 13:11 ` [PATCH v2 0/3] PCI: Improve devres documentation sashiko-bot
3 siblings, 0 replies; 6+ messages in thread
From: Philipp Stanner @ 2026-12-03 12:53 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, Philipp Stanner
pcim_enable_device() enables a PCI device and registers a devres action
which will automatically disable the device on driver detach. Users
should only use it if they want to fully rely on automatic resource
management.
Unfortunately, users often get the function's purpose wrong and
intermingle it with manual calls to pci_disable_device() et al.
Better document what pcim_enable_device() is intended for and when it
should be used.
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
drivers/pci/devres.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index 48451581516a..3e49017bb717 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -365,7 +365,11 @@ static void pcim_disable_device(void *pdev_raw)
* Returns: 0 on success, negative error code on failure.
*
* Managed pci_enable_device(). Device will automatically be disabled on
- * driver detach.
+ * driver detach. You should only use this function in probe(), not in, e.g.,
+ * resume().
+ *
+ * If you need manual enabling and disabling, use pci_enable_device() paired
+ * with pci_disable_device(). Do not mix them with pcim_enable_device().
*/
int pcim_enable_device(struct pci_dev *pdev)
{
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 3/3] PCI: Deprecate pcim_pin_device()
2026-12-03 12:53 [PATCH v2 0/3] PCI: Improve devres documentation Philipp Stanner
2026-12-03 12:53 ` [PATCH v2 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
2026-12-03 12:53 ` [PATCH v2 2/3] PCI: Better document pcim_enable_device() Philipp Stanner
@ 2026-12-03 12:53 ` Philipp Stanner
2026-12-03 13:11 ` [PATCH v2 0/3] PCI: Improve devres documentation sashiko-bot
3 siblings, 0 replies; 6+ messages in thread
From: Philipp Stanner @ 2026-12-03 12:53 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, Philipp Stanner
pcim_pin_device() reverts the action set up by pcim_enable_device(),
namely that the device gets disabled on driver unload.
This makes the PCI devres API inconsistent and confusing. Who does not
want automatic disablement of the device, should not use a function that
sets up automatic disablement. In other words, whoever needs
pcim_pin_device() just should use pci_enable_device() over
pcim_enable_device().
Mark pcim_pin_device() as deprecated.
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
drivers/pci/devres.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index 3e49017bb717..a96fa984b315 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -397,11 +397,15 @@ int pcim_enable_device(struct pci_dev *pdev)
EXPORT_SYMBOL(pcim_enable_device);
/**
- * pcim_pin_device - Pin managed PCI device
+ * pcim_pin_device - Pin managed PCI device (DEPRECATED)
* @pdev: PCI device to pin
*
* Pin managed PCI device @pdev. Pinned device won't be disabled on driver
* detach. @pdev must have been enabled with pcim_enable_device().
+ *
+ * This function is deprecated and should be removed. If you're ever in a
+ * position where it seems useful, you should manage your device enablement
+ * fully manually, with pci_enable_device() and pci_disable_device().
*/
void pcim_pin_device(struct pci_dev *pdev)
{
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread