[LTP] [PATCH 3/3] minmax: ensure the comparison numbers have compatible type

Li Wang liwang@redhat.com
Fri Mar 11 06:46:03 CET 2022


To get rid of many compiler warnings.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 lib/tst_cgroup.c                                  | 2 +-
 lib/tst_memutils.c                                | 4 ++--
 lib/tst_timer_test.c                              | 4 ++--
 testcases/kernel/syscalls/fallocate/fallocate06.c | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 8cca0654d..57940ba09 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -1116,7 +1116,7 @@ ssize_t safe_cg_read(const char *const file, const int lineno,
 		prev_len = MIN(sizeof(prev_buf), (size_t)read_ret);
 	}
 
-	out[MAX(read_ret, 0)] = '\0';
+	out[MAX(read_ret, (ssize_t)0)] = '\0';
 
 	return read_ret;
 }
diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index 3741d6e6f..d95d75e5d 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -30,7 +30,7 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
 	min_free += min_free / 10;
 
 	SAFE_SYSINFO(&info);
-	safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128 * 1024 * 1024);
+	safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), (long)128 * 1024 * 1024);
 	safety = MAX(safety, min_free);
 	safety /= info.mem_unit;
 
@@ -44,7 +44,7 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
 	 * Use the lower value of both for pollutable memory. Usually this
 	 * means we will not evict any caches.
 	 */
-	freeram = MIN(info.freeram, (tst_available_mem() * 1024));
+	freeram = MIN((long long)info.freeram, (tst_available_mem() * 1024));
 
 	/* Not enough free memory to avoid invoking OOM killer */
 	if (freeram <= safety)
diff --git a/lib/tst_timer_test.c b/lib/tst_timer_test.c
index 3cd52fc9d..c0e3de3e7 100644
--- a/lib/tst_timer_test.c
+++ b/lib/tst_timer_test.c
@@ -67,7 +67,7 @@ static const char *table_heading = " Time: us ";
  */
 static unsigned int header_len(long long max_sample)
 {
-	unsigned int l = 1;
+	size_t l = 1;
 
 	while (max_sample/=10)
 		l++;
@@ -184,7 +184,7 @@ static int cmp(const void *a, const void *b)
 static long long compute_threshold(long long requested_us,
 				   unsigned int nsamples)
 {
-	unsigned int slack_per_scall = MIN(100000, requested_us / 1000);
+	unsigned int slack_per_scall = MIN((long long)100000, requested_us / 1000);
 
 	slack_per_scall = MAX(slack_per_scall, timerslack);
 
diff --git a/testcases/kernel/syscalls/fallocate/fallocate06.c b/testcases/kernel/syscalls/fallocate/fallocate06.c
index bf0d24328..25b27e41d 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate06.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate06.c
@@ -95,7 +95,7 @@ static void setup(void)
 	TEST(toggle_cow(fd, 0));
 	SAFE_FSTAT(fd, &statbuf);
 	blocksize = statbuf.st_blksize;
-	block_offset = MIN(blocksize / 2, 512);
+	block_offset = MIN(blocksize / 2, (blksize_t)512);
 	wbuf_size = MAX(WRITE_BLOCKS, FALLOCATE_BLOCKS) * blocksize;
 	rbuf_size = (DEALLOCATE_BLOCKS + 1) * blocksize;
 	SAFE_CLOSE(fd);
-- 
2.31.1



More information about the ltp mailing list