From: Herve Codina <herve.codina@bootlin.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Bjorn Helgaas <helgaas@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@google.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Lizhi Hou <lizhi.hou@amd.com>,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-pci@vger.kernel.org,
Allan Nielsen <allan.nielsen@microchip.com>,
Horatiu Vultur <horatiu.vultur@microchip.com>,
Steen Hegelund <steen.hegelund@microchip.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v4 1/6] driver core: Introduce device_{add,remove}_of_node()
Date: Thu, 5 Dec 2024 08:33:33 +0100 [thread overview]
Message-ID: <20241205083333.3a4141b1@bootlin.com> (raw)
In-Reply-To: <2024120537-varying-chain-7d1e@gregkh>
Hi Greg,
On Thu, 5 Dec 2024 08:00:44 +0100
Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
> On Wed, Dec 04, 2024 at 03:38:25PM -0600, Bjorn Helgaas wrote:
> > [cc->to Greg, Rafael]
> >
> > On Mon, Dec 02, 2024 at 02:15:13PM +0100, Herve Codina wrote:
> > > An of_node can be set to a device using device_set_node().
> > > This function cannot prevent any of_node and/or fwnode overwrites.
> > >
> > > When adding an of_node on an already present device, the following
> > > operations need to be done:
> > > - Attach the of_node if no of_node were already attached
> > > - Attach the of_node as a fwnode if no fwnode were already attached
> > >
> > > This is the purpose of device_add_of_node().
> > > device_remove_of_node() reverts the operations done by
> > > device_add_of_node().
> > >
> > > Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> > > ---
> > > drivers/base/core.c | 52 ++++++++++++++++++++++++++++++++++++++++++
> > > include/linux/device.h | 2 ++
> >
> > I suppose this series would go via the PCI tree since the bulk of the
> > changes are there. If so, I would look for an ack from the driver
> > core folks (Greg, Rafael).
> >
> > > 2 files changed, 54 insertions(+)
> > >
> > > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > > index 8b056306f04e..3953c5ab7316 100644
> > > --- a/drivers/base/core.c
> > > +++ b/drivers/base/core.c
> > > @@ -5216,6 +5216,58 @@ void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
> > > }
> > > EXPORT_SYMBOL_GPL(set_secondary_fwnode);
> > >
> > > +/**
> > > + * device_remove_of_node - Remove an of_node from a device
> > > + * @dev: device whose device-tree node is being removed
> > > + */
> > > +void device_remove_of_node(struct device *dev)
> > > +{
> > > + dev = get_device(dev);
> > > + if (!dev)
> > > + return;
> > > +
> > > + if (!dev->of_node)
> > > + goto end;
> > > +
> > > + if (dev->fwnode == of_fwnode_handle(dev->of_node))
> > > + dev->fwnode = NULL;
> > > +
> > > + of_node_put(dev->of_node);
> > > + dev->of_node = NULL;
> > > +
> > > +end:
> > > + put_device(dev);
> > > +}
> > > +EXPORT_SYMBOL_GPL(device_remove_of_node);
> > > +
> > > +/**
> > > + * device_add_of_node - Add an of_node to an existing device
> > > + * @dev: device whose device-tree node is being added
> > > + * @of_node: of_node to add
> > > + */
> > > +void device_add_of_node(struct device *dev, struct device_node *of_node)
> > > +{
> > > + if (!of_node)
> > > + return;
> > > +
> > > + dev = get_device(dev);
> > > + if (!dev)
> > > + return;
> > > +
> > > + if (WARN(dev->of_node, "%s: Cannot replace node %pOF with %pOF\n",
> > > + dev_name(dev), dev->of_node, of_node))
> > > + goto end;
>
> Please do not reboot machines that have panic-on-warn for something that
> you can properly handle and recover from (like this.) Just print out a
> message and continue on, or better yet, return an error if this didn't
> work properly.
>
I will change to dev_warn() in the next iteration.
Thanks for pointing this.
Best regards,
Hervé
next prev parent reply other threads:[~2024-12-05 7:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 13:15 [PATCH v4 0/6] Add support for the PCI host bridge device-tree node creation Herve Codina
2024-12-02 13:15 ` [PATCH v4 1/6] driver core: Introduce device_{add,remove}_of_node() Herve Codina
2024-12-04 21:38 ` Bjorn Helgaas
2024-12-05 7:00 ` Greg Kroah-Hartman
2024-12-05 7:33 ` Herve Codina [this message]
2024-12-02 13:15 ` [PATCH v4 2/6] PCI: of: Use device_{add,remove}_of_node() to attach of_node to existing device Herve Codina
2024-12-02 13:15 ` [PATCH v4 3/6] PCI: of_property: Add support for NULL pdev in of_pci_set_address() Herve Codina
2024-12-02 13:15 ` [PATCH v4 4/6] PCI: of_property: Constify parameter in of_pci_get_addr_flags() Herve Codina
2024-12-02 13:15 ` [PATCH v4 5/6] of: Add #address-cells/#size-cells in the device-tree root empty node Herve Codina
2024-12-02 15:48 ` Rob Herring
2024-12-02 13:15 ` [PATCH v4 6/6] PCI: of: Create device-tree PCI host bridge node Herve Codina
2024-12-04 21:48 ` Bjorn Helgaas
2024-12-05 7:37 ` Herve Codina
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=20241205083333.3a4141b1@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=allan.nielsen@microchip.com \
--cc=bhelgaas@google.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=helgaas@kernel.org \
--cc=horatiu.vultur@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lizhi.hou@amd.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
--cc=steen.hegelund@microchip.com \
--cc=thomas.petazzoni@bootlin.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.