All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Herve Codina <herve.codina@bootlin.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>
Cc: 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: Wed, 4 Dec 2024 15:38:25 -0600	[thread overview]
Message-ID: <20241204213825.GA3016970@bhelgaas> (raw)
In-Reply-To: <20241202131522.142268-2-herve.codina@bootlin.com>

[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;
> +
> +	dev->of_node = of_node_get(of_node);
> +
> +	if (!dev->fwnode)
> +		dev->fwnode = of_fwnode_handle(of_node);
> +
> +end:
> +	put_device(dev);
> +}
> +EXPORT_SYMBOL_GPL(device_add_of_node);
> +
>  /**
>   * device_set_of_node_from_dev - reuse device-tree node of another device
>   * @dev: device whose device-tree node is being set
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 667cb6db9019..ef4c0f3c41cd 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -1149,6 +1149,8 @@ int device_online(struct device *dev);
>  void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
>  void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
>  void device_set_node(struct device *dev, struct fwnode_handle *fwnode);
> +void device_add_of_node(struct device *dev, struct device_node *of_node);
> +void device_remove_of_node(struct device *dev);
>  void device_set_of_node_from_dev(struct device *dev, const struct device *dev2);
>  
>  static inline struct device_node *dev_of_node(struct device *dev)
> -- 
> 2.47.0
> 

  reply	other threads:[~2024-12-04 21:38 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 [this message]
2024-12-05  7:00     ` Greg Kroah-Hartman
2024-12-05  7:33       ` Herve Codina
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=20241204213825.GA3016970@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=allan.nielsen@microchip.com \
    --cc=bhelgaas@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=herve.codina@bootlin.com \
    --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.