diff options
author | Lixin Wang <alan.1.wang@nokia-sbell.com> | 2017-10-23 11:19:53 +0800 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2017-10-23 11:18:44 -0500 |
commit | 070ea018fa092f2ef41bef57896665a25f05d2d8 (patch) | |
tree | 2e37ee4f89085d9b8c2e9eb0d916ede61fe51dbb /drivers/of | |
parent | 4ee7c0d9649d472d31969b9cbb8151161db6a807 (diff) | |
download | linux-070ea018fa092f2ef41bef57896665a25f05d2d8.tar.bz2 |
of: dynamic: fix memory leak related to properties of __of_node_dup
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>
Reviewed-by: Frank Rowand <frank.rowand@sony.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/dynamic.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 747d87619faf..c454941b34ec 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -298,6 +298,18 @@ int of_detach_node(struct device_node *np) } EXPORT_SYMBOL_GPL(of_detach_node); +static void property_list_free(struct property *prop_list) +{ + struct property *prop, *next; + + for (prop = prop_list; prop != NULL; prop = next) { + next = prop->next; + kfree(prop->name); + kfree(prop->value); + kfree(prop); + } +} + /** * of_node_release() - release a dynamically allocated node * @kref: kref element of the node to be released @@ -307,7 +319,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)) { @@ -318,18 +329,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; + property_list_free(node->properties); + property_list_free(node->deadprops); - if (!prop) { - prop = node->deadprops; - node->deadprops = NULL; - } - } kfree(node->full_name); kfree(node->data); kfree(node); |