diff mbox series

dm: update test on of_offset in ofnode_valid

Message ID 20200924152621.1317-1-patrick.delaunay@st.com
State Accepted
Commit 6d9949fe866751c527c5dafab5350af89b7b8332
Delegated to: Simon Glass
Headers show
Series dm: update test on of_offset in ofnode_valid | expand

Commit Message

Patrick DELAUNAY Sept. 24, 2020, 3:26 p.m. UTC
Update the test for node.of_offset because an invalid offset is not
always set to -1 because the return value of the libfdt functions are:
+ an error with a value < 0
+ a valid offset with value >=0

For example, in ofnode_get_by_phandle() function, we have:
node.of_offset = fdt_node_offset_by_phandle(gd->fdt_blob, phandle);
and this function can return -FDT_ERR_BADPHANDLE (-6).

Without this patch, the added test dm_test_ofnode_get_by_phandle failed.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

 include/dm/ofnode.h |  2 +-
 test/dm/ofnode.c    | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

Comments

Simon Glass Sept. 24, 2020, 6:54 p.m. UTC | #1
On Thu, 24 Sep 2020 at 09:26, Patrick Delaunay <patrick.delaunay@st.com> wrote:
>
> Update the test for node.of_offset because an invalid offset is not
> always set to -1 because the return value of the libfdt functions are:
> + an error with a value < 0
> + a valid offset with value >=0
>
> For example, in ofnode_get_by_phandle() function, we have:
> node.of_offset = fdt_node_offset_by_phandle(gd->fdt_blob, phandle);
> and this function can return -FDT_ERR_BADPHANDLE (-6).
>
> Without this patch, the added test dm_test_ofnode_get_by_phandle failed.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>
>  include/dm/ofnode.h |  2 +-
>  test/dm/ofnode.c    | 16 ++++++++++++++++
>  2 files changed, 17 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass Oct. 5, 2020, 9:32 p.m. UTC | #2
On Thu, 24 Sep 2020 at 09:26, Patrick Delaunay <patrick.delaunay@st.com> wrote:
>
> Update the test for node.of_offset because an invalid offset is not
> always set to -1 because the return value of the libfdt functions are:
> + an error with a value < 0
> + a valid offset with value >=0
>
> For example, in ofnode_get_by_phandle() function, we have:
> node.of_offset = fdt_node_offset_by_phandle(gd->fdt_blob, phandle);
> and this function can return -FDT_ERR_BADPHANDLE (-6).
>
> Without this patch, the added test dm_test_ofnode_get_by_phandle failed.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>
>  include/dm/ofnode.h |  2 +-
>  test/dm/ofnode.c    | 16 ++++++++++++++++
>  2 files changed, 17 insertions(+), 1 deletion(-)

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

Applied to u-boot-dm/next, thanks!
diff mbox series

Patch

diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 8df2facf99..ef3ac7f329 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -127,7 +127,7 @@  static inline bool ofnode_valid(ofnode node)
 	if (of_live_active())
 		return node.np != NULL;
 	else
-		return node.of_offset != -1;
+		return node.of_offset >= 0;
 }
 
 /**
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 8bfb706602..4ae8d281a7 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -19,6 +19,22 @@  static int dm_test_ofnode_compatible(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_ofnode_compatible, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+static int dm_test_ofnode_get_by_phandle(struct unit_test_state *uts)
+{
+	/* test invalid phandle */
+	ut_assert(!ofnode_valid(ofnode_get_by_phandle(0)));
+	ut_assert(!ofnode_valid(ofnode_get_by_phandle(-1)));
+
+	/* test first valid phandle */
+	ut_assert(ofnode_valid(ofnode_get_by_phandle(1)));
+
+	/* test unknown phandle */
+	ut_assert(!ofnode_valid(ofnode_get_by_phandle(0x1000000)));
+
+	return 0;
+}
+DM_TEST(dm_test_ofnode_get_by_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 static int dm_test_ofnode_by_prop_value(struct unit_test_state *uts)
 {
 	const char propname[] = "compatible";