All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] of: of_property_read_string return -ENODATA when !length
@ 2022-04-16  0:30 Stefano Stabellini
  2022-04-19 13:19 ` Rob Herring
  0 siblings, 1 reply; 2+ messages in thread
From: Stefano Stabellini @ 2022-04-16  0:30 UTC (permalink / raw)
  To: robh+dt, frowand.list
  Cc: sstabellini, devicetree, julien, xen-devel, Stefano Stabellini

From: Stefano Stabellini <stefano.stabellini@xilinx.com>

When the length of the string is zero of_property_read_string should
return -ENODATA according to the description of the function.

However, of_property_read_string doesn't check prop->length. If
prop->length is zero, return -ENODATA.

Without this patch the following command in u-boot:

fdt set /chosen/node property-name

results in of_property_read_string returning -EILSEQ when attempting to
read property-name. With this patch, it returns -ENODATA as expected.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
---
Changes in v2:
- use prop instead pp
- drop value check
- update function header documentation
---
 drivers/of/property.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 8e90071de6ed..84903dad96a4 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -431,6 +431,9 @@ EXPORT_SYMBOL_GPL(of_property_read_variable_u64_array);
  * property does not have a value, and -EILSEQ if the string is not
  * null-terminated within the length of the property data.
  *
+ * Note that the empty string "" has length of 1, thus -ENODATA cannot
+ * be interpreted as an empty string.
+ *
  * The out_string pointer is modified only if a valid string can be decoded.
  */
 int of_property_read_string(const struct device_node *np, const char *propname,
@@ -439,7 +442,7 @@ int of_property_read_string(const struct device_node *np, const char *propname,
 	const struct property *prop = of_find_property(np, propname, NULL);
 	if (!prop)
 		return -EINVAL;
-	if (!prop->value)
+	if (!prop->length)
 		return -ENODATA;
 	if (strnlen(prop->value, prop->length) >= prop->length)
 		return -EILSEQ;
-- 
2.25.1


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

* Re: [PATCH v2] of: of_property_read_string return -ENODATA when !length
  2022-04-16  0:30 [PATCH v2] of: of_property_read_string return -ENODATA when !length Stefano Stabellini
@ 2022-04-19 13:19 ` Rob Herring
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2022-04-19 13:19 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: devicetree, xen-devel, Stefano Stabellini, robh+dt, julien, frowand.list

On Fri, 15 Apr 2022 17:30:28 -0700, Stefano Stabellini wrote:
> From: Stefano Stabellini <stefano.stabellini@xilinx.com>
> 
> When the length of the string is zero of_property_read_string should
> return -ENODATA according to the description of the function.
> 
> However, of_property_read_string doesn't check prop->length. If
> prop->length is zero, return -ENODATA.
> 
> Without this patch the following command in u-boot:
> 
> fdt set /chosen/node property-name
> 
> results in of_property_read_string returning -EILSEQ when attempting to
> read property-name. With this patch, it returns -ENODATA as expected.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
> ---
> Changes in v2:
> - use prop instead pp
> - drop value check
> - update function header documentation
> ---
>  drivers/of/property.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 

Applied, thanks!

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

end of thread, other threads:[~2022-04-19 13:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-16  0:30 [PATCH v2] of: of_property_read_string return -ENODATA when !length Stefano Stabellini
2022-04-19 13:19 ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.