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

Configure Feed

Select the types of activity you want to include in your feed.

fs: use min() or umin() 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.

A couple of places need umin() because of loops like:
nfolios = DIV_ROUND_UP(ret + start, PAGE_SIZE);

for (i = 0; i < nfolios; i++) {
struct folio *folio = page_folio(pages[i]);
...
unsigned int len = umin(ret, PAGE_SIZE - start);
...
ret -= len;
...
}
where the compiler doesn't track things well enough to know that
'ret' is never negative.

The alternate loop:
for (i = 0; ret > 0; i++) {
struct folio *folio = page_folio(pages[i]);
...
unsigned int len = min(ret, PAGE_SIZE - start);
...
ret -= len;
...
}
would be equivalent and doesn't need 'nfolios'.

Most of the 'unsigned long' actually come from PAGE_SIZE.

Detected by an extra check added to min_t().

Signed-off-by: David Laight <david.laight.linux@gmail.com>
Link: https://patch.msgid.link/20251119224140.8616-31-david.laight.linux@gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

David Laight and committed by
Christian Brauner
0f5bb0cf 8f0b4cce

+13 -17
+1 -1
fs/buffer.c
··· 2354 2354 if (!head) 2355 2355 return false; 2356 2356 blocksize = head->b_size; 2357 - to = min_t(unsigned, folio_size(folio) - from, count); 2357 + to = min(folio_size(folio) - from, count); 2358 2358 to = from + to; 2359 2359 if (from < blocksize && to > folio_size(folio) - blocksize) 2360 2360 return false;
+1 -1
fs/exec.c
··· 555 555 return -E2BIG; 556 556 557 557 while (len > 0) { 558 - unsigned int bytes_to_copy = min_t(unsigned int, len, 558 + unsigned int bytes_to_copy = min(len, 559 559 min_not_zero(offset_in_page(pos), PAGE_SIZE)); 560 560 struct page *page; 561 561
+1 -2
fs/ext4/mballoc.c
··· 4276 4276 * get the corresponding group metadata to work with. 4277 4277 * For this we have goto again loop. 4278 4278 */ 4279 - thisgrp_len = min_t(unsigned int, (unsigned int)len, 4280 - EXT4_BLOCKS_PER_GROUP(sb) - EXT4_C2B(sbi, blkoff)); 4279 + thisgrp_len = min(len, EXT4_BLOCKS_PER_GROUP(sb) - EXT4_C2B(sbi, blkoff)); 4281 4280 clen = EXT4_NUM_B2C(sbi, thisgrp_len); 4282 4281 4283 4282 if (!ext4_sb_block_valid(sb, NULL, block, thisgrp_len)) {
+1 -1
fs/ext4/resize.c
··· 1479 1479 1480 1480 /* Update the global fs size fields */ 1481 1481 sbi->s_groups_count += flex_gd->count; 1482 - sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count, 1482 + sbi->s_blockfile_groups = min(sbi->s_groups_count, 1483 1483 (EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb))); 1484 1484 1485 1485 /* Update the reserved block counts only once the new group is
+1 -1
fs/ext4/super.c
··· 4832 4832 return -EINVAL; 4833 4833 } 4834 4834 sbi->s_groups_count = blocks_count; 4835 - sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count, 4835 + sbi->s_blockfile_groups = min(sbi->s_groups_count, 4836 4836 (EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb))); 4837 4837 if (((u64)sbi->s_groups_count * sbi->s_inodes_per_group) != 4838 4838 le32_to_cpu(es->s_inodes_count)) {
+2 -2
fs/fat/dir.c
··· 1353 1353 1354 1354 /* Fill the long name slots. */ 1355 1355 for (i = 0; i < long_bhs; i++) { 1356 - int copy = min_t(int, sb->s_blocksize - offset, size); 1356 + int copy = umin(sb->s_blocksize - offset, size); 1357 1357 memcpy(bhs[i]->b_data + offset, slots, copy); 1358 1358 mark_buffer_dirty_inode(bhs[i], dir); 1359 1359 offset = 0; ··· 1364 1364 err = fat_sync_bhs(bhs, long_bhs); 1365 1365 if (!err && i < nr_bhs) { 1366 1366 /* Fill the short name slot. */ 1367 - int copy = min_t(int, sb->s_blocksize - offset, size); 1367 + int copy = umin(sb->s_blocksize - offset, size); 1368 1368 memcpy(bhs[i]->b_data + offset, slots, copy); 1369 1369 mark_buffer_dirty_inode(bhs[i], dir); 1370 1370 if (IS_DIRSYNC(dir))
+1 -2
fs/fat/file.c
··· 140 140 if (copy_from_user(&range, user_range, sizeof(range))) 141 141 return -EFAULT; 142 142 143 - range.minlen = max_t(unsigned int, range.minlen, 144 - bdev_discard_granularity(sb->s_bdev)); 143 + range.minlen = max(range.minlen, bdev_discard_granularity(sb->s_bdev)); 145 144 146 145 err = fat_trim_fs(inode, &range); 147 146 if (err < 0)
+1 -1
fs/fuse/dev.c
··· 1813 1813 goto out_iput; 1814 1814 1815 1815 folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset; 1816 - nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset); 1816 + nr_bytes = min(num, folio_size(folio) - folio_offset); 1817 1817 nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT; 1818 1818 1819 1819 err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0);
+3 -5
fs/fuse/file.c
··· 1323 1323 static inline unsigned int fuse_wr_pages(loff_t pos, size_t len, 1324 1324 unsigned int max_pages) 1325 1325 { 1326 - return min_t(unsigned int, 1327 - ((pos + len - 1) >> PAGE_SHIFT) - 1328 - (pos >> PAGE_SHIFT) + 1, 1329 - max_pages); 1326 + return min(((pos + len - 1) >> PAGE_SHIFT) - (pos >> PAGE_SHIFT) + 1, 1327 + max_pages); 1330 1328 } 1331 1329 1332 1330 static ssize_t fuse_perform_write(struct kiocb *iocb, struct iov_iter *ii) ··· 1605 1607 struct folio *folio = page_folio(pages[i]); 1606 1608 unsigned int offset = start + 1607 1609 (folio_page_idx(folio, pages[i]) << PAGE_SHIFT); 1608 - unsigned int len = min_t(unsigned int, ret, PAGE_SIZE - start); 1610 + unsigned int len = umin(ret, PAGE_SIZE - start); 1609 1611 1610 1612 ap->descs[ap->num_folios].offset = offset; 1611 1613 ap->descs[ap->num_folios].length = len;
+1 -1
fs/splice.c
··· 1467 1467 1468 1468 n = DIV_ROUND_UP(left + start, PAGE_SIZE); 1469 1469 for (i = 0; i < n; i++) { 1470 - int size = min_t(int, left, PAGE_SIZE - start); 1470 + int size = umin(left, PAGE_SIZE - start); 1471 1471 1472 1472 buf.page = pages[i]; 1473 1473 buf.offset = start;