From 5272e4272d2ac9c382268ab919504422436a1ac7 Mon Sep 17 00:00:00 2001 From: Andrew Innes Date: Thu, 27 Oct 2022 17:37:36 +0800 Subject: [PATCH 1/2] Fix Multiplication converted to larger type Signed-off-by: Andrew Innes --- cmd/raidz_test/raidz_test.c | 2 +- lib/libefi/rdwr_efi.c | 2 +- module/zfs/arc.c | 2 +- tests/zfs-tests/cmd/stride_dd.c | 8 +++++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/raidz_test/raidz_test.c b/cmd/raidz_test/raidz_test.c index 34f3f6f1ccc6..c541d817ae2f 100644 --- a/cmd/raidz_test/raidz_test.c +++ b/cmd/raidz_test/raidz_test.c @@ -937,7 +937,7 @@ run_sweep(void) opts = umem_zalloc(sizeof (raidz_test_opts_t), UMEM_NOFAIL); opts->rto_ashift = ashift_v[a]; opts->rto_dcols = dcols_v[d]; - opts->rto_offset = (1 << ashift_v[a]) * rand(); + opts->rto_offset = (uint64_t)(1 << ashift_v[a]) * rand(); opts->rto_dsize = size_v[s]; opts->rto_expand = rto_opts.rto_expand; opts->rto_expand_offset = rto_opts.rto_expand_offset; diff --git a/lib/libefi/rdwr_efi.c b/lib/libefi/rdwr_efi.c index 3501c3ea391c..739219e0410f 100644 --- a/lib/libefi/rdwr_efi.c +++ b/lib/libefi/rdwr_efi.c @@ -1362,7 +1362,7 @@ efi_write(int fd, struct dk_gpt *vtoc) if (NBLOCKS(vtoc->efi_nparts, vtoc->efi_lbasize) < 34) { dk_ioc.dki_length = EFI_MIN_ARRAY_SIZE + vtoc->efi_lbasize; } else { - dk_ioc.dki_length = NBLOCKS(vtoc->efi_nparts, + dk_ioc.dki_length = (len_t)NBLOCKS(vtoc->efi_nparts, vtoc->efi_lbasize) * vtoc->efi_lbasize; } diff --git a/module/zfs/arc.c b/module/zfs/arc.c index 54cfb4bd3d04..936bcb5e3efb 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -5136,7 +5136,7 @@ arc_adapt(int bytes, arc_state_t *state) if (!zfs_arc_p_dampener_disable) mult = MIN(mult, 10); /* avoid wild arc_p adjustment */ - arc_p = MIN(arc_c - arc_p_min, arc_p + bytes * mult); + arc_p = MIN(arc_c - arc_p_min, arc_p + (uint64_t)bytes * mult); } else if (state == arc_mfu_ghost) { uint64_t delta; diff --git a/tests/zfs-tests/cmd/stride_dd.c b/tests/zfs-tests/cmd/stride_dd.c index 732ac9f47268..36847bbf8ddb 100644 --- a/tests/zfs-tests/cmd/stride_dd.c +++ b/tests/zfs-tests/cmd/stride_dd.c @@ -156,7 +156,7 @@ main(int argc, char *argv[]) } if (seek > 0) { - if (lseek(ofd, seek * bsize, SEEK_CUR) == -1) { + if (lseek(ofd, (uint64_t)seek * bsize, SEEK_CUR) == -1) { perror("output lseek"); exit(2); } @@ -195,11 +195,13 @@ main(int argc, char *argv[]) } if (stride > 1) { - if (lseek(ifd, (stride - 1) * bsize, SEEK_CUR) == -1) { + if (lseek(ifd, ((uint64_t)stride - 1) * bsize, + SEEK_CUR) == -1) { perror("input lseek"); exit(2); } - if (lseek(ofd, (stride - 1) * bsize, SEEK_CUR) == -1) { + if (lseek(ofd, ((uint64_t)stride - 1) * bsize, + SEEK_CUR) == -1) { perror("output lseek"); exit(2); } From 0afef1e1026deb96aeac1e797cb885bd5c9b1fc4 Mon Sep 17 00:00:00 2001 From: Andrew Innes Date: Thu, 27 Oct 2022 22:19:36 +0800 Subject: [PATCH 2/2] use ULL Signed-off-by: Andrew Innes --- cmd/raidz_test/raidz_test.c | 2 +- tests/zfs-tests/cmd/stride_dd.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/raidz_test/raidz_test.c b/cmd/raidz_test/raidz_test.c index c541d817ae2f..195026d3a7ab 100644 --- a/cmd/raidz_test/raidz_test.c +++ b/cmd/raidz_test/raidz_test.c @@ -937,7 +937,7 @@ run_sweep(void) opts = umem_zalloc(sizeof (raidz_test_opts_t), UMEM_NOFAIL); opts->rto_ashift = ashift_v[a]; opts->rto_dcols = dcols_v[d]; - opts->rto_offset = (uint64_t)(1 << ashift_v[a]) * rand(); + opts->rto_offset = (1ULL << ashift_v[a]) * rand(); opts->rto_dsize = size_v[s]; opts->rto_expand = rto_opts.rto_expand; opts->rto_expand_offset = rto_opts.rto_expand_offset; diff --git a/tests/zfs-tests/cmd/stride_dd.c b/tests/zfs-tests/cmd/stride_dd.c index 36847bbf8ddb..6af45c3e8aeb 100644 --- a/tests/zfs-tests/cmd/stride_dd.c +++ b/tests/zfs-tests/cmd/stride_dd.c @@ -195,12 +195,12 @@ main(int argc, char *argv[]) } if (stride > 1) { - if (lseek(ifd, ((uint64_t)stride - 1) * bsize, + if (lseek(ifd, (stride - 1ULL) * bsize, SEEK_CUR) == -1) { perror("input lseek"); exit(2); } - if (lseek(ofd, ((uint64_t)stride - 1) * bsize, + if (lseek(ofd, (stride - 1ULL) * bsize, SEEK_CUR) == -1) { perror("output lseek"); exit(2);