]> git.ipfire.org Git - thirdparty/linux.git/commit
fs: use min() or umin() instead of min_t()
authorDavid Laight <david.laight.linux@gmail.com>
Wed, 19 Nov 2025 22:41:26 +0000 (22:41 +0000)
committerChristian Brauner <brauner@kernel.org>
Mon, 15 Dec 2025 13:33:37 +0000 (14:33 +0100)
commit0f5bb0cfb0b40a31d2fe146ecbef5727690fa547
treef89e33d5203b91364ce40a4dc1a4880252030dbf
parent8f0b4cce4481fb22653697cced8d0d04027cb1e8
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>
fs/buffer.c
fs/exec.c
fs/ext4/mballoc.c
fs/ext4/resize.c
fs/ext4/super.c
fs/fat/dir.c
fs/fat/file.c
fs/fuse/dev.c
fs/fuse/file.c
fs/splice.c