lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250328220037.149763-1-siddarthsgml@gmail.com>
Date: Sat, 29 Mar 2025 03:30:37 +0530
From: Siddarth G <siddarthsgml@...il.com>
To: shuah@...nel.org
Cc: akpm@...ux-foundation.org,
	linux-kernel@...r.kernel.org,
	linux-kselftest@...r.kernel.org,
	linux-mm@...ck.org,
	Siddarth G <siddarthsgml@...il.com>,
	David Binderman <dcb314@...mail.com>
Subject: [PATCH] selftests/mm: Fix loss of information warnings

Cppcheck reported a style 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.

Changing the type of page_size from 'unsigned int' to 'unsigned long long'
was considered. But that might cause new conversion issues in other
parts of the code where calculations involving 'page_size' are assigned
to int variables. So we approach by appending ULL suffixes

Reported-by: David Binderman <dcb314@...mail.com>
Closes: https://lore.kernel.org/all/AS8PR02MB10217315060BBFDB21F19643E9CA62@AS8PR02MB10217.eurprd02.prod.outlook.com/
Signed-off-by: Siddarth G <siddarthsgml@...il.com>
---
 tools/testing/selftests/mm/pagemap_ioctl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
index 57b4bba2b45f..f3b12402ca89 100644
--- a/tools/testing/selftests/mm/pagemap_ioctl.c
+++ b/tools/testing/selftests/mm/pagemap_ioctl.c
@@ -244,7 +244,7 @@ int sanity_tests_sd(void)
 	long walk_end;
 
 	vec_size = num_pages/2;
-	mem_size = num_pages * page_size;
+	mem_size = num_pages * (long long)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 = 1050 * page_size;
+	mem_size = 1050ULL * 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 = 10000 * page_size;
+	mem_size = 10000ULL * page_size;
 	vec_size = 50;
 
 	vec = malloc(sizeof(struct page_region) * vec_size);
@@ -1058,7 +1058,7 @@ int sanity_tests(void)
 	char *tmp_buf;
 
 	/* 1. wrong operation */
-	mem_size = 10 * page_size;
+	mem_size = 10ULL * page_size;
 	vec_size = mem_size / page_size;
 
 	vec = malloc(sizeof(struct page_region) * vec_size);
@@ -1507,7 +1507,7 @@ int main(int __attribute__((unused)) argc, char *argv[])
 	sanity_tests_sd();
 
 	/* 2. Normal page testing */
-	mem_size = 10 * page_size;
+	mem_size = 10ULL * 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 = 512 * 10 * page_size;
+	mem_size = 512ULL * 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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ