Skip to content

Commit 3b9cf79

Browse files
Stefan M Schaeckelerrobherring
authored andcommitted
of: unittest: for strings, account for trailing \0 in property length field
For strings, account for trailing \0 in property length field: This is consistent with how dtc builds string properties. Function __of_prop_dup() would misbehave on such properties as it duplicates properties based on the property length field creating new string values without trailing \0s. Signed-off-by: Stefan M Schaeckeler <[email protected]> Reviewed-by: Frank Rowand <[email protected]> Tested-by: Frank Rowand <[email protected]> Cc: <[email protected]> Signed-off-by: Rob Herring <[email protected]>
1 parent 3098e5b commit 3b9cf79

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/of/unittest.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,28 @@ static void __init of_unittest_dynamic(void)
165165
/* Add a new property - should pass*/
166166
prop->name = "new-property";
167167
prop->value = "new-property-data";
168-
prop->length = strlen(prop->value);
168+
prop->length = strlen(prop->value) + 1;
169169
unittest(of_add_property(np, prop) == 0, "Adding a new property failed\n");
170170

171171
/* Try to add an existing property - should fail */
172172
prop++;
173173
prop->name = "new-property";
174174
prop->value = "new-property-data-should-fail";
175-
prop->length = strlen(prop->value);
175+
prop->length = strlen(prop->value) + 1;
176176
unittest(of_add_property(np, prop) != 0,
177177
"Adding an existing property should have failed\n");
178178

179179
/* Try to modify an existing property - should pass */
180180
prop->value = "modify-property-data-should-pass";
181-
prop->length = strlen(prop->value);
181+
prop->length = strlen(prop->value) + 1;
182182
unittest(of_update_property(np, prop) == 0,
183183
"Updating an existing property should have passed\n");
184184

185185
/* Try to modify non-existent property - should pass*/
186186
prop++;
187187
prop->name = "modify-property";
188188
prop->value = "modify-missing-property-data-should-pass";
189-
prop->length = strlen(prop->value);
189+
prop->length = strlen(prop->value) + 1;
190190
unittest(of_update_property(np, prop) == 0,
191191
"Updating a missing property should have passed\n");
192192

0 commit comments

Comments
 (0)