linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/mm/ksm_functional: prevent unmapping undefined address
@ 2024-01-05 20:24 JP Kobryn
  2024-01-07 20:42 ` David Hildenbrand
  0 siblings, 1 reply; 2+ messages in thread
From: JP Kobryn @ 2024-01-05 20:24 UTC (permalink / raw)
  To: linux-mm, david, akpm

Replace some goto statements with return statements so that unmap() is
not called on an undefined address. This change is made so that unmap()
can only be reached after mmap() is called (and the address mentioned is
defined). Returning MAP_FAILED seems acceptable since client code checks
for this value.

Fixes: 42096aa24b82 ("selftest/mm: ksm_functional_tests: test in mmap_and_merge_range() if anything got merged")
Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
---
 tools/testing/selftests/mm/ksm_functional_tests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
index fbff0dd09191..d615767e396b 100644
--- a/tools/testing/selftests/mm/ksm_functional_tests.c
+++ b/tools/testing/selftests/mm/ksm_functional_tests.c
@@ -155,12 +155,12 @@ static char *mmap_and_merge_range(char val, unsigned long size, int prot,
 	/* Stabilize accounting by disabling KSM completely. */
 	if (ksm_unmerge()) {
 		ksft_test_result_fail("Disabling (unmerging) KSM failed\n");
-		goto unmap;
+		return MAP_FAILED;
 	}
 
 	if (get_my_merging_pages() > 0) {
 		ksft_test_result_fail("Still pages merged\n");
-		goto unmap;
+		return MAP_FAILED;
 	}
 
 	map = mmap(NULL, size, PROT_READ|PROT_WRITE,
-- 
2.43.0



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

* Re: [PATCH] selftests/mm/ksm_functional: prevent unmapping undefined address
  2024-01-05 20:24 [PATCH] selftests/mm/ksm_functional: prevent unmapping undefined address JP Kobryn
@ 2024-01-07 20:42 ` David Hildenbrand
  0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2024-01-07 20:42 UTC (permalink / raw)
  To: JP Kobryn, linux-mm, akpm

On 05.01.24 21:24, JP Kobryn wrote:
> Replace some goto statements with return statements so that unmap() is
> not called on an undefined address. This change is made so that unmap()
> can only be reached after mmap() is called (and the address mentioned is
> defined). Returning MAP_FAILED seems acceptable since client code checks
> for this value.
> 
> Fixes: 42096aa24b82 ("selftest/mm: ksm_functional_tests: test in mmap_and_merge_range() if anything got merged")
> Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
> ---
>   tools/testing/selftests/mm/ksm_functional_tests.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> index fbff0dd09191..d615767e396b 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -155,12 +155,12 @@ static char *mmap_and_merge_range(char val, unsigned long size, int prot,
>   	/* Stabilize accounting by disabling KSM completely. */
>   	if (ksm_unmerge()) {
>   		ksft_test_result_fail("Disabling (unmerging) KSM failed\n");
> -		goto unmap;
> +		return MAP_FAILED;
>   	}
>   
>   	if (get_my_merging_pages() > 0) {
>   		ksft_test_result_fail("Still pages merged\n");
> -		goto unmap;
> +		return MAP_FAILED;
>   	}
>   
>   	map = mmap(NULL, size, PROT_READ|PROT_WRITE,

Indeed, thanks.

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



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

end of thread, other threads:[~2024-01-07 20:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-05 20:24 [PATCH] selftests/mm/ksm_functional: prevent unmapping undefined address JP Kobryn
2024-01-07 20:42 ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox