Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/mm/ksm_functional: prevent unmapping undefined address

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.

Link: https://lkml.kernel.org/r/20240105202401.28851-1-inwardvessel@gmail.com
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>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

JP Kobryn and committed by
Andrew Morton
3956570e 6212eb4d

+2 -2
+2 -2
tools/testing/selftests/mm/ksm_functional_tests.c
··· 155 155 /* Stabilize accounting by disabling KSM completely. */ 156 156 if (ksm_unmerge()) { 157 157 ksft_test_result_fail("Disabling (unmerging) KSM failed\n"); 158 - goto unmap; 158 + return MAP_FAILED; 159 159 } 160 160 161 161 if (get_my_merging_pages() > 0) { 162 162 ksft_test_result_fail("Still pages merged\n"); 163 - goto unmap; 163 + return MAP_FAILED; 164 164 } 165 165 166 166 map = mmap(NULL, size, PROT_READ|PROT_WRITE,