[RFC PATCH 04/13] core: ofnode: Fix inconsistent returns of *_read_u32_array

Sean Anderson seanga2 at gmail.com
Fri Feb 5 05:39:14 CET 2021


The documentation for dev_read_u32_array says the return value is an errno,
but fdtdec_get_int_array returns FDT_ERRs. Convert the return values so
callers can handle errors properly.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---

 drivers/core/ofnode.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 7a5f4c0a73..c071b968d5 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -220,9 +220,18 @@ 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 err = fdtdec_get_int_array(gd->fdt_blob,
+					       ofnode_to_offset(node), propname,
+					       out_values, sz);
+
+		switch (err) {
+		case FDT_ERR_NOTFOUND:
+			return -EINVAL;
+		case FDT_ERR_BADLAYOUT:
+			return -EOVERFLOW;
+		default:
+			return 0;
+		}
 	}
 }
 
-- 
2.29.2



More information about the U-Boot mailing list