lkml.org 
[lkml]   [2017]   [Oct]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v3] of: dynamic: fix memory leak related to properties of __of_node_dup
From
Date
Hi Lixin,

On 10/19/17 02:40, Lixin Wang wrote:
> If a node with no properties is dynamically added, then a property is
> dynamically added to the node, then the property is dynamically removed,
> the result will be node->properties == NULL and node->deadprops != NULL.
>
> Add a separate function to release the properties in both lists.
>
> Signed-off-by: Lixin Wang <alan.1.wang@nokia-sbell.com>
> ---
> v2 -> v3:
> * Add a separate function to release the properties in both lists.
> * Change the patch description for this change.
>
> drivers/of/dynamic.c | 27 +++++++++++++++------------
> 1 file changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
> index 301b6db..b28511f 100644
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -315,6 +315,19 @@ int of_detach_node(struct device_node *np)
> }
> EXPORT_SYMBOL_GPL(of_detach_node);
>
> +static void __of_property_list_release(struct property *prop)
> +{
> + struct property *next;
> +
> + while (prop) {
> + next = prop->next;
> + kfree(prop->name);
> + kfree(prop->value);
> + kfree(prop);
> + prop = next;
> + }
> +}
> +
> /**
> * of_node_release() - release a dynamically allocated node
> * @kref: kref element of the node to be released
> @@ -324,7 +337,6 @@ EXPORT_SYMBOL_GPL(of_detach_node);
> void of_node_release(struct kobject *kobj)
> {
> struct device_node *node = kobj_to_device_node(kobj);
> - struct property *prop = node->properties;
>
> /* We should never be releasing nodes that haven't been detached. */
> if (!of_node_check_flag(node, OF_DETACHED)) {
> @@ -335,18 +347,9 @@ void of_node_release(struct kobject *kobj)
> if (!of_node_check_flag(node, OF_DYNAMIC))
> return;
>
> - while (prop) {
> - struct property *next = prop->next;
> - kfree(prop->name);
> - kfree(prop->value);
> - kfree(prop);
> - prop = next;
> + __of_property_list_release(node->properties);
> + __of_property_list_release(node->deadprops);
>
> - if (!prop) {
> - prop = node->deadprops;
> - node->deadprops = NULL;
> - }
> - }
> kfree(node->full_name);
> kfree(node->data);
> kfree(node);
>

The code is correct, but I would prefer some style issues to be more
consistent with device tree code. I will reply to this email with
an example patch that you can use.

-Frank

\
 
 \ /
  Last update: 2017-10-22 17:31    [W:0.131 / U:1.556 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site