Re: [PATCH V5 1/3] of: dynamic: Add interfaces for creating device node dynamically

From: Clément Léger
Date: Mon Jan 02 2023 - 08:48:49 EST


Le Thu, 15 Dec 2022 09:30:44 -0800,
Lizhi Hou <lizhi.hou@xxxxxxx> a écrit :

> of_create_node() creates device node dynamically. The parent device node
> and full name are required for creating the node. It optionally creates
> an OF changeset and attaches the newly created node to the changeset. The
> device node pointer and the changeset pointer can be used to add
> properties to the device node and apply the node to the base tree.
>
> of_destroy_node() frees the device node created by of_create_node(). If
> an OF changeset was also created for this node, it will destroy the
> changeset before freeing the device node.
>
> Expand of_changeset APIs to handle specific types of properties.
> of_changeset_add_prop_string()
> of_changeset_add_prop_string_array()
> of_changeset_add_prop_u32_array()
>
> Signed-off-by: Lizhi Hou <lizhi.hou@xxxxxxx>
> Signed-off-by: Sonal Santan <sonal.santan@xxxxxxx>
> Signed-off-by: Max Zhen <max.zhen@xxxxxxx>
> Reviewed-by: Brian Xu <brian.xu@xxxxxxx>
> ---
> drivers/of/dynamic.c | 197 +++++++++++++++++++++++++++++++++++++++++++
> include/linux/of.h | 24 ++++++
> 2 files changed, 221 insertions(+)
>
> diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
> index cd3821a6444f..067d996a9f79 100644
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -461,6 +461,71 @@ struct device_node *__of_node_dup(const struct device_node *np,
> return NULL;
> }
>
> +/**
> + * of_create_node - Dynamically create a device node
> + *
> + * @parent: Pointer to parent device node
> + * @full_name: Node full name
> + * @cset: Pointer to returning changeset
> + *
> + * Return: Pointer to the created device node or NULL in case of an error.
> + */
> +struct device_node *of_create_node(struct device_node *parent,
> + const char *full_name,
> + struct of_changeset **cset)
> +{
> + struct of_changeset *ocs;
> + struct device_node *np;
> + int ret;
> +
> + np = __of_node_dup(NULL, full_name);
> + if (!np)
> + return NULL;
> + np->parent = parent;
> +
> + if (!cset)
> + return np;
> +
> + ocs = kmalloc(sizeof(*cset), GFP_KERNEL);

I started to test this series and this sizeof(*cset) is probably wrong,
it should be sizeof(*ocs) or it will yield the size of a struct
of_changeset pointer and not the struct of_changeset itself.

--
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com