diff mbox series

[v10,1/3] test: fix test/dm/regmap.c

Message ID 20210411092158.5244-2-xypron.glpk@gmx.de
State Accepted
Commit 1b8897c63e4c4eedd55f69f9728cd49f2a1cddba
Delegated to: Tom Rini
Headers show
Series Add support for stack-protector | expand

Commit Message

Heinrich Schuchardt April 11, 2021, 9:21 a.m. UTC
regmap_read() only fills the first two bytes of val. The last two bytes are
random data from the stack. This means the test will fail randomly.

For low endian systems we could simply initialize val to 0 and get correct
results. But tests should not depend on endianness. So let's use a pointer
conversion instead.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v10:
	new patch
---
 test/dm/regmap.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

--
2.30.2

Comments

Simon Glass April 14, 2021, 7:38 p.m. UTC | #1
On Sun, 11 Apr 2021 at 10:23, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> regmap_read() only fills the first two bytes of val. The last two bytes are
> random data from the stack. This means the test will fail randomly.
>
> For low endian systems we could simply initialize val to 0 and get correct
> results. But tests should not depend on endianness. So let's use a pointer
> conversion instead.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v10:
>         new patch
> ---
>  test/dm/regmap.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini April 20, 2021, 2:21 p.m. UTC | #2
On Sun, Apr 11, 2021 at 11:21:56AM +0200, Heinrich Schuchardt wrote:

> regmap_read() only fills the first two bytes of val. The last two bytes are
> random data from the stack. This means the test will fail randomly.
> 
> For low endian systems we could simply initialize val to 0 and get correct
> results. But tests should not depend on endianness. So let's use a pointer
> conversion instead.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Reviewed-by: Simon Glass <sjg@chromium.org>

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

Patch

diff --git a/test/dm/regmap.c b/test/dm/regmap.c
index 22a293096c..372a73ca0c 100644
--- a/test/dm/regmap.c
+++ b/test/dm/regmap.c
@@ -286,7 +286,8 @@  U_BOOT_DRIVER(regmap_test) = {
 static int dm_test_devm_regmap(struct unit_test_state *uts)
 {
 	int i = 0;
-	u32 val;
+	u16 val;
+	void *valp = &val;
 	u16 pattern[REGMAP_TEST_BUF_SZ];
 	u16 *buffer;
 	struct udevice *dev;
@@ -311,7 +312,7 @@  static int dm_test_devm_regmap(struct unit_test_state *uts)
 		ut_assertok(regmap_write(priv->cfg_regmap, i, pattern[i]));
 	}
 	for (i = 0; i < REGMAP_TEST_BUF_SZ; i++) {
-		ut_assertok(regmap_read(priv->cfg_regmap, i, &val));
+		ut_assertok(regmap_read(priv->cfg_regmap, i, valp));
 		ut_asserteq(val, buffer[i]);
 		ut_asserteq(val, pattern[i]);
 	}
@@ -319,9 +320,9 @@  static int dm_test_devm_regmap(struct unit_test_state *uts)
 	ut_asserteq(-ERANGE, regmap_write(priv->cfg_regmap, REGMAP_TEST_BUF_SZ,
 					  val));
 	ut_asserteq(-ERANGE, regmap_read(priv->cfg_regmap, REGMAP_TEST_BUF_SZ,
-					 &val));
+					 valp));
 	ut_asserteq(-ERANGE, regmap_write(priv->cfg_regmap, -1, val));
-	ut_asserteq(-ERANGE, regmap_read(priv->cfg_regmap, -1, &val));
+	ut_asserteq(-ERANGE, regmap_read(priv->cfg_regmap, -1, valp));

 	return 0;
 }