From: Bjorn Helgaas <helgaas@kernel.org>
To: Bartosz Golaszewski <brgl@bgdev.pl>, Rob Herring <robh+dt@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Krishna chaitanya chundru <quic_krichai@quicinc.com>,
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH v3 1/2] PCI: don't rely on of_platform_depopulate() for reused OF-nodes
Date: Fri, 23 Aug 2024 17:10:21 -0500 [thread overview]
Message-ID: <20240823221021.GA388724@bhelgaas> (raw)
In-Reply-To: <20240823093323.33450-2-brgl@bgdev.pl>
[+to Rob]
On Fri, Aug 23, 2024 at 11:33:22AM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.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.
Rob, any concerns with this?
> Fixes: 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> drivers/pci/remove.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
> index 910387e5bdbf..4770cb87e3f0 100644
> --- a/drivers/pci/remove.c
> +++ b/drivers/pci/remove.c
> @@ -1,7 +1,10 @@
> // SPDX-License-Identifier: GPL-2.0
> #include <linux/pci.h>
> #include <linux/module.h>
> +#include <linux/of.h>
> #include <linux/of_platform.h>
> +#include <linux/platform_device.h>
> +
> #include "pci.h"
>
> static void pci_free_resources(struct pci_dev *dev)
> @@ -14,12 +17,25 @@ static void pci_free_resources(struct pci_dev *dev)
> }
> }
>
> +static int pci_pwrctl_unregister(struct device *dev, void *data)
> +{
> + struct device_node *pci_node = data, *plat_node = dev_of_node(dev);
> +
> + 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);
> + }
> +
> + return 0;
> +}
> +
> static void pci_stop_dev(struct pci_dev *dev)
> {
> pci_pme_active(dev, false);
>
> if (pci_dev_is_added(dev)) {
> - of_platform_depopulate(&dev->dev);
> + device_for_each_child(dev->dev.parent, dev_of_node(&dev->dev),
> + pci_pwrctl_unregister);
> device_release_driver(&dev->dev);
> pci_proc_detach_device(dev);
> pci_remove_sysfs_dev_files(dev);
> --
> 2.43.0
>
next prev parent reply other threads:[~2024-08-23 22:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-23 9:33 [PATCH v3 0/2] PCI/pwrctl: fixes for v6.11 Bartosz Golaszewski
2024-08-23 9:33 ` [PATCH v3 1/2] PCI: don't rely on of_platform_depopulate() for reused OF-nodes Bartosz Golaszewski
2024-08-23 22:10 ` Bjorn Helgaas [this message]
2024-08-24 7:49 ` Bartosz Golaszewski
2024-08-27 12:55 ` Rob Herring
2024-08-27 8:40 ` Manivannan Sadhasivam
2024-08-27 12:25 ` Bartosz Golaszewski
2024-08-27 14:09 ` Manivannan Sadhasivam
2024-08-23 9:33 ` [PATCH v3 2/2] PCI/pwrctl: put the bus rescan on a different thread Bartosz Golaszewski
2024-08-27 8:56 ` Manivannan Sadhasivam
2024-09-02 7:38 ` Bartosz Golaszewski
2024-09-02 7:42 ` [PATCH v3 0/2] PCI/pwrctl: fixes for v6.11 Bartosz Golaszewski
2024-09-03 22:13 ` Bjorn Helgaas
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=20240823221021.GA388724@bhelgaas \
--to=helgaas@kernel.org \
--cc=bartosz.golaszewski@linaro.org \
--cc=bhelgaas@google.com \
--cc=brgl@bgdev.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=quic_krichai@quicinc.com \
--cc=robh+dt@kernel.org \
/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