diff options
| author | David Laight <david.laight.linux@gmail.com> | 2025-11-19 22:41:26 +0000 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2025-12-15 14:33:37 +0100 |
| commit | 0f5bb0cfb0b40a31d2fe146ecbef5727690fa547 (patch) | |
| tree | f89e33d5203b91364ce40a4dc1a4880252030dbf /include | |
| parent | 8f0b4cce4481fb22653697cced8d0d04027cb1e8 (diff) | |
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>
Diffstat (limited to 'include')
0 files changed, 0 insertions, 0 deletions
