mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <sha@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v4 5/6] of: implement of_move_node helper
Date: Tue, 13 Jun 2023 10:30:10 +0200	[thread overview]
Message-ID: <19baddaa-8b8c-3d51-1a0f-d93fec484d68@pengutronix.de> (raw)
In-Reply-To: <20230613082721.GN18491@pengutronix.de>

On 13.06.23 10:27, Sascha Hauer wrote:
> On Mon, Jun 12, 2023 at 02:51:03PM +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>
>> ---
>>  drivers/of/base.c | 18 ++++++++++++++++++
>>  include/of.h      |  1 +
>>  2 files changed, 19 insertions(+)
>>
>> diff --git a/drivers/of/base.c b/drivers/of/base.c
>> index e3416b5b75a7..43a4a923d9c5 100644
>> --- a/drivers/of/base.c
>> +++ b/drivers/of/base.c
>> @@ -2695,6 +2695,24 @@ void of_delete_node(struct device_node *node)
>>  	free(node);
>>  }
>>  
>> +void of_move_node(struct device_node *parent, struct device_node *node)
>> +{
>> +	if (!node)
>> +		return;
>> +
>> +	list_del(&node->list);
>> +	list_del(&node->parent_list);
>> +
>> +	free(node->full_name);
>> +	node->full_name = basprintf("%s/%s", parent->full_name, node->name);
>> +
>> +	if (!node->parent)
>> +		return;
> 
> Why is the old parent relevant here? Even when node didn't have a parent
> before you should still add it to the children list of the new parent.
> 
> Also node->parent should be set to the new parent.
> 
> You seem to honour the case that node didn't have a parent previously.
> Does the list_del(&node->parent_list) work in this case? I can't see any
> INIT_LIST_HEAD(&node->parent_list) in the code, so I assume running a
> list_del on it results in a NULL pointer dereference.

I will revisit this. Can you pick patches 1-4 though, so we can finally
get this in?

> 
> Sascha
> 
>> +
>> +	list_add(&node->list, &parent->list);
>> +	list_add_tail(&node->parent_list, &parent->children);
>> +}
>> +
>>  /*
>>   * of_find_node_by_chosen - Find a node given a chosen property pointing at it
>>   * @propname:   the name of the property containing a path or alias
>> diff --git a/include/of.h b/include/of.h
>> index 0037bad6c4d7..686c1632c267 100644
>> --- a/include/of.h
>> +++ b/include/of.h
>> @@ -187,6 +187,7 @@ extern struct device_node *of_create_node(struct device_node *root,
>>  extern void of_merge_nodes(struct device_node *np, const struct device_node *other);
>>  extern struct device_node *of_copy_node(struct device_node *parent,
>>  				const struct device_node *other);
>> +void of_move_node(struct device_node *parent, struct device_node *node);
>>  extern struct device_node *of_dup(const struct device_node *root);
>>  extern void of_delete_node(struct device_node *node);
>>  
>> -- 
>> 2.39.2
>>
>>
>>
> 

-- 
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 |




  reply	other threads:[~2023-06-13  8:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12 12:50 [PATCH v4 0/6] boards: qemu-virt: support passing in FIT public key Ahmad Fatoum
2023-06-12 12:50 ` [PATCH v4 1/6] boards: qemu-virt: apply overlay at postcore_initcall level Ahmad Fatoum
2023-06-12 12:51 ` [PATCH v4 2/6] kbuild: support DTC_CPP_FLAGS_file.dtbo Ahmad Fatoum
2023-06-12 12:51 ` [PATCH v4 3/6] boards: qemu-virt: compile overlay as such Ahmad Fatoum
2023-06-12 12:51 ` [PATCH v4 4/6] boards: qemu-virt: support passing in FIT public key Ahmad Fatoum
2023-06-12 12:51 ` [PATCH v4 5/6] of: implement of_move_node helper Ahmad Fatoum
2023-06-13  8:27   ` Sascha Hauer
2023-06-13  8:30     ` Ahmad Fatoum [this message]
2023-06-13  8:32       ` Sascha Hauer
2023-06-12 12:51 ` [PATCH v4 6/6] boards: qemu-virt: support older QEMU with /soc/flash 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=19baddaa-8b8c-3d51-1a0f-d93fec484d68@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=sha@pengutronix.de \
    /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