[U-Boot] [PATCH 1/1] test: overlay: NULL passed as fdt

Heinrich Schuchardt xypron.glpk at gmx.de
Sat Dec 8 08:53:05 UTC 2018


The uts created in do_ut_overlay() is not the one used in
cmd_ut_category(). Currently all tests are therefore called with
uts->priv = NULL and fail.

Using a static variable is the easiest fix here.

Fixes: e93232e15ec9 ("test: overlay: Use cmd_ut_category()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 test/overlay/cmd_ut_overlay.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/test/overlay/cmd_ut_overlay.c b/test/overlay/cmd_ut_overlay.c
index 3d34c8ab53a..fc2491d0b47 100644
--- a/test/overlay/cmd_ut_overlay.c
+++ b/test/overlay/cmd_ut_overlay.c
@@ -23,6 +23,8 @@ extern u32 __dtb_test_fdt_base_begin;
 extern u32 __dtb_test_fdt_overlay_begin;
 extern u32 __dtb_test_fdt_overlay_stacked_begin;
 
+static void *fdt;
+
 static int ut_fdt_getprop_u32_by_index(void *fdt, const char *path,
 				    const char *name, int index,
 				    u32 *out)
@@ -67,7 +69,6 @@ static int fdt_getprop_str(void *fdt, const char *path, const char *name,
 
 static int fdt_overlay_change_int_property(struct unit_test_state *uts)
 {
-	void *fdt = uts->priv;
 	u32 val = 0;
 
 	ut_assertok(ut_fdt_getprop_u32(fdt, "/test-node", "test-int-property",
@@ -80,7 +81,6 @@ OVERLAY_TEST(fdt_overlay_change_int_property, 0);
 
 static int fdt_overlay_change_str_property(struct unit_test_state *uts)
 {
-	void *fdt = uts->priv;
 	const char *val = NULL;
 
 	ut_assertok(fdt_getprop_str(fdt, "/test-node", "test-str-property",
@@ -93,7 +93,6 @@ OVERLAY_TEST(fdt_overlay_change_str_property, 0);
 
 static int fdt_overlay_add_str_property(struct unit_test_state *uts)
 {
-	void *fdt = uts->priv;
 	const char *val = NULL;
 
 	ut_assertok(fdt_getprop_str(fdt, "/test-node", "test-str-property-2",
@@ -106,7 +105,6 @@ OVERLAY_TEST(fdt_overlay_add_str_property, 0);
 
 static int fdt_overlay_add_node_by_phandle(struct unit_test_state *uts)
 {
-	void *fdt = uts->priv;
 	int off;
 
 	off = fdt_path_offset(fdt, "/test-node/new-node");
@@ -120,7 +118,6 @@ OVERLAY_TEST(fdt_overlay_add_node_by_phandle, 0);
 
 static int fdt_overlay_add_node_by_path(struct unit_test_state *uts)
 {
-	void *fdt = uts->priv;
 	int off;
 
 	off = fdt_path_offset(fdt, "/new-node");
@@ -134,7 +131,6 @@ OVERLAY_TEST(fdt_overlay_add_node_by_path, 0);
 
 static int fdt_overlay_add_subnode_property(struct unit_test_state *uts)
 {
-	void *fdt = uts->priv;
 	int off;
 
 	off = fdt_path_offset(fdt, "/test-node/sub-test-node");
@@ -150,7 +146,6 @@ OVERLAY_TEST(fdt_overlay_add_subnode_property, 0);
 static int fdt_overlay_local_phandle(struct unit_test_state *uts)
 {
 	uint32_t local_phandle;
-	void *fdt = uts->priv;
 	u32 val = 0;
 	int off;
 
@@ -175,7 +170,6 @@ OVERLAY_TEST(fdt_overlay_local_phandle, 0);
 static int fdt_overlay_local_phandles(struct unit_test_state *uts)
 {
 	uint32_t local_phandle, test_phandle;
-	void *fdt = uts->priv;
 	u32 val = 0;
 	int off;
 
@@ -205,7 +199,6 @@ OVERLAY_TEST(fdt_overlay_local_phandles, 0);
 
 static int fdt_overlay_stacked(struct unit_test_state *uts)
 {
-	void *fdt = uts->priv;
 	u32 val = 0;
 
 	ut_assertok(ut_fdt_getprop_u32(fdt, "/new-local-node",
@@ -225,7 +218,7 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	void *fdt_base = &__dtb_test_fdt_base_begin;
 	void *fdt_overlay = &__dtb_test_fdt_overlay_begin;
 	void *fdt_overlay_stacked = &__dtb_test_fdt_overlay_stacked_begin;
-	void *fdt_base_copy, *fdt_overlay_copy, *fdt_overlay_stacked_copy;
+	void *fdt_overlay_copy, *fdt_overlay_stacked_copy;
 	int ret = -ENOMEM;
 
 	uts = calloc(1, sizeof(*uts));
@@ -235,10 +228,9 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	ut_assertok(fdt_check_header(fdt_base));
 	ut_assertok(fdt_check_header(fdt_overlay));
 
-	fdt_base_copy = malloc(FDT_COPY_SIZE);
-	if (!fdt_base_copy)
+	fdt = malloc(FDT_COPY_SIZE);
+	if (!fdt)
 		goto err1;
-	uts->priv = fdt_base_copy;
 
 	fdt_overlay_copy = malloc(FDT_COPY_SIZE);
 	if (!fdt_overlay_copy)
@@ -254,7 +246,7 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	 * (and relocate it since the memory might be mapped
 	 * read-only)
 	 */
-	ut_assertok(fdt_open_into(fdt_base, fdt_base_copy, FDT_COPY_SIZE));
+	ut_assertok(fdt_open_into(fdt_base, fdt, FDT_COPY_SIZE));
 
 	/*
 	 * Resize the overlay to 4k so that we have room to operate on
@@ -275,10 +267,10 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 				  FDT_COPY_SIZE));
 
 	/* Apply the overlay */
-	ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_copy));
+	ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_copy));
 
 	/* Apply the stacked overlay */
-	ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_stacked_copy));
+	ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_stacked_copy));
 
 	ret = cmd_ut_category("overlay", tests, n_ents, argc, argv);
 
@@ -286,9 +278,7 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 err3:
 	free(fdt_overlay_copy);
 err2:
-	free(fdt_base_copy);
+	free(fdt);
 err1:
-	free(uts);
-
 	return ret;
 }
-- 
2.19.2



More information about the U-Boot mailing list