From: David Laight <david.laight.linux@gmail.com> mainline inclusion from mainline-v6.19-rc1 commit 9420e720ad192c53c8d2803c5a2313b2d586adbd category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9104 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- min_t(unsigned int, a, b) casts an 'unsigned long' to 'unsigned int'. Use min(a, b) instead as it promotes any 'unsigned int' to 'unsigned long' and so cannot discard significant bits. In this case the 'unsigned long' value is small enough that the result is ok. (Similarly for max_t() and clamp_t().) Detected by an extra check added to min_t(). Signed-off-by: David Laight <david.laight.linux@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Zizhi Wo <wozizhi@huawei.com> --- block/blk-iocost.c | 6 ++---- block/partitions/efi.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index a9c3f17ab680..0019b67aed15 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -2333,14 +2333,12 @@ static void ioc_timer_fn(struct timer_list *timer) if (time_after64(iocg->activated_at, ioc->period_at)) usage_dur = max_t(u64, now.now - iocg->activated_at, 1); else usage_dur = max_t(u64, now.now - ioc->period_at, 1); - usage = clamp_t(u32, - DIV64_U64_ROUND_UP(usage_us * WEIGHT_ONE, - usage_dur), - 1, WEIGHT_ONE); + usage = clamp(DIV64_U64_ROUND_UP(usage_us * WEIGHT_ONE, usage_dur), + 1, WEIGHT_ONE); /* * Already donating or accumulated enough to start. * Determine the donation amount. */ diff --git a/block/partitions/efi.c b/block/partitions/efi.c index 7acba66eed48..638261e9f2fb 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -213,12 +213,11 @@ static int is_pmbr_valid(legacy_mbr *mbr, sector_t total_sectors) */ if (ret == GPT_MBR_PROTECTIVE) { sz = le32_to_cpu(mbr->partition_record[part].size_in_lba); if (sz != (uint32_t) total_sectors - 1 && sz != 0xFFFFFFFF) pr_debug("GPT: mbr size in lba (%u) different than whole disk (%u).\n", - sz, min_t(uint32_t, - total_sectors - 1, 0xFFFFFFFF)); + sz, (uint32_t)min(total_sectors - 1, 0xFFFFFFFF)); } done: return ret; } -- 2.52.0