Re: [PATCH master v2 1/2] of: implement of_reparent_node helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03.07.23 10:54, Sascha Hauer wrote:
> 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@xxxxxxxxxxxxxx>
>> ---
>> 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.

A node without a parent doesn't have a name, that's why I limited
it to nodes that have 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.

Argh.. Thanks for noticing.


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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux