Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: use min() instead of min_t()

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>

authored by

David Laight and committed by
Jens Axboe
9420e720 e8f0abdd

+3 -6
+2 -4
block/blk-iocost.c
··· 2334 2334 else 2335 2335 usage_dur = max_t(u64, now.now - ioc->period_at, 1); 2336 2336 2337 - usage = clamp_t(u32, 2338 - DIV64_U64_ROUND_UP(usage_us * WEIGHT_ONE, 2339 - usage_dur), 2340 - 1, WEIGHT_ONE); 2337 + usage = clamp(DIV64_U64_ROUND_UP(usage_us * WEIGHT_ONE, usage_dur), 2338 + 1, WEIGHT_ONE); 2341 2339 2342 2340 /* 2343 2341 * Already donating or accumulated enough to start.
+1 -2
block/partitions/efi.c
··· 215 215 sz = le32_to_cpu(mbr->partition_record[part].size_in_lba); 216 216 if (sz != (uint32_t) total_sectors - 1 && sz != 0xFFFFFFFF) 217 217 pr_debug("GPT: mbr size in lba (%u) different than whole disk (%u).\n", 218 - sz, min_t(uint32_t, 219 - total_sectors - 1, 0xFFFFFFFF)); 218 + sz, (uint32_t)min(total_sectors - 1, 0xFFFFFFFF)); 220 219 } 221 220 done: 222 221 return ret;