All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frank Rowand <frowand.list@gmail.com>
To: Lixin Wang <alan.1.wang@nokia-sbell.com>,
	Rob Herring <robh+dt@kernel.org>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3] of: dynamic: fix memory leak related to properties of __of_node_dup
Date: Thu, 19 Oct 2017 16:26:25 -0700	[thread overview]
Message-ID: <59E934A1.9060304@gmail.com> (raw)
In-Reply-To: <1508406006-64893-1-git-send-email-alan.1.wang@nokia-sbell.com>

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

  reply	other threads:[~2017-10-19 23:26 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-13  1:42 [PATCH] of: dynamic: fix memory leak related to properties of __of_node_dup alawang
2017-10-13  1:42 ` alawang
2017-10-17  4:20 ` [PATCH v2] " Lixin Wang
2017-10-17  4:20   ` Lixin Wang
2017-10-19  9:40 ` [PATCH v3] " Lixin Wang
2017-10-19  9:40   ` Lixin Wang
2017-10-19 23:26   ` Frank Rowand [this message]
     [not found]     ` <59E934A1.9060304-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-19 23:34       ` frowand.list-Re5JQEeQqe8AvxtiuMwx3w
2017-10-19 23:34         ` frowand.list
     [not found] ` <1507858967-40416-1-git-send-email-alan.1.wang-FTnzSCDXTkYjo0HpFSRKWA@public.gmane.org>
2017-10-13  3:25   ` [PATCH] " Lixin Wang
2017-10-13  3:25     ` Lixin Wang
2017-10-13 20:47   ` Rob Herring
2017-10-13 20:47     ` Rob Herring
2017-10-14  0:59     ` Frank Rowand
2017-10-16  4:35       ` Wang, Alan 1. (NSB - CN/Hangzhou)
     [not found]       ` <59E1615F.50901-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-17 14:03         ` Rob Herring
2017-10-17 14:03           ` Rob Herring
2017-10-20  1:59   ` [PATCH v4] " Lixin Wang
2017-10-20  1:59     ` Lixin Wang
     [not found]     ` <1508464749-54218-1-git-send-email-alan.1.wang-FTnzSCDXTkYjo0HpFSRKWA@public.gmane.org>
2017-10-20 18:12       ` Rob Herring
2017-10-20 18:12         ` Rob Herring
2017-10-23  3:19 ` [PATCH v5] " Lixin Wang
2017-10-23  3:19   ` Lixin Wang
2017-10-23  5:16   ` Frank Rowand
2017-10-23 16:47     ` Rob Herring

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=59E934A1.9060304@gmail.com \
    --to=frowand.list@gmail.com \
    --cc=alan.1.wang@nokia-sbell.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.