linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: memcg: uninitialized variable in test_memcg_reclaim()
@ 2022-07-19  9:46 Dan Carpenter
  2022-07-19 17:27 ` Yosry Ahmed
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2022-07-19  9:46 UTC (permalink / raw)
  To: Yosry Ahmed
  Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
	Muchun Song, Tejun Heo, Zefan Li, Shuah Khan, David Rientjes,
	Andrew Morton, cgroups, linux-mm, linux-kselftest,
	kernel-janitors

The "fd" is used on the clean up path without ever being initialized.

Fixes: eae3cb2e87ff ("selftests: cgroup: add a selftest for memory.reclaim")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
I kind of went over kill on fixing this as if it were real code which
matters.  :P

 .../selftests/cgroup/test_memcontrol.c        | 23 +++++++++++--------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
index 8833359556f3..08681699c2f9 100644
--- a/tools/testing/selftests/cgroup/test_memcontrol.c
+++ b/tools/testing/selftests/cgroup/test_memcontrol.c
@@ -658,18 +658,18 @@ static int test_memcg_reclaim(const char *root)
 
 	memcg = cg_name(root, "memcg_test");
 	if (!memcg)
-		goto cleanup;
+		return KSFT_FAIL;
 
 	if (cg_create(memcg))
-		goto cleanup;
+		goto free_memcg;
 
 	current = cg_read_long(memcg, "memory.current");
 	if (current != 0)
-		goto cleanup;
+		goto destroy_memcg;
 
 	fd = get_temp_fd();
 	if (fd < 0)
-		goto cleanup;
+		goto destroy_memcg;
 
 	cg_run_nowait(memcg, alloc_pagecache_50M_noexit, (void *)(long)fd);
 
@@ -697,7 +697,7 @@ static int test_memcg_reclaim(const char *root)
 			fprintf(stderr,
 				"failed to allocate %ld for memcg reclaim test\n",
 				expected_usage);
-			goto cleanup;
+			goto close;
 		}
 	}
 
@@ -717,7 +717,7 @@ static int test_memcg_reclaim(const char *root)
 		 * not reclaim the full amount.
 		 */
 		if (to_reclaim <= 0)
-			goto cleanup;
+			goto close;
 
 
 		snprintf(buf, sizeof(buf), "%ld", to_reclaim);
@@ -729,7 +729,7 @@ static int test_memcg_reclaim(const char *root)
 			 */
 			current = cg_read_long(memcg, "memory.current");
 			if (!values_close(current, MB(30), 3) && current > MB(30))
-				goto cleanup;
+				goto close;
 			break;
 		}
 
@@ -738,14 +738,17 @@ static int test_memcg_reclaim(const char *root)
 			continue;
 
 		/* We got an unexpected error or ran out of retries. */
-		goto cleanup;
+		goto close;
 	}
 
 	ret = KSFT_PASS;
-cleanup:
+
+close:
+	close(fd);
+destroy_memcg:
 	cg_destroy(memcg);
+free_memcg:
 	free(memcg);
-	close(fd);
 
 	return ret;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-20 17:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19  9:46 [PATCH] selftests: memcg: uninitialized variable in test_memcg_reclaim() Dan Carpenter
2022-07-19 17:27 ` Yosry Ahmed
2022-07-20  9:29   ` Dan Carpenter
2022-07-20 17:35     ` Yosry Ahmed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).