Skip to content

Commit 29acfb6

Browse files
frowandrobherring
authored andcommitted
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: 2fe0e87 ("of: overlay: check prevents multiple fragments touching same property") Reported-by: Erhard F. <[email protected]> Signed-off-by: Frank Rowand <[email protected]> Signed-off-by: Rob Herring <[email protected]>
1 parent 478ff64 commit 29acfb6

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

drivers/of/unittest-data/overlay_bad_add_dup_prop.dts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,37 @@
33
/plugin/;
44

55
/*
6-
* &electric_1/motor-1 and &spin_ctrl_1 are the same node:
7-
* /testcase-data-2/substation@100/motor-1
6+
* &electric_1/motor-1/electric and &spin_ctrl_1/electric are the same node:
7+
* /testcase-data-2/substation@100/motor-1/electric
88
*
99
* Thus the property "rpm_avail" in each fragment will
1010
* result in an attempt to update the same property twice.
1111
* This will result in an error and the overlay apply
1212
* will fail.
13+
*
14+
* The previous version of this test did not include the extra
15+
* level of node 'electric'. That resulted in the 'rpm_avail'
16+
* property being located in the pre-existing node 'motor-1'.
17+
* Modifying a property results in a WARNING that a memory leak
18+
* will occur if the overlay is removed. Since the overlay apply
19+
* fails, the memory leak does actually occur, and kmemleak will
20+
* further report the memory leak if CONFIG_DEBUG_KMEMLEAK is
21+
* enabled. Adding the overlay node 'electric' avoids the
22+
* memory leak and thus people who use kmemleak will not
23+
* have to debug this non-problem again.
1324
*/
1425

1526
&electric_1 {
1627

1728
motor-1 {
18-
rpm_avail = < 100 >;
29+
electric {
30+
rpm_avail = < 100 >;
31+
};
1932
};
2033
};
2134

2235
&spin_ctrl_1 {
23-
rpm_avail = < 100 200 >;
36+
electric {
37+
rpm_avail = < 100 200 >;
38+
};
2439
};

drivers/of/unittest.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,21 +3181,21 @@ static __init void of_unittest_overlay_high_level(void)
31813181
"OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
31823182

31833183
EXPECT_BEGIN(KERN_ERR,
3184-
"OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail");
3184+
"OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
31853185
EXPECT_BEGIN(KERN_ERR,
3186-
"OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail");
3186+
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
31873187
EXPECT_BEGIN(KERN_ERR,
3188-
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/rpm_avail");
3188+
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
31893189

31903190
unittest(overlay_data_apply("overlay_bad_add_dup_prop", NULL),
31913191
"Adding overlay 'overlay_bad_add_dup_prop' failed\n");
31923192

31933193
EXPECT_END(KERN_ERR,
3194-
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/rpm_avail");
3194+
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
31953195
EXPECT_END(KERN_ERR,
3196-
"OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail");
3196+
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
31973197
EXPECT_END(KERN_ERR,
3198-
"OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/motor-1/rpm_avail");
3198+
"OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
31993199

32003200
unittest(overlay_data_apply("overlay_bad_phandle", NULL),
32013201
"Adding overlay 'overlay_bad_phandle' failed\n");

0 commit comments

Comments
 (0)