mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Siddarth G <siddarthsgml@gmail.com>
To: shuah@kernel.org
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-mm@kvack.org,
	Siddarth G <siddarthsgml@gmail.com>,
	David Binderman <dcb314@hotmail.com>
Subject: [PATCH v2] selftests/mm: Convert page_size to unsigned long
Date: Sun, 30 Mar 2025 16:18:37 +0530	[thread overview]
Message-ID: <20250330104837.21360-1-siddarthsgml@gmail.com> (raw)

Cppcheck warning:
int result is assigned to long long variable. If the variable is long long
to avoid loss of information, then you have loss of information.

This patch changes the type of page_size from 'unsigned int' to
'unsigned long' instead of using ULL suffixes. Changing hpage_size to
'unsigned long' was considered, but since gethugepage() expects an int,
this change was avoided. Similarly, wp_init(), wp_free(), wp_addr_range()
are designed to accept int parameters, even though they are assigned with
long values. Future updates to these functions might be required ?

Reported-by: David Binderman <dcb314@hotmail.com>
Closes: https://lore.kernel.org/all/AS8PR02MB10217315060BBFDB21F19643E9CA62@AS8PR02MB10217.eurprd02.prod.outlook.com/

Signed-off-by: Siddarth G <siddarthsgml@gmail.com>
---
Changes since v1:
 - Instead of using ULL suffixes, converted page_size and related
   variables involving it from 'int' to 'long'

 tools/testing/selftests/mm/pagemap_ioctl.c | 24 +++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
index f3b12402ca89..fe5ae8b25ff6 100644
--- a/tools/testing/selftests/mm/pagemap_ioctl.c
+++ b/tools/testing/selftests/mm/pagemap_ioctl.c
@@ -34,7 +34,7 @@
 #define PAGEMAP "/proc/self/pagemap"
 int pagemap_fd;
 int uffd;
-unsigned int page_size;
+unsigned long page_size;
 unsigned int hpage_size;
 const char *progname;
 
@@ -184,7 +184,7 @@ void *gethugetlb_mem(int size, int *shmid)
 
 int userfaultfd_tests(void)
 {
-	int mem_size, vec_size, written, num_pages = 16;
+	long mem_size, vec_size, written, num_pages = 16;
 	char *mem, *vec;
 
 	mem_size = num_pages * page_size;
@@ -213,7 +213,7 @@ int userfaultfd_tests(void)
 	written = pagemap_ioctl(mem, mem_size, vec, 1, PM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC,
 				vec_size - 2, PAGE_IS_WRITTEN, 0, 0, PAGE_IS_WRITTEN);
 	if (written < 0)
-		ksft_exit_fail_msg("error %d %d %s\n", written, errno, strerror(errno));
+		ksft_exit_fail_msg("error %ld %d %s\n", written, errno, strerror(errno));
 
 	ksft_test_result(written == 0, "%s all new pages must not be written (dirty)\n", __func__);
 
@@ -244,7 +244,7 @@ int sanity_tests_sd(void)
 	long walk_end;
 
 	vec_size = num_pages/2;
-	mem_size = num_pages * (long long)page_size;
+	mem_size = num_pages * page_size;
 
 	vec = malloc(sizeof(struct page_region) * vec_size);
 	if (!vec)
@@ -432,7 +432,7 @@ int sanity_tests_sd(void)
 	free(vec2);
 
 	/* 8. Smaller vec */
-	mem_size = 1050ULL * page_size;
+	mem_size = 1050 * page_size;
 	vec_size = mem_size/(page_size*2);
 
 	vec = malloc(sizeof(struct page_region) * vec_size);
@@ -487,7 +487,7 @@ int sanity_tests_sd(void)
 	total_pages = 0;
 
 	/* 9. Smaller vec */
-	mem_size = 10000ULL * page_size;
+	mem_size = 10000 * page_size;
 	vec_size = 50;
 
 	vec = malloc(sizeof(struct page_region) * vec_size);
@@ -995,7 +995,7 @@ int unmapped_region_tests(void)
 {
 	void *start = (void *)0x10000000;
 	int written, len = 0x00040000;
-	int vec_size = len / page_size;
+	long vec_size = len / page_size;
 	struct page_region *vec = malloc(sizeof(struct page_region) * vec_size);
 
 	/* 1. Get written pages */
@@ -1051,14 +1051,14 @@ static void test_simple(void)
 int sanity_tests(void)
 {
 	unsigned long long mem_size, vec_size;
-	int ret, fd, i, buf_size;
+	long ret, fd, i, buf_size;
 	struct page_region *vec;
 	char *mem, *fmem;
 	struct stat sbuf;
 	char *tmp_buf;
 
 	/* 1. wrong operation */
-	mem_size = 10ULL * page_size;
+	mem_size = 10 * page_size;
 	vec_size = mem_size / page_size;
 
 	vec = malloc(sizeof(struct page_region) * vec_size);
@@ -1160,7 +1160,7 @@ int sanity_tests(void)
 
 	ret = stat(progname, &sbuf);
 	if (ret < 0)
-		ksft_exit_fail_msg("error %d %d %s\n", ret, errno, strerror(errno));
+		ksft_exit_fail_msg("error %ld %d %s\n", ret, errno, strerror(errno));
 
 	fmem = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	if (fmem == MAP_FAILED)
@@ -1507,7 +1507,7 @@ int main(int __attribute__((unused)) argc, char *argv[])
 	sanity_tests_sd();
 
 	/* 2. Normal page testing */
-	mem_size = 10ULL * page_size;
+	mem_size = 10 * page_size;
 	mem = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
 	if (mem == MAP_FAILED)
 		ksft_exit_fail_msg("error nomem\n");
@@ -1520,7 +1520,7 @@ int main(int __attribute__((unused)) argc, char *argv[])
 	munmap(mem, mem_size);
 
 	/* 3. Large page testing */
-	mem_size = 512ULL * 10 * page_size;
+	mem_size = 512 * 10 * page_size;
 	mem = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
 	if (mem == MAP_FAILED)
 		ksft_exit_fail_msg("error nomem\n");
-- 
2.43.0


                 reply	other threads:[~2025-03-30 10:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250330104837.21360-1-siddarthsgml@gmail.com \
    --to=siddarthsgml@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dcb314@hotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®