Skip to content

Commit f688d61

Browse files
Stefano Stabellinirobherring
authored andcommitted
of: of_property_read_string return -ENODATA when !length
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 <[email protected]> Signed-off-by: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f2701e0 commit f688d61

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/of/property.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ EXPORT_SYMBOL_GPL(of_property_read_variable_u64_array);
431431
* property does not have a value, and -EILSEQ if the string is not
432432
* null-terminated within the length of the property data.
433433
*
434+
* Note that the empty string "" has length of 1, thus -ENODATA cannot
435+
* be interpreted as an empty string.
436+
*
434437
* The out_string pointer is modified only if a valid string can be decoded.
435438
*/
436439
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,
439442
const struct property *prop = of_find_property(np, propname, NULL);
440443
if (!prop)
441444
return -EINVAL;
442-
if (!prop->value)
445+
if (!prop->length)
443446
return -ENODATA;
444447
if (strnlen(prop->value, prop->length) >= prop->length)
445448
return -EILSEQ;

0 commit comments

Comments
 (0)