mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH master v2 1/2] of: implement of_reparent_node helper
Date: Mon, 3 Jul 2023 10:54:42 +0200	[thread overview]
Message-ID: <20230703085442.GK18491@pengutronix.de> (raw)
In-Reply-To: <20230629065612.1119622-1-a.fatoum@pengutronix.de>

On Thu, Jun 29, 2023 at 08:56:12AM +0200, Ahmad Fatoum wrote:
> Reparenting nodes can be a useful thing to do in fixups. Add a helper
> for that.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 -> v2:
>   - rename from of_move_node to of_reparent_node
>   - ensure that there's a parent to avoid null pointer deref
>     (Sascha)
>   - set node->parent to new_parent (Sascha)
>   - Remove broken condition on old parent (Sascha)
> ---
>  drivers/of/base.c           | 26 ++++++++++++++++++++++++++
>  include/of.h                |  1 +
>  test/self/of_manipulation.c |  8 ++++++--
>  3 files changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 4dc1c76b136d..e1134e9c694b 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2697,6 +2697,32 @@ void of_delete_node(struct device_node *node)
>  	free(node);
>  }
>  
> +/*
> + * of_reparent_node - Move node from beneath one parent to another
> + * @new_parent: The new parent node
> + * @node        The node to be moved
> + */
> +int of_reparent_node(struct device_node *new_parent, struct device_node *node)
> +{
> +	if (!node)
> +		return 0;
> +
> +	if (!new_parent || !node->parent)
> +		return -EINVAL;
> +
> +	list_del(&node->parent_list);
> +	list_del(&node->list);

You could put these list operations into a if (node->parent), then @node
wouldn't necessarily need a parent.

> +
> +	free(node->full_name);
> +	node->full_name = basprintf("%s/%s", new_parent->full_name, node->name);

That fixes full_name of @node, but not its children.

One obvious solution would be to iterate over the children and fix the
name recursively. Another one would be to git rid of the full_name
member and generate the name dynamically when needed, but that wouldn't be
master material anymore.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  parent reply	other threads:[~2023-07-03  8:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-29  6:56 Ahmad Fatoum
2023-06-29  6:56 ` [PATCH master v2 2/2] boards: qemu-virt: support older QEMU with /soc/flash Ahmad Fatoum
2023-07-03  8:54 ` Sascha Hauer [this message]
2023-07-03  8:57   ` [PATCH master v2 1/2] of: implement of_reparent_node helper Ahmad Fatoum

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=20230703085442.GK18491@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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