From: Cyril Hrubis <chrubis@suse.cz>
To: Edward Liaw <edliaw@google.com>
Cc: kernel-team@android.com, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] minmax: fix type warnings
Date: Wed, 14 Sep 2022 11:45:22 +0200 [thread overview]
Message-ID: <YyGisrbDIgVa/0QA@yuki> (raw)
In-Reply-To: <20220913202839.1807979-1-edliaw@google.com>
Hi!
> SAFE_SYSINFO(&info);
> safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128L * 1024 * 1024);
> - safety = MAX(safety, min_free);
> + safety = MAX(safety, (size_t)min_free);
> safety /= info.mem_unit;
We can define the min_free to be size_t from the start as:
diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index 0d20bb17c..6fc9f6a93 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -20,11 +20,11 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
{
size_t i, map_count = 0, safety = 0, blocksize = BLOCKSIZE;
unsigned long long freeram;
- unsigned long min_free;
+ size_t min_free;
void **map_blocks;
struct sysinfo info;
- SAFE_FILE_SCANF("/proc/sys/vm/min_free_kbytes", "%lu", &min_free);
+ SAFE_FILE_SCANF("/proc/sys/vm/min_free_kbytes", "%zu", &min_free);
min_free *= 1024;
/* Apply a margin because we cannot get below "min" watermark */
min_free += min_free / 10;
> if (info.freeswap > safety)
> diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c
> index c16b50a6d..f425c223d 100644
> --- a/testcases/kernel/mem/mmapstress/mmapstress01.c
> +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c
> @@ -310,7 +310,7 @@ int main(int argc, char *argv[])
> anyfail();
> }
> for (bytes_left = filesize; bytes_left; bytes_left -= c) {
> - write_cnt = MIN(pagesize, bytes_left);
> + write_cnt = MIN(pagesize, (int)bytes_left);
> if ((c = write(fd, buf, write_cnt)) != write_cnt) {
> if (c == -1) {
> perror("write error");
> diff --git a/testcases/kernel/mem/mmapstress/mmapstress10.c b/testcases/kernel/mem/mmapstress/mmapstress10.c
> index 28b4f1e91..53f02c1f6 100644
> --- a/testcases/kernel/mem/mmapstress/mmapstress10.c
> +++ b/testcases/kernel/mem/mmapstress/mmapstress10.c
> @@ -360,7 +360,7 @@ int main(int argc, char *argv[])
> }
>
> for (bytes_left = filesize; bytes_left; bytes_left -= c) {
> - write_cnt = MIN(pagesize, bytes_left);
> + write_cnt = MIN(pagesize, (int)bytes_left);
> if ((c = write(fd, (char *)buf, write_cnt)) != write_cnt) {
> if (c == -1) {
> perror("write error");
> diff --git a/testcases/kernel/mem/tunable/overcommit_memory.c b/testcases/kernel/mem/tunable/overcommit_memory.c
> index 20151ebb0..7fe8fe14c 100644
> --- a/testcases/kernel/mem/tunable/overcommit_memory.c
> +++ b/testcases/kernel/mem/tunable/overcommit_memory.c
> @@ -248,9 +248,9 @@ static void calculate_total_batch_size(void)
> SAFE_SYSINFO(&info);
>
> /* see linux source mm/mm_init.c mm_compute_batch() (This is in pages) */
> - long batch_size = MAX(ncpus * 2,
> - MAX(32,
> - MIN(INT32_MAX,
> + long batch_size = MAX(ncpus * 2L,
> + MAX(32L,
> + MIN((long)INT32_MAX,
> (long)(info.totalram / pagesize) / ncpus / 256
> )
> )
> diff --git a/testcases/kernel/syscalls/mprotect/mprotect02.c b/testcases/kernel/syscalls/mprotect/mprotect02.c
> index de9b4ea00..da445d442 100644
> --- a/testcases/kernel/syscalls/mprotect/mprotect02.c
> +++ b/testcases/kernel/syscalls/mprotect/mprotect02.c
> @@ -77,7 +77,7 @@ int main(int ac, char **av)
>
> do {
>
> - bytes_to_write = MIN(strlen(buf), num_bytes);
> + bytes_to_write = MIN((unsigned int)strlen(buf), num_bytes);
Again we can define the num_bytes to be size_t from the start.
The rest looks good.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-09-14 9:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-13 20:28 [LTP] [PATCH v1] minmax: fix type warnings Edward Liaw via ltp
2022-09-14 9:20 ` Petr Vorel
2022-09-14 9:45 ` Cyril Hrubis [this message]
2022-09-14 13:35 ` Petr Vorel
2022-09-14 13:50 ` Petr Vorel
2022-09-15 20:51 ` Edward Liaw via ltp
2022-09-16 9:13 ` Cyril Hrubis
2022-09-26 18:15 ` Edward Liaw via ltp
2022-09-27 9:06 ` Cyril Hrubis
2022-09-27 21:20 ` Edward Liaw via ltp
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=YyGisrbDIgVa/0QA@yuki \
--to=chrubis@suse.cz \
--cc=edliaw@google.com \
--cc=kernel-team@android.com \
--cc=ltp@lists.linux.it \
/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