of: unittest: fix memory leak in unittest_data_add
diff mbox series

Message ID 20191004185847.14074-1-navid.emamdoost@gmail.com
State Accepted
Headers show
Series
  • of: unittest: fix memory leak in unittest_data_add
Related show

Checks

Context Check Description
robh/checkpatch success

Commit Message

Navid Emamdoost Oct. 4, 2019, 6:58 p.m. UTC
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 <navid.emamdoost@gmail.com>
---
 drivers/of/unittest.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Markus Elfring Oct. 5, 2019, 2:34 p.m. UTC | #1
> 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.

Can a wording like the following be nicer for the change description?

  The buffer “__dtb_testcases_begin” will be duplicated to the local
  variable “unittest_data”. Release the corresponding memory
  after a call of the function “of_fdt_unflatten_tree” failed
  in the implementation of the function “unittest_data_add”.


Regards,
Markus
Rob Herring Oct. 15, 2019, 7:41 p.m. UTC | #2
On Fri,  4 Oct 2019 13:58:43 -0500, Navid Emamdoost wrote:
> 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 <navid.emamdoost@gmail.com>
> ---
>  drivers/of/unittest.c | 1 +
>  1 file changed, 1 insertion(+)
> 

Applied, thanks.

Rob
Frank Rowand Oct. 17, 2019, 5:51 p.m. UTC | #3
On 10/15/2019 14:41, Rob Herring wrote:
> On Fri,  4 Oct 2019 13:58:43 -0500, Navid Emamdoost wrote:
>> 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 <navid.emamdoost@gmail.com>
>> ---
>>  drivers/of/unittest.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
> 
> Applied, thanks.
> 
> Rob
> 

Academic since already applied, but:

Reviewed-by: Frank Rowand <frowand.list@gmail.com>

Patch
diff mbox series

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 480a21e2ed39..92e895d86458 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1207,6 +1207,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;
 	}