From: Andrew Scull <ascull@google.com>
Date: Sun, 3 Apr 2022 10:39:15 +0000 (+0000)
Subject: test: dm: devres: Remove use-after-free
X-Git-Tag: v2025.01-rc5-pxa1908~1427^2
X-Git-Url: http://git.dujemihanovic.xyz/img/html/static/gitweb.css?a=commitdiff_plain;h=d69616e529560ace8cdf40bda91464a88c7ff43a;p=u-boot.git

test: dm: devres: Remove use-after-free

Use-after-free shouldn't be used, even in tests. It's bad practice and
makes the test brittle.

Signed-off-by: Andrew Scull <ascull@google.com>
Cc: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

diff --git a/test/dm/devres.c b/test/dm/devres.c
index 4f959d11da..524114c833 100644
--- a/test/dm/devres.c
+++ b/test/dm/devres.c
@@ -178,11 +178,8 @@ static int dm_test_devres_phase(struct unit_test_state *uts)
 	ut_asserteq(1, stats.allocs);
 	ut_asserteq(TEST_DEVRES_SIZE, stats.total_size);
 
-	/* Unbinding removes the other. Note this access a freed pointer */
+	/* Unbinding removes the other. */
 	device_unbind(dev);
-	devres_get_stats(dev, &stats);
-	ut_asserteq(0, stats.allocs);
-	ut_asserteq(0, stats.total_size);
 
 	return 0;
 }