From: Philipp Stanner <pstanner@redhat.com>
To: Jonathan Corbet <corbet@lwn.net>,
Hans de Goede <hdegoede@redhat.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Bjorn Helgaas <bhelgaas@google.com>,
Philipp Stanner <pstanner@redhat.com>,
Sam Ravnborg <sam@ravnborg.org>,
dakr@redhat.com
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org
Subject: [PATCH v2 09/10] PCI: remove legacy pcim_release()
Date: Tue, 23 Jan 2024 10:43:06 +0100 [thread overview]
Message-ID: <20240123094317.15958-10-pstanner@redhat.com> (raw)
In-Reply-To: <20240123094317.15958-1-pstanner@redhat.com>
Thanks to preceding cleanup steps, pcim_release() is now not needed
anymore and can be replaced by pcim_disable_device(), which is the exact
counterpart to pcim_enable_device().
This permits removing further parts of the old devres API.
Replace pcim_release() with pcim_disable_device().
Remove the now surplus function get_pci_dr().
Signed-off-by: Philipp Stanner <pstanner@redhat.com>
---
drivers/pci/devres.c | 49 +++++++++++++++++++-------------------------
1 file changed, 21 insertions(+), 28 deletions(-)
diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index 4314d0863282..f368181c6c92 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -463,48 +463,41 @@ int pcim_intx(struct pci_dev *pdev, int enable)
return 0;
}
-static void pcim_release(struct device *gendev, void *res)
+static void pcim_disable_device(void *pdev_raw)
{
- struct pci_dev *dev = to_pci_dev(gendev);
-
- if (!dev->pinned)
- pci_disable_device(dev);
-}
-
-static struct pci_devres *get_pci_dr(struct pci_dev *pdev)
-{
- struct pci_devres *dr, *new_dr;
-
- dr = devres_find(&pdev->dev, pcim_release, NULL, NULL);
- if (dr)
- return dr;
+ struct pci_dev *pdev = pdev_raw;
- new_dr = devres_alloc(pcim_release, sizeof(*new_dr), GFP_KERNEL);
- if (!new_dr)
- return NULL;
- return devres_get(&pdev->dev, new_dr, NULL, NULL);
+ if (!pdev->pinned)
+ pci_disable_device(pdev);
}
/**
* pcim_enable_device - Managed pci_enable_device()
* @pdev: PCI device to be initialized
*
- * Managed pci_enable_device().
+ * Returns: 0 on success, negative error code on failure.
+ *
+ * Managed pci_enable_device(). Device will automatically be disabled on
+ * driver detach.
*/
int pcim_enable_device(struct pci_dev *pdev)
{
- struct pci_devres *dr;
- int rc;
+ int ret;
- dr = get_pci_dr(pdev);
- if (unlikely(!dr))
- return -ENOMEM;
+ ret = devm_add_action(&pdev->dev, pcim_disable_device, pdev);
+ if (ret != 0)
+ return ret;
- rc = pci_enable_device(pdev);
- if (!rc)
- pdev->is_managed = 1;
+ /*
+ * We prefer removing the action in case of an error over
+ * devm_add_action_or_reset() because the later could theoretically be
+ * disturbed by users having pinned the device too soon.
+ */
+ ret = pci_enable_device(pdev);
+ if (ret != 0)
+ devm_remove_action(&pdev->dev, pcim_disable_device, pdev);
- return rc;
+ return ret;
}
EXPORT_SYMBOL(pcim_enable_device);
--
2.43.0
next prev parent reply other threads:[~2024-01-23 9:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 9:42 [PATCH v2 00/10] Make PCI's devres API more consistent Philipp Stanner
2024-01-23 9:42 ` [PATCH v2 01/10] PCI: add new set of devres functions Philipp Stanner
2024-01-23 9:42 ` [PATCH v2 02/10] PCI: deprecate iomap-table functions Philipp Stanner
2024-01-23 9:43 ` [PATCH v2 03/10] PCI: warn users about complicated devres nature Philipp Stanner
2024-01-23 9:43 ` [PATCH v2 04/10] PCI: make devres region requests consistent Philipp Stanner
2024-01-23 9:43 ` [PATCH v2 05/10] PCI: move dev-enabled status bit to struct pci_dev Philipp Stanner
2024-01-23 9:43 ` [PATCH v2 06/10] PCI: move pinned " Philipp Stanner
2024-01-23 9:43 ` [PATCH v2 07/10] PCI: give pcim_set_mwi() its own devres callback Philipp Stanner
2024-01-23 9:43 ` [PATCH v2 08/10] PCI: give pci(m)_intx " Philipp Stanner
2024-01-23 9:43 ` Philipp Stanner [this message]
2024-01-23 9:43 ` [PATCH v2 10/10] drm/vboxvideo: fix mapping leaks Philipp Stanner
2024-01-29 11:15 ` Hans de Goede
2024-01-29 13:12 ` Philipp Stanner
2024-01-23 10:23 ` [PATCH v2 00/10] Make PCI's devres API more consistent 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=20240123094317.15958-10-pstanner@redhat.com \
--to=pstanner@redhat.com \
--cc=airlied@gmail.com \
--cc=bhelgaas@google.com \
--cc=corbet@lwn.net \
--cc=dakr@redhat.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=hdegoede@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=sam@ravnborg.org \
--cc=tzimmermann@suse.de \
/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
all inboxes | Powered by JetHome®