Skip to contentSkip to conversation

hugemmap: use 64-bit types

PATCH In review Edward Liaw via ltp 2 participants 2 messages Mar 21, 2023 – Mar 22, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hugemmap: use 64-bit types

Compiler throws -Wshift-count-overflow warning when compiling hugemmap13 and hugemmap14 as 32-bit. Resolve warning by using unsigned long long that is always 64-bit.

---
 .../kernel/mem/hugetlb/hugemmap/hugemmap13.c   | 10 +++++-----
 .../kernel/mem/hugetlb/hugemmap/hugemmap14.c   | 18 +++++++++---------
 2 files changed, 14 insertions(+), 14 deletions(-)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c +5 -5
index 7235c55ac..f8c36640d 100644
@@ -24,7 +24,7 @@
 
 #include "hugetlb.h"
 
-#define FOURGB (1UL << 32)
+#define FOURGB (1ULL << 32)
 #define MNTPOINT "hugetlbfs/"
 static int  fd = -1;
 static unsigned long hpage_size;
@@ -33,16 +33,16 @@ static int page_size;
 static void run_test(void)
 {
 	void *p, *q = NULL;
-	unsigned long lowaddr;
-	unsigned long below_start;
-	unsigned long above_end;
+	unsigned long long lowaddr;
+	unsigned long long below_start;
+	unsigned long long above_end;
 
 	p = mmap((void *)FOURGB, hpage_size, PROT_READ|PROT_WRITE,
 		 MAP_SHARED | MAP_FIXED, fd, 0);
 	if (p == MAP_FAILED) {
 		/* slice 0 (high) spans from 4G-1T */
 		below_start = FOURGB;
-		above_end = 1024L*1024*1024*1024;
+		above_end = 1024ULL*1024*1024*1024;
 
 		if (range_is_mapped(below_start, above_end) == 1) {
 			tst_res(TINFO|TERRNO, "region 4G-IT is not free & "
testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c +9 -9
index 13068e5b6..c54a746b3 100644
@@ -24,30 +24,30 @@
 
 #include "hugetlb.h"
 
-#define FOURGB (1UL << 32)
+#define FOURGB (1ULL << 32)
 #define MNTPOINT "hugetlbfs/"
 static int  fd = -1;
-static unsigned long hpage_size;
+static unsigned long long hpage_size;
 static int page_size;
 
 static void run_test(void)
 {
 	void *p, *q = NULL, *r = NULL;
-	unsigned long lowaddr, highaddr;
-	unsigned long below_start;
-	unsigned long above_end;
+	unsigned long long lowaddr, highaddr;
+	unsigned long long below_start;
+	unsigned long long above_end;
 
 	/*
 	 * We use a low address right below 4GB so we can test for
 	 * off-by-one errors
 	 */
 	lowaddr = FOURGB - hpage_size;
-	tst_res(TINFO, "Mapping hugepage at %lx...", lowaddr);
+	tst_res(TINFO, "Mapping hugepage at %llx...", lowaddr);
 	p = mmap((void *)lowaddr, hpage_size, PROT_READ|PROT_WRITE,
 		 MAP_SHARED|MAP_FIXED, fd, 0);
 	if (p == MAP_FAILED) {
 		/* This is last low slice - 256M just before 4G */
-		below_start = FOURGB - 256L*1024*1024;
+		below_start = FOURGB - 256ULL*1024*1024;
 		above_end = FOURGB;
 
 		if (range_is_mapped(below_start, above_end) == 1) {
@@ -66,7 +66,7 @@ static void run_test(void)
 
 	/* Test for off by one errors */
 	highaddr = FOURGB;
-	tst_res(TINFO, "Mapping normal page at %lx...", highaddr);
+	tst_res(TINFO, "Mapping normal page at %llx...", highaddr);
 	q = mmap((void *)highaddr, page_size, PROT_READ|PROT_WRITE,
 		 MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0);
 	if (q == MAP_FAILED) {
@@ -94,7 +94,7 @@ static void run_test(void)
 	 * greater.
 	 */
 	highaddr = ((lowaddr >> 28) + 128) << 28;
-	tst_res(TINFO, "Mapping normal page at %lx...", highaddr);
+	tst_res(TINFO, "Mapping normal page at %llx...", highaddr);
 	r = mmap((void *)highaddr, page_size, PROT_READ|PROT_WRITE,
 		 MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0);
 	if (r == MAP_FAILED) {
Signature · 5 lines
2.40.0.rc1.284.g88254d51c5-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Patch applied, thanks!

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp