public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/1] hugeshmat04: Restore the correct shmmax value
@ 2023-08-03 10:30 Leo Yu-Chi Liang
  2023-08-03 10:42 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Leo Yu-Chi Liang @ 2023-08-03 10:30 UTC (permalink / raw)
  To: ltp; +Cc: cynthia, patrick

The type of shmmax is unsinged long in Linux kernel and the default value
is ((~0UL) - (1UL << 24)). If we try to access this value with %ld format
string in scanf-like function, we end up getting different incorrect values
depends on the implementation of different libc.

Fix this by accessing shmmax with the correct %lu format string.

Signed-off-by: Leo Yu-Chi Liang <ycliang@andestech.com>
---
 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
index 50efa8a52..b3e7c272a 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -83,12 +83,12 @@ static void setup(void)
 	long hpage_size, orig_hugepages;
 
 	orig_hugepages = get_sys_tune("nr_hugepages");
-	SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &orig_shmmax);
-	SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", (long)SIZE);
-	SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &new_shmmax);
+	SAFE_FILE_SCANF(PATH_SHMMAX, "%lu", &orig_shmmax);
+	SAFE_FILE_PRINTF(PATH_SHMMAX, "%lu", (long)SIZE);
+	SAFE_FILE_SCANF(PATH_SHMMAX, "%lu", &new_shmmax);
 
 	if (new_shmmax < SIZE)
-		tst_brk(TCONF,	"shmmax too low, have: %ld", new_shmmax);
+		tst_brk(TCONF,	"shmmax too low, have: %lu", new_shmmax);
 
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -99,7 +99,7 @@ static void setup(void)
 static void cleanup(void)
 {
 	if (orig_shmmax != -1)
-		SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
+		SAFE_FILE_PRINTF(PATH_SHMMAX, "%lu", orig_shmmax);
 }
 
 static struct tst_test test = {
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-05  2:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-03 10:30 [LTP] [PATCH 1/1] hugeshmat04: Restore the correct shmmax value Leo Yu-Chi Liang
2023-08-03 10:42 ` Cyril Hrubis
2023-08-05  2:41   ` Leo Liang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox