mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Joanne Koong <joannelkoong@gmail.com>
Cc: Arnd Bergmann <arnd@kernel.org>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Christian Brauner <brauner@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>,
	"Darrick J. Wong" <djwong@kernel.org>,
	Jeff Layton <jlayton@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fs: fuse: fix max() of incompatible types
Date: Wed, 24 Dec 2025 09:47:10 +0000	[thread overview]
Message-ID: <20251224094710.573cf39b@pumpkin> (raw)
In-Reply-To: <CAJnrk1bW+OoiZSFOzO8VAtHjS_Us=-AtuBSZZCvnrdvqK-qqfw@mail.gmail.com>

On Tue, 23 Dec 2025 14:58:06 -0800
Joanne Koong <joannelkoong@gmail.com> wrote:

> On Tue, Dec 23, 2025 at 1:54 PM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > 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.
> >
> > Fixes: 0f5bb0cfb0b4 ("fs: use min() or umin() instead of min_t()")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>  
> 
> 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

> 
> Thanks,
> Joanne
> 
> [1] https://lore.kernel.org/linux-fsdevel/20251216141647.13911-1-david.laight.linux@gmail.com/
> 
> > ---
> >  fs/fuse/file.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> > index 4f71eb5a9bac..d3dec67d73fc 100644
> > --- a/fs/fuse/file.c
> > +++ b/fs/fuse/file.c
> > @@ -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
> >  


      reply	other threads:[~2025-12-24  9:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-23 21:54 Arnd Bergmann
2025-12-23 22:58 ` Joanne Koong
2025-12-24  9:47   ` David Laight [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251224094710.573cf39b@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=brauner@kernel.org \
    --cc=djwong@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=joannelkoong@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®