[PATCH 04/16] selftests/mm: Fix type mismatch warnings

Muhammad Usama Anjum
2025-01-09T17:39:26Z

Fix type mismatch warnings in different tests.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
tools/testing/selftests/mm/compaction_test.c | 2 +-
tools/testing/selftests/mm/gup_longterm.c | 3 ++-
tools/testing/selftests/mm/hugetlb_dio.c | 2 +-
tools/testing/selftests/mm/hugetlb_fault_after_madv.c | 2 +-
tools/testing/selftests/mm/hugetlb_madv_vs_map.c | 2 +-
tools/testing/selftests/mm/ksm_functional_tests.c | 6 +++---
tools/testing/selftests/mm/mlock-random-test.c | 4 ++--
tools/testing/selftests/mm/pkey_sighandler_tests.c | 2 +-
tools/testing/selftests/mm/soft-dirty.c | 2 +-
9 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c
index 8d23b698ce9db..f6f32a5732e9e 100644
--- a/tools/testing/selftests/mm/compaction_test.c
+++ b/tools/testing/selftests/mm/compaction_test.c
@@ -134,7 +134,7 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
lseek(fd, 0, SEEK_SET);

if (write(fd, init_nr_hugepages, strlen(init_nr_hugepages))
- != strlen(init_nr_hugepages)) {
+ != (signed long int)strlen(init_nr_hugepages)) {
ksft_print_msg("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n",
strerror(errno));
goto close_fd;
diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c
index 03a31dcb57577..7f1b4ad7fcaec 100644
--- a/tools/testing/selftests/mm/gup_longterm.c
+++ b/tools/testing/selftests/mm/gup_longterm.c
@@ -446,7 +446,8 @@ static int tests_per_test_case(void)

int main(void)
{
- int i, err;
+ unsigned int i;
+ int err;

pagesize = getpagesize();
nr_hugetlbsizes = detect_hugetlb_page_sizes(hugetlbsizes,
diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
index db63abe5ee5e8..62f368d4c8c16 100644
--- a/tools/testing/selftests/mm/hugetlb_dio.c
+++ b/tools/testing/selftests/mm/hugetlb_dio.c
@@ -63,7 +63,7 @@ void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
memset(buffer, 'A', writesize);

/* Write the buffer to the file */
- if (write(fd, buffer, writesize) != (writesize)) {
+ if (write(fd, buffer, writesize) != (signed int)writesize) {
munmap(orig_buffer, h_pagesize);
close(fd);
ksft_exit_fail_perror("Error writing to file\n");
diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
index e62f4e1388f26..2b5acb13ee0be 100644
--- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
+++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c
@@ -88,7 +88,7 @@ int main(void)
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
-1, 0);

- if ((unsigned long)huge_ptr == -1)
+ if (huge_ptr == MAP_FAILED)
ksft_exit_skip("Failed to allocated huge page\n");

pthread_create(&thread1, NULL, madv, NULL);
diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
index 6c326cf3dcf6b..eda38b63e9e8d 100644
--- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
+++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
@@ -100,7 +100,7 @@ int main(void)
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
-1, 0);

- if ((unsigned long)huge_ptr == -1) {
+ if (huge_ptr == MAP_FAILED) {
ksft_test_result_fail("Failed to allocate huge page\n");
return KSFT_FAIL;
}
diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
index 66b4e111b5a27..4f96126e4e1f9 100644
--- a/tools/testing/selftests/mm/ksm_functional_tests.c
+++ b/tools/testing/selftests/mm/ksm_functional_tests.c
@@ -306,7 +306,7 @@ static void test_unmerge_zero_pages(void)

/* Check if ksm_zero_pages is updated correctly after KSM merging */
pages_expected = size / pagesize;
- if (pages_expected != get_my_ksm_zero_pages()) {
+ if ((signed long)pages_expected != get_my_ksm_zero_pages()) {
ksft_test_result_fail("'ksm_zero_pages' updated after merging\n");
goto unmap;
}
@@ -319,7 +319,7 @@ static void test_unmerge_zero_pages(void)

/* Check if ksm_zero_pages is updated correctly after unmerging */
pages_expected /= 2;
- if (pages_expected != get_my_ksm_zero_pages()) {
+ if ((signed long)pages_expected != get_my_ksm_zero_pages()) {
ksft_test_result_fail("'ksm_zero_pages' updated after unmerging\n");
goto unmap;
}
@@ -625,7 +625,7 @@ static void test_prot_none(void)
{
const unsigned int size = 2 * MiB;
char *map;
- int i;
+ unsigned int i;

ksft_print_msg("[RUN] %s\n", __func__);

diff --git a/tools/testing/selftests/mm/mlock-random-test.c b/tools/testing/selftests/mm/mlock-random-test.c
index 0d95d630d0450..f410699458f2a 100644
--- a/tools/testing/selftests/mm/mlock-random-test.c
+++ b/tools/testing/selftests/mm/mlock-random-test.c
@@ -138,7 +138,7 @@ static void test_mlock_within_limit(char *p, int alloc_size)
int page_size = 0;

getrlimit(RLIMIT_MEMLOCK, &cur);
- if (cur.rlim_cur < alloc_size)
+ if (cur.rlim_cur < (unsigned int)alloc_size)
ksft_exit_fail_msg("alloc_size[%d] < %u rlimit,lead to mlock failure\n",
alloc_size, (unsigned int)cur.rlim_cur);

@@ -204,7 +204,7 @@ static void test_mlock_outof_limit(char *p, int alloc_size)
struct rlimit cur;

getrlimit(RLIMIT_MEMLOCK, &cur);
- if (cur.rlim_cur >= alloc_size)
+ if (cur.rlim_cur >= (unsigned int)alloc_size)
ksft_exit_fail_msg("alloc_size[%d] >%u rlimit, violates test condition\n",
alloc_size, (unsigned int)cur.rlim_cur);

diff --git a/tools/testing/selftests/mm/pkey_sighandler_tests.c b/tools/testing/selftests/mm/pkey_sighandler_tests.c
index cd46528d6c215..89c0f4e090374 100644
--- a/tools/testing/selftests/mm/pkey_sighandler_tests.c
+++ b/tools/testing/selftests/mm/pkey_sighandler_tests.c
@@ -535,7 +535,7 @@ static void (*pkey_tests[])(void) = {

int main(void)
{
- int i;
+ unsigned int i;

ksft_print_header();
ksft_set_plan(ARRAY_SIZE(pkey_tests));
diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c
index b6eb5c4642ce5..68edb2475ccd4 100644
--- a/tools/testing/selftests/mm/soft-dirty.c
+++ b/tools/testing/selftests/mm/soft-dirty.c
@@ -77,7 +77,7 @@ static void test_vma_reuse(int pagemap_fd, int pagesize)
static void test_hugepage(int pagemap_fd)
{
char *map;
- int i, ret;
+ unsigned int i, ret;
size_t hpage_len = read_pmd_pagesize();

if (!hpage_len)
--
2.39.5