Skip to contentSkip to conversation

selftests/mm: close fd on write error

PATCH Applied Wei Yang 4 participants 6 messages May 20 – May 24

Subsystems (4)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 selftests/mm: close fd on write error

When create_pagecache_thp_and_fd() write returns error on /proc/sys/vm/dropcache, it just "goto err_out_unlink", which left fd still open.

Use "goto err_out_close" to close the fd.

---
 tools/testing/selftests/mm/split_huge_page_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/mm/split_huge_page_test.c +1 -1
index 460fa1f606fd..f30402ece608 100644
@@ -469,7 +469,7 @@ static int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size,
 	}
 	if (write(*fd, "3", 1) != 1) {
 		ksft_perror("write to drop_caches");
-		goto err_out_unlink;
+		goto err_out_close;
 	}
 	close(*fd);
 
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Wei Yang

When create_pagecache_thp_and_fd() write returns error on /proc/sys/vm/dropcache, it just "goto err_out_unlink", which left fd still open.

Use "goto err_out_close" to close the fd.

---
 tools/testing/selftests/mm/split_huge_page_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/mm/split_huge_page_test.c +0 -0
index 460fa1f606fd..f30402ece608 100644

tools/testing/selftests/mm/split_huge_page_test.c static int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, · line 474

Quoted 7 lines
tools/testing/selftests/mm/split_huge_page_test.c +1 -1
@@ -469,7 +469,7 @@ static int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size,
 	}
 	if (write(*fd, "3", 1) != 1) {
 		ksft_perror("write to drop_caches");
-		goto err_out_unlink;
+		goto err_out_close;
 	}
 	close(*fd);

LGTM

I asked AI and it points to another problem:

for (i = 0; i < nr_thps; i++) {
	if (is_backed_by_folio(page_area + i * pagesize, 0,
			       pagemap_fd, kpageflags_fd))
		continue;
	ksft_test_result_fail("THP %zu not split\n", i);
}

ksft_test_result_pass("Split PTE-mapped huge pages successful\n");

"If one THP is not split, it prints FAIL, but then falls through and also prints PASS.

It should probably jump to out after the failure".

Quoted 1 line
author
#2 lore raw
Quoted 41 lines · Dev Jain
Quoted 16 lines · Wei Yang

When create_pagecache_thp_and_fd() write returns error on /proc/sys/vm/dropcache, it just "goto err_out_unlink", which left fd still open.

Use "goto err_out_close" to close the fd.

---
 tools/testing/selftests/mm/split_huge_page_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/mm/split_huge_page_test.c +0 -0
index 460fa1f606fd..f30402ece608 100644

tools/testing/selftests/mm/split_huge_page_test.c static int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, · line 474

Quoted 7 lines
tools/testing/selftests/mm/split_huge_page_test.c +1 -1
@@ -469,7 +469,7 @@ static int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size,
 	}
 	if (write(*fd, "3", 1) != 1) {
 		ksft_perror("write to drop_caches");
-		goto err_out_unlink;
+		goto err_out_close;
 	}
 	close(*fd);

LGTM

I asked AI and it points to another problem:

for (i = 0; i < nr_thps; i++) {
	if (is_backed_by_folio(page_area + i * pagesize, 0,
			       pagemap_fd, kpageflags_fd))
		continue;
	ksft_test_result_fail("THP %zu not split\n", i);
}
Quoted 6 lines

ksft_test_result_pass("Split PTE-mapped huge pages successful\n");

"If one THP is not split, it prints FAIL, but then falls through and also prints PASS.

It should probably jump to out after the failure".

Thanks for AI.

It looks we should "goto out" after ksft_test_result_fail().

Signature · 2 lines
Wei Yang
Help you, Help me
maintainer
#3 lore raw
Quoted 3 lines · On Wed, 20 May 2026 09:38:24 +0000 Wei Yang <[email protected]> wrote:

Subject: [PATCH] selftests/mm: close fd on write error

selftest/mm is a big place nowadays. I'll rewrite this to "selftests/mm/split_huge_page_test.c: ...".

Quoted 9 lines
Quoted 9 lines

I asked AI and it points to another problem:

for (i = 0; i < nr_thps; i++) {
	if (is_backed_by_folio(page_area + i * pagesize, 0,
			       pagemap_fd, kpageflags_fd))
		continue;
	ksft_test_result_fail("THP %zu not split\n", i);
}
Quoted 6 lines
Quoted 6 lines

ksft_test_result_pass("Split PTE-mapped huge pages successful\n");

"If one THP is not split, it prints FAIL, but then falls through and also prints PASS.

It should probably jump to out after the failure".

https://sashiko.dev/#/patchset/[email protected]
doesn't say this?

Quoted 3 lines

Thanks for AI.

It looks we should "goto out" after ksft_test_result_fail().

I'll assume that's a separate patch.

author
#4 lore raw
Quoted 8 lines · Andrew Morton
Quoted 3 lines · On Wed, 20 May 2026 09:38:24 +0000 Wei Yang <[email protected]> wrote:

Subject: [PATCH] selftests/mm: close fd on write error

selftest/mm is a big place nowadays. I'll rewrite this to "selftests/mm/split_huge_page_test.c: ...".

Thanks, will do similar in future work.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

I asked AI and it points to another problem:

for (i = 0; i < nr_thps; i++) {
	if (is_backed_by_folio(page_area + i * pagesize, 0,
			       pagemap_fd, kpageflags_fd))
		continue;
	ksft_test_result_fail("THP %zu not split\n", i);
}

ksft_test_result_pass("Split PTE-mapped huge pages successful\n");

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

"If one THP is not split, it prints FAIL, but then falls through and also prints PASS.

It should probably jump to out after the failure".

https://sashiko.dev/#/patchset/[email protected]
doesn't say this?

I took a look into the above link, but not see any comment.

Not sure I got it clearly?

Quoted 6 lines
Quoted 4 lines

Thanks for AI.

It looks we should "goto out" after ksft_test_result_fail().

I'll assume that's a separate patch.

Agree.

The credit belongs to @Dev. Not sure I should send the fix.

Signature · 2 lines
Wei Yang
Help you, Help me