public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Herve Codina <herve.codina@bootlin.com>
Cc: "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 v5 1/5] driver core: Introduce device_{add,remove}_of_node()
Date: Tue, 24 Dec 2024 09:29:47 +0100	[thread overview]
Message-ID: <2024122459-only-catchy-9f13@gregkh> (raw)
In-Reply-To: <20241209130339.81354-2-herve.codina@bootlin.com>

On Mon, Dec 09, 2024 at 02:03:33PM +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    | 54 ++++++++++++++++++++++++++++++++++++++++++
>  include/linux/device.h |  2 ++
>  2 files changed, 56 insertions(+)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 8b056306f04e..81e5465aa746 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -5216,6 +5216,60 @@ 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)

Why is this void?

> +{
> +	if (!of_node)
> +		return;
> +
> +	dev = get_device(dev);
> +	if (!dev)
> +		return;
> +
> +	if (dev->of_node) {
> +		dev_warn(dev, "Cannot replace node %pOF with %pOF\n",
> +			 dev->of_node, of_node);

Why not return an error too?  Otherwise you can never know if this
worked or not.

thanks,

greg k-h

  reply	other threads:[~2024-12-24  8:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-09 13:03 [PATCH v5 0/5] Add support for the PCI host bridge device-tree node creation Herve Codina
2024-12-09 13:03 ` [PATCH v5 1/5] driver core: Introduce device_{add,remove}_of_node() Herve Codina
2024-12-24  8:29   ` Greg Kroah-Hartman [this message]
2024-12-09 13:03 ` [PATCH v5 2/5] PCI: of: Use device_{add,remove}_of_node() to attach of_node to existing device Herve Codina
2024-12-09 13:03 ` [PATCH v5 3/5] PCI: of_property: Add support for NULL pdev in of_pci_set_address() Herve Codina
2024-12-09 13:03 ` [PATCH v5 4/5] PCI: of_property: Constify parameter in of_pci_get_addr_flags() Herve Codina
2024-12-09 13:03 ` [PATCH v5 5/5] PCI: of: Create device-tree PCI host bridge node Herve Codina
2024-12-24  6:20   ` kernel test robot

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=2024122459-only-catchy-9f13@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=allan.nielsen@microchip.com \
    --cc=bhelgaas@google.com \
    --cc=devicetree@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox