public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH next] fuse: Fix 'min: signedness error' in fuse_wr_pages()
@ 2026-01-13 19:22 david.laight.linux
  2026-01-13 20:23 ` Brian Masney
  2026-02-03  1:05 ` Nathan Chancellor
  0 siblings, 2 replies; 3+ messages in thread
From: david.laight.linux @ 2026-01-13 19:22 UTC (permalink / raw)
  To: Christian Brauner, Andrew Morton, Miklos Szeredi, Mark Brown,
	linux-kernel, linux-fsdevel, Alexander Viro, Andreas Dilger,
	Kees Cook, OGAWA Hirofumi, Theodore Ts'o, Brian Masney
  Cc: David Laight

From: David Laight <david.laight.linux@gmail.com>

On 32bit systems 'pos' is s64 and everything else is 32bit so the
first argument to min() is signed - generating a warning.
On 64bit systems 'len' is 64bit unsigned forcing everything to unsigned.

Fix by reworking the exprssion to completely avoid 64bit maths on 32bit.
Use DIV_ROUND_UP() instead of open-coding something equivalent.

Note that the 32bit 'len' cannot overflow because the syscall interface
limits read/write (etc) to (INT_MAX - PAGE_SIZE) bytes (even on 64bit).

Fixes: 0f5bb0cfb0b4 ("fs: use min() or umin() instead of min_t()")
Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
 fs/fuse/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 2595b6b4922b..ff823b0545ed 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1323,8 +1323,8 @@ 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);
+	len += pos % PAGE_SIZE;
+	return min(DIV_ROUND_UP(len, PAGE_SIZE), max_pages);
 }
 
 static ssize_t fuse_perform_write(struct kiocb *iocb, struct iov_iter *ii)
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH next] fuse: Fix 'min: signedness error' in fuse_wr_pages()
  2026-01-13 19:22 [PATCH next] fuse: Fix 'min: signedness error' in fuse_wr_pages() david.laight.linux
@ 2026-01-13 20:23 ` Brian Masney
  2026-02-03  1:05 ` Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: Brian Masney @ 2026-01-13 20:23 UTC (permalink / raw)
  To: david.laight.linux
  Cc: Christian Brauner, Andrew Morton, Miklos Szeredi, Mark Brown,
	linux-kernel, linux-fsdevel, Alexander Viro, Andreas Dilger,
	Kees Cook, OGAWA Hirofumi, Theodore Ts'o

On Tue, Jan 13, 2026 at 07:22:43PM +0000, david.laight.linux@gmail.com wrote:
> From: David Laight <david.laight.linux@gmail.com>
> 
> On 32bit systems 'pos' is s64 and everything else is 32bit so the
> first argument to min() is signed - generating a warning.
> On 64bit systems 'len' is 64bit unsigned forcing everything to unsigned.
> 
> Fix by reworking the exprssion to completely avoid 64bit maths on 32bit.
> Use DIV_ROUND_UP() instead of open-coding something equivalent.
> 
> Note that the 32bit 'len' cannot overflow because the syscall interface
> limits read/write (etc) to (INT_MAX - PAGE_SIZE) bytes (even on 64bit).
> 
> Fixes: 0f5bb0cfb0b4 ("fs: use min() or umin() instead of min_t()")
> Signed-off-by: David Laight <david.laight.linux@gmail.com>

Reported-by: Brian Masney <bmasney@redhat.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>

This fixes the MIPS cross compiler error on arm64 that I reported. I
also tested a native arm64 build.

Brian


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH next] fuse: Fix 'min: signedness error' in fuse_wr_pages()
  2026-01-13 19:22 [PATCH next] fuse: Fix 'min: signedness error' in fuse_wr_pages() david.laight.linux
  2026-01-13 20:23 ` Brian Masney
@ 2026-02-03  1:05 ` Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2026-02-03  1:05 UTC (permalink / raw)
  To: david.laight.linux, Christian Brauner
  Cc: Andrew Morton, Miklos Szeredi, Mark Brown, linux-kernel,
	linux-fsdevel, Alexander Viro, Andreas Dilger, Kees Cook,
	OGAWA Hirofumi, Theodore Ts'o, Brian Masney

On Tue, Jan 13, 2026 at 07:22:43PM +0000, david.laight.linux@gmail.com wrote:
> From: David Laight <david.laight.linux@gmail.com>
> 
> On 32bit systems 'pos' is s64 and everything else is 32bit so the
> first argument to min() is signed - generating a warning.
> On 64bit systems 'len' is 64bit unsigned forcing everything to unsigned.
> 
> Fix by reworking the exprssion to completely avoid 64bit maths on 32bit.
> Use DIV_ROUND_UP() instead of open-coding something equivalent.
> 
> Note that the 32bit 'len' cannot overflow because the syscall interface
> limits read/write (etc) to (INT_MAX - PAGE_SIZE) bytes (even on 64bit).
> 
> Fixes: 0f5bb0cfb0b4 ("fs: use min() or umin() instead of min_t()")

Christian, you took 0f5bb0cfb0b4 in vfs-7.0.misc, could you please apply
this fix? Building this file for 32-bit has been broken for the majority
of the -next cycle (I applied an earlier fix David provided and forgot
to chase it until now).

> Signed-off-by: David Laight <david.laight.linux@gmail.com>
> ---
>  fs/fuse/file.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index 2595b6b4922b..ff823b0545ed 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -1323,8 +1323,8 @@ 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);
> +	len += pos % PAGE_SIZE;
> +	return min(DIV_ROUND_UP(len, PAGE_SIZE), max_pages);
>  }
>  
>  static ssize_t fuse_perform_write(struct kiocb *iocb, struct iov_iter *ii)
> -- 
> 2.39.5
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-03  1:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-13 19:22 [PATCH next] fuse: Fix 'min: signedness error' in fuse_wr_pages() david.laight.linux
2026-01-13 20:23 ` Brian Masney
2026-02-03  1:05 ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox