From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 840D733A9C5 for ; Wed, 24 Dec 2025 09:47:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766569638; cv=none; b=DTGJqiBMt0YDcQETzBMvvnEIwPpKWFpaH2heLHcdG0aUS95ecSieCFf4nd6SF+ZGEe1RR1WX2e/hub5Y+aS2+74KbVSTP8O0uFX7xlNH0ggZNG0CXG4Fv4qUnDB5CXxd1v65R56XZcJWYW3Vtuu/URYq/FYnLOlIJu2YuE3/ycw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766569638; c=relaxed/simple; bh=3WwPAi6GWw857Gak2vKffzJbsdsOIPnhdNwDa66xA6s=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HohfPO/ig2u8rqEr5mGVQK/hD+FEjKacmcPWtZERnWByljW/TcDjrU4n6ENnvSR8Ln/XBQfJAjE75GXGAO0NvA3AhX6xWH+Wd7h+/iFoSxyHJQdoswl4AfBv5DdQ56ds1Iylz4fwD665r1wPinSznv0Pr+B3rOK8oLDE7IY2F4Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=A6IU1+UB; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A6IU1+UB" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-47a8195e515so38699945e9.0 for ; Wed, 24 Dec 2025 01:47:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766569633; x=1767174433; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=K6Mw+fgAuYTORZpYlCld7jbQZ0WmIDOv9Eo5eY1hcJo=; b=A6IU1+UBUW3KKscDl22DMt8D6fLGuo3a9qnpsTLbBDKLIUuaJQ3wwwszADyolEszEx geoyRJQQuKarkZAN7ygYwWeBIcX04jggo5XQPPVbLRToOX1uZjI3UYhiCYYqx6sUNh7X RJiMKqsRySbcwtXs/y9v8WNC9c/Z2z2otXHxGjjqtRFFOls2wizdZ7KpyRbcEbn9sb7S WQb+44VSbvsoOALFBueAxuviSg16WvoJ4jbsjAAWpRElWaF0/5flbPQOZIyeit9YmbOl +nw2LuzWEhjExkMr1Y8OGXanmgU66eR91ZfBTeqWrbGVFuO/eTK/64N90/MikFR8S7vV cjzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766569633; x=1767174433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=K6Mw+fgAuYTORZpYlCld7jbQZ0WmIDOv9Eo5eY1hcJo=; b=ei+s2m7DLfCjgcIi+HZa/ZnYPb7MUTp4jMM0zUQS35bABsqmIU/kEPFEl5dheFXzyJ eiACcPIGDbsKfZMxOCPESycNl13Ww1fMz8M70v+ZPc9EfnbzOP58s0UI+KQ6KWe9WNEs LsLajkaFg91qWMeAs2Y4ajsRt2PaQIouOGHxWXa5+falhdFIcxp4L5iivbwC2a+CWV0+ ILKLVxD81y0Y2k8qhq+Kt4dLZCaZ3boJY8JNc4Z+hTuEKNXuxSTgPr0Ny9U2ZdhShpUc jPfU+Ue9XhFjTmFqxPJPsfPo6h2aX2vaFUvczWTncm6+7Bpd+ZdvqJ5xiAVnze303/z9 RKGg== X-Forwarded-Encrypted: i=1; AJvYcCW3QiexPu426yMaZKXiAdNyUO8Ox4F9sin/nCY8HnLpPseZEcbBEWy23YWnc53haZKsAUfZgWwoRaKv6To=@vger.kernel.org X-Gm-Message-State: AOJu0YwqbSoW6kgqKEVxPPJqqT2qFHRMKycsGsFTQSRdvQ1dwT8jm2xU mXCEsewwrhjaNZ5mtGrBuDIj643ga41YdUedq9GXUcloc2qM28R1vyTv X-Gm-Gg: AY/fxX5cZjpc/v6XxSnwidzZVUK6U1bDevxfzFYc3DbcLvJFiK1RCZfK5DCCADp3jWx Q58I0i/9A8Nxjc34Uyl1By2jCZzbNHtfGT2IHgQ0V+NH9FOhDz9IhBBzt4Isg898bQfVvuEHpU5 kFd9WEun9VeveYlW6Ny1LQgcET3a8pqvIHunTGXAR31CTVeG34xteckfaQyg0RT0LNLvgXQpBmC CQXqL6LiyKyP3vM7fv10yxAAqL36fynJzjVV06u+IJpqe9AtRaWUjo30nBJo70BK6sE08qKTNNI e7vulI/KZFVETpYQrcTmLNPCvf3U8GWjc31u9Esq6DNuQm4tMyuoSifq/jDjZ2LSGFCnQG3JPEy jbuoyX6s4Q4SSWwMunaomY0I/lpVKjSs5cec90IpF+XDKTKj1pu/5j06Kq2+G1MfddcFft4s9uT zJet2pRtC/8Wufb6lffWr5CJD4Qxnie/Yq3D2nK794OgYZiIVkn+abRxRzyNVuNw== X-Google-Smtp-Source: AGHT+IHGj8t4k+MaGDBP6naQrG87ugF9YMEAtBRGvCNNU6h1/vj03U7uxdysFQXOCrj2EOEJ1QT8ww== X-Received: by 2002:a05:600c:45c8:b0:477:8a2a:1244 with SMTP id 5b1f17b1804b1-47d195558bemr165624465e9.11.1766569632612; Wed, 24 Dec 2025 01:47:12 -0800 (PST) Received: from pumpkin (host-2-103-239-165.as13285.net. [2.103.239.165]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47be272e46fsm331672525e9.4.2025.12.24.01.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 01:47:12 -0800 (PST) Date: Wed, 24 Dec 2025 09:47:10 +0000 From: David Laight To: Joanne Koong Cc: Arnd Bergmann , Miklos Szeredi , Christian Brauner , Arnd Bergmann , "Darrick J. Wong" , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fs: fuse: fix max() of incompatible types Message-ID: <20251224094710.573cf39b@pumpkin> In-Reply-To: References: <20251223215442.720828-1-arnd@kernel.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 23 Dec 2025 14:58:06 -0800 Joanne Koong wrote: > On Tue, Dec 23, 2025 at 1:54=E2=80=AFPM Arnd Bergmann w= rote: > > > > From: Arnd Bergmann > > > > 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_as= sert_390' declared with attribute error: min(((pos + len - 1) >> 12) - (pos= >> 12) + 1, max_pages) signedness error > > 652 | _compiletime_assert(condition, msg, __compiletime_asser= t_, __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 =20 >=20 > Hi Arnd, >=20 > 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 =3D DIV_ROUND_UP(offset_in_page(pos) + len, PAGE_SIZ= E); return min(nr_pages, max_pages); which is the same algorithm coded with some helpers. David >=20 > Thanks, > Joanne >=20 > [1] https://lore.kernel.org/linux-fsdevel/20251216141647.13911-1-david.la= ight.linux@gmail.com/ >=20 > > --- > > 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 =3D ((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 > > =20