Commit e1e13262 authored by Dev Jain's avatar Dev Jain Committed by Andrew Morton

selftests/mm: mremap_test: use sscanf to parse /proc/self/maps

Enforce consistency across files by avoiding two separate functions to
parse /proc/self/maps, replacing them with a simple sscanf().

Link: https://lkml.kernel.org/r/20240330173557.2697684-4-dev.jain@arm.comSigned-off-by: default avatarDev Jain <dev.jain@arm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Kalesh Singh <kaleshsingh@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 7033c6cc
...@@ -148,19 +148,21 @@ static unsigned long long get_mmap_min_addr(void) ...@@ -148,19 +148,21 @@ static unsigned long long get_mmap_min_addr(void)
* Using /proc/self/maps, assert that the specified address range is contained * Using /proc/self/maps, assert that the specified address range is contained
* within a single mapping. * within a single mapping.
*/ */
static bool is_range_mapped(FILE *maps_fp, void *start, void *end) static bool is_range_mapped(FILE *maps_fp, unsigned long start,
unsigned long end)
{ {
char *line = NULL; char *line = NULL;
size_t len = 0; size_t len = 0;
bool success = false; bool success = false;
unsigned long first_val, second_val;
rewind(maps_fp); rewind(maps_fp);
while (getline(&line, &len, maps_fp) != -1) { while (getline(&line, &len, maps_fp) != -1) {
char *first = strtok(line, "- "); if (sscanf(line, "%lx-%lx", &first_val, &second_val) != 2) {
void *first_val = (void *)strtol(first, NULL, 16); ksft_exit_fail_msg("cannot parse /proc/self/maps\n");
char *second = strtok(NULL, "- "); break;
void *second_val = (void *) strtol(second, NULL, 16); }
if (first_val <= start && second_val >= end) { if (first_val <= start && second_val >= end) {
success = true; success = true;
...@@ -255,7 +257,8 @@ static void mremap_expand_merge(FILE *maps_fp, unsigned long page_size) ...@@ -255,7 +257,8 @@ static void mremap_expand_merge(FILE *maps_fp, unsigned long page_size)
goto out; goto out;
} }
success = is_range_mapped(maps_fp, start, start + 3 * page_size); success = is_range_mapped(maps_fp, (unsigned long)start,
(unsigned long)(start + 3 * page_size));
munmap(start, 3 * page_size); munmap(start, 3 * page_size);
out: out:
...@@ -294,7 +297,8 @@ static void mremap_expand_merge_offset(FILE *maps_fp, unsigned long page_size) ...@@ -294,7 +297,8 @@ static void mremap_expand_merge_offset(FILE *maps_fp, unsigned long page_size)
goto out; goto out;
} }
success = is_range_mapped(maps_fp, start, start + 3 * page_size); success = is_range_mapped(maps_fp, (unsigned long)start,
(unsigned long)(start + 3 * page_size));
munmap(start, 3 * page_size); munmap(start, 3 * page_size);
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment