linux/fs/fat
David Laight 0f5bb0cfb0
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>
History 2025-12-15 14:33:37 +01:00
..
.kunitconfig fat: Add KUnit tests for checksums and timestamps 2021-08-13 13:13:18 -06:00
cache.c fs/fat: remove unnecessary wrapper fat_max_cache() 2025-12-10 16:07:42 -08:00
dir.c fs: use min() or umin() instead of min_t() 2025-12-15 14:33:37 +01:00
fat.h fat: Convert to new mount api 2024-07-03 10:48:59 +02:00
fat_test.c fs: fat: add missing MODULE_DESCRIPTION() macros 2024-05-28 12:06:55 +02:00
fatent.c fs: fat: Prevent fsfuzzer from dominating the console 2025-07-09 22:57:55 -07:00
file.c fs: use min() or umin() instead of min_t() 2025-12-15 14:33:37 +01:00
inode.c vfs-6.19-rc1.fs_header 2025-12-01 14:18:01 -08:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile fat: Add KUnit tests for checksums and timestamps 2021-08-13 13:13:18 -06:00
misc.c fat: fix too many log in fat_chain_add() 2025-08-02 12:01:40 -07:00
namei_msdos.c new helper: set_default_d_op() 2025-06-10 22:21:16 -04:00
namei_vfat.c new helper: set_default_d_op() 2025-06-10 22:21:16 -04:00
nfs.c fat: fix uninitialized field in nostale filehandles 2024-02-22 15:38:55 -08:00