linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: unittest: fix memory leak in unittest_data_add
@ 2019-10-04 18:58 Navid Emamdoost
  2019-10-05 14:34 ` Markus Elfring
  2019-10-15 19:41 ` Rob Herring
  0 siblings, 2 replies; 4+ messages in thread
From: Navid Emamdoost @ 2019-10-04 18:58 UTC (permalink / raw)
  Cc: emamd001, kjlu, smccaman, Navid Emamdoost, Rob Herring,
	Frank Rowand, devicetree, linux-kernel

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(+)

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;
 	}
 
-- 
2.17.1


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

* Re: [PATCH] of: unittest: fix memory leak in unittest_data_add
  2019-10-04 18:58 [PATCH] of: unittest: fix memory leak in unittest_data_add Navid Emamdoost
@ 2019-10-05 14:34 ` Markus Elfring
  2019-10-15 19:41 ` Rob Herring
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-10-05 14:34 UTC (permalink / raw)
  To: Navid Emamdoost, devicetree
  Cc: Navid Emamdoost, Kangjie Lu, Stephen McCamant, Frank Rowand,
	Rob Herring, linux-kernel, kernel-janitors

> 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

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

* Re: [PATCH] of: unittest: fix memory leak in unittest_data_add
  2019-10-04 18:58 [PATCH] of: unittest: fix memory leak in unittest_data_add Navid Emamdoost
  2019-10-05 14:34 ` Markus Elfring
@ 2019-10-15 19:41 ` Rob Herring
  2019-10-17 17:51   ` Frank Rowand
  1 sibling, 1 reply; 4+ messages in thread
From: Rob Herring @ 2019-10-15 19:41 UTC (permalink / raw)
  To: Navid Emamdoost
  Cc: emamd001, kjlu, smccaman, Navid Emamdoost, Frank Rowand,
	devicetree, linux-kernel

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

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

* Re: [PATCH] of: unittest: fix memory leak in unittest_data_add
  2019-10-15 19:41 ` Rob Herring
@ 2019-10-17 17:51   ` Frank Rowand
  0 siblings, 0 replies; 4+ messages in thread
From: Frank Rowand @ 2019-10-17 17:51 UTC (permalink / raw)
  To: Rob Herring, Navid Emamdoost
  Cc: emamd001, kjlu, smccaman, devicetree, linux-kernel

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>

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

end of thread, other threads:[~2019-10-17 17:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04 18:58 [PATCH] of: unittest: fix memory leak in unittest_data_add Navid Emamdoost
2019-10-05 14:34 ` Markus Elfring
2019-10-15 19:41 ` Rob Herring
2019-10-17 17:51   ` Frank Rowand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).