Skip to contentSkip to conversation

dm: core: Expand integer-reading tests

PATCH In review Simon Glass 2 participants 2 messages Sep 30, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 30/45 dm: core: Expand integer-reading tests

The current tests do not cover all the behaviour. Add some more.

Tidy up a few inconsistencies between livetree and flattree which come to light with these tests. Also drop the -ENODATA error since it is never actually returned.

---

Changes in v3:
- Avoid code-size increase in SPL where error codes matter less

 drivers/core/of_access.c |   5 +-
 drivers/core/ofnode.c    |  17 +++++--
 include/dm/of_access.h   |  10 ++--
 include/dm/ofnode.h      |   8 +--
 test/dm/ofnode.c         | 102 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 125 insertions(+), 17 deletions(-)
drivers/core/of_access.c +1 -4
index 8631e1c286b..85f7da5a499 100644
@@ -471,8 +471,7 @@ struct device_node *of_find_node_by_phandle(struct device_node *root,
  * @len:	requested length of property value
  *
  * Return: the property value on success, -EINVAL if the property does not
- * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
- * property data isn't large enough.
+ * exist and -EOVERFLOW if the property data isn't large enough.
  */
 static void *of_find_property_value_of_size(const struct device_node *np,
 					    const char *propname, u32 len)
@@ -481,8 +480,6 @@ static void *of_find_property_value_of_size(const struct device_node *np,
 
 	if (!prop)
 		return ERR_PTR(-EINVAL);
-	if (!prop->value)
-		return ERR_PTR(-ENODATA);
 	if (len > prop->length)
 		return ERR_PTR(-EOVERFLOW);
 
drivers/core/ofnode.c +14 -3
index 4dd2aee11ce..e4b4b352e46 100644
@@ -296,9 +296,20 @@ int ofnode_read_u32_array(ofnode node, const char *propname,
 		return of_read_u32_array(ofnode_to_np(node), propname,
 					 out_values, sz);
 	} else {
-		return fdtdec_get_int_array(gd->fdt_blob,
-					    ofnode_to_offset(node), propname,
-					    out_values, sz);
+		int ret;
+
+		ret = fdtdec_get_int_array(gd->fdt_blob,
+					   ofnode_to_offset(node), propname,
+					   out_values, sz);
+
+		/* get the error right, but space is more important in SPL */
+		if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
+			if (ret == -FDT_ERR_NOTFOUND)
+				return -EINVAL;
+			else if (ret == -FDT_ERR_BADLAYOUT)
+				return -EOVERFLOW;
+		}
+		return ret;
 	}
 }
 
include/dm/of_access.h +4 -6
index dd70b44344d..c556a18f7d9 100644
@@ -327,8 +327,7 @@ int of_read_u32(const struct device_node *np, const char *propname, u32 *outp);
  * @outp:	pointer to return value, modified only if return value is 0.
  *
  * Return:
- *   0 on success, -EINVAL if the property does not exist,
- *   -ENODATA if property does not have a value, and -EOVERFLOW if the
+ *   0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if the
  *   property data isn't large enough.
  */
 int of_read_u32_index(const struct device_node *np, const char *propname,
@@ -345,8 +344,7 @@ int of_read_u32_index(const struct device_node *np, const char *propname,
  * @outp:	pointer to return value, modified only if return value is 0.
  *
  * Return:
- *   0 on success, -EINVAL if the property does not exist,
- *   -ENODATA if property does not have a value, and -EOVERFLOW if the
+ *   0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if the
  *   property data isn't large enough.
  */
 int of_read_u64(const struct device_node *np, const char *propname, u64 *outp);
@@ -362,8 +360,8 @@ int of_read_u64(const struct device_node *np, const char *propname, u64 *outp);
  * @out_values:	pointer to return value, modified only if return value is 0.
  * @sz:		number of array elements to read
  * Return:
- *   0 on success, -EINVAL if the property does not exist, -ENODATA
- *   if property does not have a value, and -EOVERFLOW is longer than sz.
+ *   0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if
+ *   longer than sz.
  */
 int of_read_u32_array(const struct device_node *np, const char *propname,
 		      u32 *out_values, size_t sz);
include/dm/ofnode.h +4 -4
index a674d7d8fd6..8b0a1087062 100644
@@ -373,12 +373,12 @@ const char *ofnode_read_string(ofnode node, const char *propname);
  * @propname:	name of the property to read
  * @out_values:	pointer to return value, modified only if return value is 0
  * @sz:		number of array elements to read
- * Return: 0 if OK, -ve on error
+ * Return: 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough
  *
  * Search for a property in a device node and read 32-bit value(s) from
- * it. Returns 0 on success, -EINVAL if the property does not exist,
- * -ENODATA if property does not have a value, and -EOVERFLOW if the
- * property data isn't large enough.
+ * it.
  *
  * The out_values is modified only if a valid u32 value can be decoded.
  */
test/dm/ofnode.c +102 -0

127 lines not on this page · raw message

Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
#1 lore raw
Quoted 7 lines · Simon Glass

The current tests do not cover all the behaviour. Add some more.

Tidy up a few inconsistencies between livetree and flattree which come to light with these tests. Also drop the -ENODATA error since it is never actually returned.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom