mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] of: overlay: fix memory leak of ovcs on error exit path
@ 2017-11-29 19:17 Colin King
  2017-11-30 12:14 ` Frank Rowand
  0 siblings, 1 reply; 10+ messages in thread
From: Colin King @ 2017-11-29 19:17 UTC (permalink / raw)
  To: Pantelis Antoniou, Rob Herring, Frank Rowand, devicetree
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently if the call to of_resolve_phandles fails then then ovcs
is not kfree'd on the error exit path.  Rather than try and make
the clean up exit path more convoluted, fix this by just kfree'ing
ovcs at the point of error detection and exit via the same exit
path.

Detected by CoverityScan, CID#1462296 ("Resource Leak")

Fixes: f948d6d8b792 ("of: overlay: avoid race condition between applying multiple overlays")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/of/overlay.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 53bc9e3f0b98..6c8efe7d8cbb 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -708,8 +708,10 @@ int of_overlay_apply(struct device_node *tree, int *ovcs_id)
 	of_overlay_mutex_lock();
 
 	ret = of_resolve_phandles(tree);
-	if (ret)
+	if (ret) {
+		kfree(ovcs);
 		goto err_overlay_unlock;
+	}
 
 	mutex_lock(&of_mutex);
 
-- 
2.14.1

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

end of thread, other threads:[~2017-12-04 15:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29 19:17 [PATCH] of: overlay: fix memory leak of ovcs on error exit path Colin King
2017-11-30 12:14 ` Frank Rowand
2017-11-30 12:18   ` Colin Ian King
2017-11-30 13:37     ` Frank Rowand
2017-11-30 15:01       ` Frank Rowand
2017-11-30 15:26         ` Rob Herring
2017-11-30 12:50   ` Dan Carpenter
2017-11-30 12:54     ` Colin Ian King
2017-11-30 13:51     ` Geert Uytterhoeven
2017-12-04 15:15     ` Geert Uytterhoeven

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

all inboxes | Powered by JetHome®