public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] of: overlay: fix memory leak related to duplicated property
@ 2017-10-13  1:53 alawang
  2017-10-13  3:07 ` [PATCH] " Lixin Wang
  2017-10-13 21:39 ` [PATCH 1/2] " Frank Rowand
  0 siblings, 2 replies; 11+ messages in thread
From: alawang @ 2017-10-13  1:53 UTC (permalink / raw)
  To: Pantelis Antoniou, Rob Herring, Frank Rowand
  Cc: linux-kernel, devicetree, alawang

Function of_changeset_add_property or of_changeset_update_property may
fails. In this case the property just allocated is never deallocated.

Signed-off-by: alawang <alan.1.wang@nokia-sbell.com>
---
 drivers/of/overlay.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 8ecfee3..af3b9a1 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -162,6 +162,7 @@ static int of_overlay_apply_single_property(struct of_overlay *ov,
 		bool is_symbols_node)
 {
 	struct property *propn = NULL, *tprop;
+	int ret = 0;
 
 	/* NOTE: Multiple changes of single properties not supported */
 	tprop = of_find_property(target, prop->name, NULL);
@@ -186,10 +187,16 @@ static int of_overlay_apply_single_property(struct of_overlay *ov,
 
 	/* not found? add */
 	if (tprop == NULL)
-		return of_changeset_add_property(&ov->cset, target, propn);
-
-	/* found? update */
-	return of_changeset_update_property(&ov->cset, target, propn);
+		ret = of_changeset_add_property(&ov->cset, target, propn);
+	else /* found? update */
+		ret = of_changeset_update_property(&ov->cset, target, propn);
+
+	if (ret) {
+		kfree(propn->name);
+		kfree(propn->value);
+		kfree(propn);
+	}
+	return ret;
 }
 
 static int of_overlay_apply_single_device_node(struct of_overlay *ov,
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-10-17 14:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-13  1:53 [PATCH 1/2] of: overlay: fix memory leak related to duplicated property alawang
2017-10-13  3:07 ` [PATCH] " Lixin Wang
2017-10-13 20:49   ` Rob Herring
2017-10-13 22:04   ` Frank Rowand
2017-10-16  2:35     ` Wang, Alan 1. (NSB - CN/Hangzhou)
2017-10-16  6:07       ` Frank Rowand
2017-10-16 20:54         ` Rob Herring
2017-10-16  9:54   ` Lixin Wang
2017-10-17 14:06     ` Rob Herring
2017-10-13 21:39 ` [PATCH 1/2] " Frank Rowand
2017-10-16  2:29   ` Wang, Alan 1. (NSB - CN/Hangzhou)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox