public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] of: unittest: for strings, account for trailing \0 in property length field
@ 2018-05-21 23:26 Stefan M Schaeckeler
  2018-05-22 17:25 ` Rob Herring
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan M Schaeckeler @ 2018-05-21 23:26 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand, devicetree@vger.kernel.org

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 <sschaeck@cisco.com>
Reviewed-by: Frank Rowand <frank.rowand@sony.com>
Tested-by: Frank Rowand <frank.rowand@sony.com>
---
Changes in v3:
 - forgot one string in v2.
Changes in v2:
- fixed spacing around + sign.

 drivers/of/unittest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 6bb37c1..ecee50d 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -165,20 +165,20 @@ static void __init of_unittest_dynamic(void)
 	/* Add a new property - should pass*/
 	prop->name = "new-property";
 	prop->value = "new-property-data";
-	prop->length = strlen(prop->value);
+	prop->length = strlen(prop->value) + 1;
 	unittest(of_add_property(np, prop) == 0, "Adding a new property failed\n");
 
 	/* Try to add an existing property - should fail */
 	prop++;
 	prop->name = "new-property";
 	prop->value = "new-property-data-should-fail";
-	prop->length = strlen(prop->value);
+	prop->length = strlen(prop->value) + 1;
 	unittest(of_add_property(np, prop) != 0,
 		 "Adding an existing property should have failed\n");
 
 	/* Try to modify an existing property - should pass */
 	prop->value = "modify-property-data-should-pass";
-	prop->length = strlen(prop->value);
+	prop->length = strlen(prop->value) + 1;
 	unittest(of_update_property(np, prop) == 0,
 		 "Updating an existing property should have passed\n");
 
@@ -186,7 +186,7 @@ static void __init of_unittest_dynamic(void)
 	prop++;
 	prop->name = "modify-property";
 	prop->value = "modify-missing-property-data-should-pass";
-	prop->length = strlen(prop->value);
+	prop->length = strlen(prop->value) + 1;
 	unittest(of_update_property(np, prop) == 0,
 		 "Updating a missing property should have passed\n");
 
-- 
2.10.3.dirty


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

* Re: [PATCH v3] of: unittest: for strings, account for trailing \0 in property length field
  2018-05-21 23:26 [PATCH v3] of: unittest: for strings, account for trailing \0 in property length field Stefan M Schaeckeler
@ 2018-05-22 17:25 ` Rob Herring
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2018-05-22 17:25 UTC (permalink / raw)
  To: Stefan M Schaeckeler; +Cc: Frank Rowand, devicetree@vger.kernel.org

On Mon, May 21, 2018 at 04:26:14PM -0700, Stefan M Schaeckeler wrote:
> 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 <sschaeck@cisco.com>
> Reviewed-by: Frank Rowand <frank.rowand@sony.com>
> Tested-by: Frank Rowand <frank.rowand@sony.com>
> ---
> Changes in v3:
>  - forgot one string in v2.
> Changes in v2:
> - fixed spacing around + sign.
> 
>  drivers/of/unittest.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Applied, thanks.

Rob

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

end of thread, other threads:[~2018-05-22 17:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-21 23:26 [PATCH v3] of: unittest: for strings, account for trailing \0 in property length field Stefan M Schaeckeler
2018-05-22 17:25 ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox