diff options
| author | Dan Carpenter <[email protected]> | 2024-08-09 12:32:30 +0000 |
|---|---|---|
| committer | Andrew Morton <[email protected]> | 2024-08-16 05:16:15 +0000 |
| commit | af3b7d09a9934220a8136065a0e6985fe0b67a1b (patch) | |
| tree | a94088eb6c3bd235e633cc90c5f0e404b7b77c34 | |
| parent | mm/numa: no task_numa_fault() call if PMD is changed (diff) | |
| download | kernel-af3b7d09a9934220a8136065a0e6985fe0b67a1b.tar.gz kernel-af3b7d09a9934220a8136065a0e6985fe0b67a1b.zip | |
selftests/mm: compaction_test: fix off by one in check_compaction()
The "initial_nr_hugepages" variable is unsigned long so it takes up to 20
characters to print, plus 1 more character for the NUL terminator.
Unfortunately, this buffer is not quite large enough for the terminator to
fit. Also use snprintf() for a belt and suspenders approach.
Link: https://lkml.kernel.org/r/[email protected]
Fixes: fb9293b6b015 ("selftests/mm: compaction_test: fix bogus test success and reduce probability of OOM-killer invocation")
Signed-off-by: Dan Carpenter <[email protected]>
Cc: Shuah Khan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
| -rw-r--r-- | tools/testing/selftests/mm/compaction_test.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c index e140558e6f53..2c3a0eb6b22d 100644 --- a/tools/testing/selftests/mm/compaction_test.c +++ b/tools/testing/selftests/mm/compaction_test.c @@ -89,9 +89,10 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size, int fd, ret = -1; int compaction_index = 0; char nr_hugepages[20] = {0}; - char init_nr_hugepages[20] = {0}; + char init_nr_hugepages[24] = {0}; - sprintf(init_nr_hugepages, "%lu", initial_nr_hugepages); + snprintf(init_nr_hugepages, sizeof(init_nr_hugepages), + "%lu", initial_nr_hugepages); /* We want to test with 80% of available memory. Else, OOM killer comes in to play */ |
