Commit 29acfb65 authored by Frank Rowand's avatar Frank Rowand Committed by Rob Herring

of: unittest: kmemleak in duplicate property update

kmemleak reports several memory leaks from devicetree unittest.
This is the fix for problem 5 of 5.

When overlay 'overlay_bad_add_dup_prop' is applied, the apply code
properly detects that a memory leak will occur if the overlay is removed
since the duplicate property is located in a base devicetree node and
reports via printk():

  OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail
  OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail

The overlay is removed when the apply code detects multiple changesets
modifying the same property.  This is reported via printk():

  OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/rpm_avail

As a result of this error, the overlay is removed resulting in the
expected memory leak.

Add another device node level to the overlay so that the duplicate
property is located in a node added by the overlay, thus no memory
leak will occur when the overlay is removed.

Thus users of kmemleak will not have to debug this leak in the future.

Fixes: 2fe0e876 ("of: overlay: check prevents multiple fragments touching same property")
Reported-by: default avatarErhard F. <erhard_f@mailbox.org>
Signed-off-by: default avatarFrank Rowand <frank.rowand@sony.com>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
parent 478ff649
...@@ -3,22 +3,37 @@ ...@@ -3,22 +3,37 @@
/plugin/; /plugin/;
/* /*
* &electric_1/motor-1 and &spin_ctrl_1 are the same node: * &electric_1/motor-1/electric and &spin_ctrl_1/electric are the same node:
* /testcase-data-2/substation@100/motor-1 * /testcase-data-2/substation@100/motor-1/electric
* *
* Thus the property "rpm_avail" in each fragment will * Thus the property "rpm_avail" in each fragment will
* result in an attempt to update the same property twice. * result in an attempt to update the same property twice.
* This will result in an error and the overlay apply * This will result in an error and the overlay apply
* will fail. * will fail.
*
* The previous version of this test did not include the extra
* level of node 'electric'. That resulted in the 'rpm_avail'
* property being located in the pre-existing node 'motor-1'.
* Modifying a property results in a WARNING that a memory leak
* will occur if the overlay is removed. Since the overlay apply
* fails, the memory leak does actually occur, and kmemleak will
* further report the memory leak if CONFIG_DEBUG_KMEMLEAK is
* enabled. Adding the overlay node 'electric' avoids the
* memory leak and thus people who use kmemleak will not
* have to debug this non-problem again.
*/ */
&electric_1 { &electric_1 {
motor-1 { motor-1 {
rpm_avail = < 100 >; electric {
rpm_avail = < 100 >;
};
}; };
}; };
&spin_ctrl_1 { &spin_ctrl_1 {
rpm_avail = < 100 200 >; electric {
rpm_avail = < 100 200 >;
};
}; };
...@@ -3181,21 +3181,21 @@ static __init void of_unittest_overlay_high_level(void) ...@@ -3181,21 +3181,21 @@ static __init void of_unittest_overlay_high_level(void)
"OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller"); "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
EXPECT_BEGIN(KERN_ERR, EXPECT_BEGIN(KERN_ERR,
"OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail"); "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
EXPECT_BEGIN(KERN_ERR, EXPECT_BEGIN(KERN_ERR,
"OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail"); "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
EXPECT_BEGIN(KERN_ERR, EXPECT_BEGIN(KERN_ERR,
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/rpm_avail"); "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
unittest(overlay_data_apply("overlay_bad_add_dup_prop", NULL), unittest(overlay_data_apply("overlay_bad_add_dup_prop", NULL),
"Adding overlay 'overlay_bad_add_dup_prop' failed\n"); "Adding overlay 'overlay_bad_add_dup_prop' failed\n");
EXPECT_END(KERN_ERR, EXPECT_END(KERN_ERR,
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/rpm_avail"); "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
EXPECT_END(KERN_ERR, EXPECT_END(KERN_ERR,
"OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail"); "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
EXPECT_END(KERN_ERR, EXPECT_END(KERN_ERR,
"OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail"); "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
unittest(overlay_data_apply("overlay_bad_phandle", NULL), unittest(overlay_data_apply("overlay_bad_phandle", NULL),
"Adding overlay 'overlay_bad_phandle' failed\n"); "Adding overlay 'overlay_bad_phandle' failed\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment