Skip to content

Commit

Permalink
PCI/pwrctl: Remove pwrctl device without iterating over all children …
Browse files Browse the repository at this point in the history
…of pwrctl parent

There is no need to iterate over all children of the pwrctl device parent
to remove the pwrctl device. Since the pwrctl device associated with the
PCI device can be found using of_find_device_by_node() API, use it directly
instead.

Any pwrctl devices lying around without getting associated with the PCI
devices will be removed once their parent device gets removed.

Link: https://lore.kernel.org/r/20241025-pci-pwrctl-rework-v2-5-568756156cbe@linaro.org
Tested-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tested-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
[bhelgaas: commit log]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
  • Loading branch information
Manivannan Sadhasivam authored and Krzysztof Wilczyński committed Nov 21, 2024
1 parent b458ff7 commit 681725a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions drivers/pci/remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@ static void pci_free_resources(struct pci_dev *dev)
}
}

static int pci_pwrctl_unregister(struct device *dev, void *data)
static void pci_pwrctl_unregister(struct device *dev)
{
struct device_node *pci_node = data, *plat_node = dev_of_node(dev);
struct platform_device *pdev;

if (dev_is_platform(dev) && plat_node && plat_node == pci_node) {
of_device_unregister(to_platform_device(dev));
of_node_clear_flag(plat_node, OF_POPULATED);
}
pdev = of_find_device_by_node(dev_of_node(dev));
if (!pdev)
return;

return 0;
of_device_unregister(pdev);
of_node_clear_flag(dev_of_node(dev), OF_POPULATED);
}

static void pci_stop_dev(struct pci_dev *dev)
{
pci_pme_active(dev, false);

if (pci_dev_is_added(dev)) {
device_for_each_child(dev->dev.parent, dev_of_node(&dev->dev),
pci_pwrctl_unregister);
pci_pwrctl_unregister(&dev->dev);
device_release_driver(&dev->dev);
pci_proc_detach_device(dev);
pci_remove_sysfs_dev_files(dev);
Expand Down

0 comments on commit 681725a

Please sign in to comment.