Skip to content

Commit f748a07

Browse files
Philipp Stannerbjorn-helgaas
authored andcommitted
PCI: Remove legacy pcim_release()
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 PCI devres implementation. Replace pcim_release() with pcim_disable_device(). Remove the now unused function get_pci_dr(). Remove the struct pci_devres from pci.h. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Philipp Stanner <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 25216af commit f748a07

File tree

2 files changed

+25
-44
lines changed

2 files changed

+25
-44
lines changed

drivers/pci/devres.c

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -477,48 +477,45 @@ int pcim_intx(struct pci_dev *pdev, int enable)
477477
return 0;
478478
}
479479

480-
static void pcim_release(struct device *gendev, void *res)
480+
static void pcim_disable_device(void *pdev_raw)
481481
{
482-
struct pci_dev *dev = to_pci_dev(gendev);
483-
484-
if (pci_is_enabled(dev) && !dev->pinned)
485-
pci_disable_device(dev);
486-
}
487-
488-
static struct pci_devres *get_pci_dr(struct pci_dev *pdev)
489-
{
490-
struct pci_devres *dr, *new_dr;
491-
492-
dr = devres_find(&pdev->dev, pcim_release, NULL, NULL);
493-
if (dr)
494-
return dr;
482+
struct pci_dev *pdev = pdev_raw;
495483

496-
new_dr = devres_alloc(pcim_release, sizeof(*new_dr), GFP_KERNEL);
497-
if (!new_dr)
498-
return NULL;
499-
return devres_get(&pdev->dev, new_dr, NULL, NULL);
484+
if (!pdev->pinned)
485+
pci_disable_device(pdev);
500486
}
501487

502488
/**
503489
* pcim_enable_device - Managed pci_enable_device()
504490
* @pdev: PCI device to be initialized
505491
*
506-
* Managed pci_enable_device().
492+
* Returns: 0 on success, negative error code on failure.
493+
*
494+
* Managed pci_enable_device(). Device will automatically be disabled on
495+
* driver detach.
507496
*/
508497
int pcim_enable_device(struct pci_dev *pdev)
509498
{
510-
struct pci_devres *dr;
511-
int rc;
499+
int ret;
512500

513-
dr = get_pci_dr(pdev);
514-
if (unlikely(!dr))
515-
return -ENOMEM;
501+
ret = devm_add_action(&pdev->dev, pcim_disable_device, pdev);
502+
if (ret != 0)
503+
return ret;
516504

517-
rc = pci_enable_device(pdev);
518-
if (!rc)
519-
pdev->is_managed = 1;
505+
/*
506+
* We prefer removing the action in case of an error over
507+
* devm_add_action_or_reset() because the latter could theoretically be
508+
* disturbed by users having pinned the device too soon.
509+
*/
510+
ret = pci_enable_device(pdev);
511+
if (ret != 0) {
512+
devm_remove_action(&pdev->dev, pcim_disable_device, pdev);
513+
return ret;
514+
}
520515

521-
return rc;
516+
pdev->is_managed = true;
517+
518+
return ret;
522519
}
523520
EXPORT_SYMBOL(pcim_enable_device);
524521

drivers/pci/pci.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -810,22 +810,6 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
810810
}
811811
#endif
812812

813-
/*
814-
* Managed PCI resources. This manages device on/off, INTx/MSI/MSI-X
815-
* on/off and BAR regions. pci_dev itself records MSI/MSI-X status, so
816-
* there's no need to track it separately. pci_devres is initialized
817-
* when a device is enabled using managed PCI device enable interface.
818-
*
819-
* TODO: Struct pci_devres only needs to be here because they're used in pci.c.
820-
* Port or move these functions to devres.c and then remove them from here.
821-
*/
822-
struct pci_devres {
823-
/*
824-
* TODO:
825-
* This struct is now surplus. Remove it by refactoring pci/devres.c
826-
*/
827-
};
828-
829813
int pcim_intx(struct pci_dev *dev, int enable);
830814

831815
int pcim_request_region(struct pci_dev *pdev, int bar, const char *name);

0 commit comments

Comments
 (0)