fs: fuse: fix max() of incompatible types
Subsystems (2)
PATCH 1/1 fs: fuse: fix max() of incompatible types
From: Arnd Bergmann <[email protected]>
The 'max()' value of a 'long long' and an 'unsigned int' is problematic if the former is negative:
In function 'fuse_wr_pages',
inlined from 'fuse_perform_write' at fs/fuse/file.c:1347:27:
include/linux/compiler_types.h:652:45: error: call to '__compiletime_assert_390' declared with attribute error: min(((pos + len - 1) >> 12) - (pos >> 12) + 1, max_pages) signedness error
652 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
Use a temporary variable to make it clearer what is going on here.
--- fs/fuse/file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/fuse/file.c +4 -2
@@ -1323,8 +1323,10 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,static inline unsigned int fuse_wr_pages (loff_t pos,size_t len,unsigned int max_pages) { -return min (((pos + len -1 ) >>PAGE_SHIFT ) - (pos >>PAGE_SHIFT ) +1 , - max_pages); +unsigned int pages = ((pos + len -1 ) >>PAGE_SHIFT ) - + (pos >>PAGE_SHIFT ) +1 ; + +return min (pages, max_pages); }static ssize_t fuse_perform_write (struct kiocb *iocb,struct iov_iter *ii)
Signature · 1 line
2.39.5
Quoted 8 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The '
max()' value of a 'long long' and an 'unsigned int' is problematic if the former is negative:In function '
fuse_wr_pages',inlined from 'fuse_perform_write' at fs/fuse/file.c:1347:27:
Quoted 8 lines
include/linux/compiler_types.h:652:45: error: call to '__compiletime_assert_390' declared with attribute error:min(((pos + len - 1) >> 12) - (pos >> 12) + 1, max_pages)signedness error
652 |_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^Use a temporary variable to make it clearer what is going on here.
Fixes 0f5bb0cfb0b4 ("fs: use min() or umin() instead of min_t()")Signed-off-by Arnd Bergmann <[email protected]>
Hi Arnd,
I believe there was a patch sent last week [1] by David that addresses this as well.
Thanks,
Joanne
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
Quoted 24 lines
--- fs/fuse/file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/fuse/file.c +4
-3@@ -1323,8 +1323,10 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,static inline unsigned int fuse_wr_pages (loff_t pos,size_t len,unsigned int max_pages) { -return min (((pos + len -1 ) >>PAGE_SHIFT ) - (pos >>PAGE_SHIFT ) +1 , - max_pages); +unsigned int pages = ((pos + len -1 ) >>PAGE_SHIFT ) - + (pos >>PAGE_SHIFT ) +1 ; + +return min (pages, max_pages); }static ssize_t fuse_perform_write (struct kiocb *iocb,struct iov_iter *ii) --2.39.5
Quoted 15 lines · On Tue, 23 Dec 2025 14:58:06 -0800 Joanne Koong <[email protected]> wrote:
Quoted 14 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The '
max()' value of a 'long long' and an 'unsigned int' is problematic if the former is negative:In function '
fuse_wr_pages',inlined from 'fuse_perform_write' at fs/fuse/file.c:1347:27:
include/linux/compiler_types.h:652:45: error: call to '__compiletime_assert_390' declared with attribute error:min(((pos + len - 1) >> 12) - (pos >> 12) + 1, max_pages)signedness error
652 |_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^Use a temporary variable to make it clearer what is going on here.
Quoted 7 lines
Quoted 2 lines
Fixes 0f5bb0cfb0b4 ("fs: use min() or umin() instead of min_t()")Signed-off-by Arnd Bergmann <[email protected]>Hi Arnd,
I believe there was a patch sent last week [1] by David that addresses this as well.
My patch was:
return min(((len + (pos & (PAGE_SIZE - 1)) - 1) >> PAGE_SHIFT) + 1,
max_pages);
And your suggestion of:
I find this logic a bit confusing to read still, what about something like:
unsigned int nr_pages = DIV_ROUND_UP(offset_in_page(pos) + len, PAGE_SIZE); return min(nr_pages, max_pages);
which is the same algorithm coded with some helpers.
David
Quoted 30 lines
Thanks,
Joanne[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
Quoted 24 lines
--- fs/fuse/file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/fuse/file.c +4
-3@@ -1323,8 +1323,10 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,static inline unsigned int fuse_wr_pages (loff_t pos,size_t len,unsigned int max_pages) { -return min (((pos + len -1 ) >>PAGE_SHIFT ) - (pos >>PAGE_SHIFT ) +1 , - max_pages); +unsigned int pages = ((pos + len -1 ) >>PAGE_SHIFT ) - + (pos >>PAGE_SHIFT ) +1 ; + +return min (pages, max_pages); }static ssize_t fuse_perform_write (struct kiocb *iocb,struct iov_iter *ii) --2.39.5