blob: d1533b25673c84980faf4efc644265d9d1d8cf7a [file] [log] [blame]
From 8eaea2a3f510057ff778672cf232774bf19fd90c Mon Sep 17 00:00:00 2001
From: Navid Emamdoost <>
Date: Fri, 4 Oct 2019 13:58:43 -0500
Subject: [PATCH] of: unittest: fix memory leak in unittest_data_add
commit e13de8fe0d6a51341671bbe384826d527afe8d44 upstream.
In unittest_data_add, a copy buffer is created via kmemdup. This buffer
is leaked if of_fdt_unflatten_tree fails. The release for the
unittest_data buffer is added.
Fixes: b951f9dc7f25 ("Enabling OF selftest to run without machine's devicetree")
Signed-off-by: Navid Emamdoost <>
Reviewed-by: Frank Rowand <>
Signed-off-by: Rob Herring <>
Signed-off-by: Paul Gortmaker <>
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 3832a5de4602..55bcac00f33d 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1205,6 +1205,7 @@ static int __init unittest_data_add(void)
of_fdt_unflatten_tree(unittest_data, NULL, &unittest_data_node);
if (!unittest_data_node) {
pr_warn("%s: No tree to attach; not running tests\n", __func__);
+ kfree(unittest_data);
return -ENODATA;