diff mbox series

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

Message ID 20210205043924.149504-5-seanga2@gmail.com
State RFC
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series spi: dw: Add support for XIP mode | expand

Commit Message

Sean Anderson Feb. 5, 2021, 4:39 a.m. UTC
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@gmail.com>
---

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

Comments

Simon Glass Feb. 7, 2021, 2:37 p.m. UTC | #1
On Thu, 4 Feb 2021 at 21:39, Sean Anderson <seanga2@gmail.com> wrote:
>
> 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@gmail.com>
> ---
>
>  drivers/core/ofnode.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

This could really use a driver model test so that both options are
automatically checked.
diff mbox series

Patch

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;
+		}
 	}
 }