[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240819082445.10248-2-brgl@bgdev.pl>
Date: Mon, 19 Aug 2024 10:24:43 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Bjorn Helgaas <bhelgaas@...gle.com>
Cc: linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: [PATCH v2 1/2] PCI: don't rely on of_platform_depopulate() for reused OF-nodes
From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
of_platform_depopulate() doesn't play nice with reused OF nodes - it
ignores the ones that are not marked explicitly as populated and it may
happen that the PCI device goes away before the platform device in which
case the PCI core clears the OF_POPULATED bit. We need to
unconditionally unregister the platform devices for child nodes when
stopping the PCI device.
Fixes: 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
---
drivers/pci/remove.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index 910387e5bdbf..c7092a34a5f6 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/pci.h>
#include <linux/module.h>
+#include <linux/of.h>
#include <linux/of_platform.h>
#include "pci.h"
@@ -16,13 +17,26 @@ static void pci_free_resources(struct pci_dev *dev)
static void pci_stop_dev(struct pci_dev *dev)
{
+ struct platform_device *pdev;
+
pci_pme_active(dev, false);
if (pci_dev_is_added(dev)) {
- of_platform_depopulate(&dev->dev);
device_release_driver(&dev->dev);
pci_proc_detach_device(dev);
pci_remove_sysfs_dev_files(dev);
+
+ if (dev_of_node(&dev->dev)) {
+ for_each_child_of_node_scoped(dev_of_node(&dev->dev),
+ child) {
+ pdev = of_find_device_by_node(child);
+ if (pdev) {
+ of_device_unregister(pdev);
+ of_node_clear_flag(child, OF_POPULATED);
+ }
+ }
+ }
+
of_pci_remove_node(dev);
pci_dev_assign_added(dev, false);
--
2.43.0
Powered by blists - more mailing lists