[PATCH] fix a number of memleaks with three patches

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

 




>From c50312e4796bb76877a7d7cd453476462a24cf53 Mon Sep 17 00:00:00 2001
From: Qi Hou <qi.hou@xxxxxxxxxxxxx>
Date: Fri, 13 Jan 2017 09:56:28 +0800
Subject: [PATCH 1/3] of: fix of_node leak caused in of_find_node_opts_by_path

During stepping down the tree, parent node is gotten first and its refcount is
increased with of_node_get() in __of_get_next_child(). Since it just being used
as step node, its refcount must be decreased with of_node_put() after traversing
its child nodes.

Or, its refcount will never be descreased to ZERO, then it will never be freed,
as well as other related memory blocks.

To fix this, decrease refcount of parent with of_node_put() after
__of_find_node_by_path().

Signed-off-by: Qi Hou <qi.hou@xxxxxxxxxxxxx>
Reviewed-by: Zhang Xiao <xiao.zhang@xxxxxxxxxxxxx>
Acked-by: Bruce Ashfield <bruce.ashfield@xxxxxxxxxxxxx>
---
 drivers/of/base.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index d4bea3c..c72e860 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -802,7 +802,7 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent,
  */
 struct device_node *of_find_node_opts_by_path(const char *path, const char **opts)
 {
-	struct device_node *np = NULL;
+	struct device_node *np = NULL, *npp = NULL;
 	struct property *pp;
 	unsigned long flags;
 	const char *separator = strchr(path, ':');
@@ -843,7 +843,9 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
 		np = of_node_get(of_root);
 	while (np && *path == '/') {
 		path++; /* Increment past '/' delimiter */
-		np = __of_find_node_by_path(np, path);
+		npp = np;
+		np = __of_find_node_by_path(npp, path);
+		of_node_put(npp);
 		path = strchrnul(path, '/');
 		if (separator && separator < path)
 			break;
-- 
1.9.1

>From 3c5d1c038a7d8d49fd3a2f9bd0c873ca3b6dc41b Mon Sep 17 00:00:00 2001
From: Qi Hou <qi.hou@xxxxxxxxxxxxx>
Date: Mon, 16 Jan 2017 12:40:18 +0800
Subject: [PATCH 2/3] i2c: add missing of_node_put in i2c_unregister_device

Refcount of of_node is increased with of_node_get() in of_i2c_register_device().
It must be decreased with of_node_put() in i2c_unregister_device().

Signed-off-by: Qi Hou <qi.hou@xxxxxxxxxxxxx>
Reviewed-by: Zhang Xiao <xiao.zhang@xxxxxxxxxxxxx>
Acked-by: Bruce Ashfield <bruce.ashfield@xxxxxxxxxxxxx>
---
 drivers/i2c/i2c-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 583e950..8afa0f4 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1366,6 +1366,7 @@ void i2c_unregister_device(struct i2c_client *client)
 		of_node_clear_flag(client->dev.of_node, OF_POPULATED);
 	if (ACPI_COMPANION(&client->dev))
 		acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
+	of_node_put(client->dev.of_node);
 	device_unregister(&client->dev);
 }
 EXPORT_SYMBOL_GPL(i2c_unregister_device);
-- 
1.9.1

>From 430451b32fc8596bb1f887d89bbc5e391e052d3d Mon Sep 17 00:00:00 2001
From: Qi Hou <qi.hou@xxxxxxxxxxxxx>
Date: Mon, 16 Jan 2017 17:58:39 +0800
Subject: [PATCH 3/3] i2c: add missing of_node_put in i2c_mux_del_adapters

Refcount of of_node is increased with of_node_get() in i2c_mux_add_adapter().
It must be decreased with of_node_put() in i2c_mux_del_adapters().

Signe-off-by: Qi Hou <qi.hou@xxxxxxxxxxxxx>
Reviewed-by: Zhang Xiao <xiao.zhang@xxxxxxxxxxxxx>
Acked-by: Bruce Ashfield <bruce.ashfield@xxxxxxxxxxxxx>
---
 drivers/i2c/i2c-mux.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 83768e8..d7ebbfb 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -437,6 +437,7 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc)
 		sysfs_remove_link(&muxc->dev->kobj, symlink_name);
 
 		sysfs_remove_link(&priv->adap.dev.kobj, "mux_device");
+		of_node_put(adap->dev.of_node);
 		i2c_del_adapter(adap);
 		kfree(priv);
 	}
-- 
1.9.1


[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]