mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Elder <elder@ieee.org>
To: Arnd Bergmann <arnd@kernel.org>,
	linux-kernel@vger.kernel.org, Ilya Dryomov <idryomov@gmail.com>,
	Jens Axboe <axboe@kernel.dk>,
	Nathan Chancellor <nathan@kernel.org>,
	Alex Elder <elder@inktank.com>,
	Josh Durgin <josh.durgin@inktank.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Dongsheng Yang <dongsheng.yang@easystack.cn>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	Hannes Reinecke <hare@suse.de>,
	Christian Brauner <brauner@kernel.org>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	"Ricardo B. Marliere" <ricardo@marliere.net>,
	Jinjie Ruan <ruanjinjie@huawei.com>,
	Alex Elder <elder@linaro.org>,
	ceph-devel@vger.kernel.org, linux-block@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH 3/9] rbd: avoid out-of-range warning
Date: Thu, 28 Mar 2024 09:53:55 -0500	[thread overview]
Message-ID: <b8e848fe-96d8-4f75-a2e9-2ed5c11a2fd7@ieee.org> (raw)
In-Reply-To: <20240328143051.1069575-4-arnd@kernel.org>

On 3/28/24 9:30 AM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> clang-14 points out that the range check is always true on 64-bit
> architectures since a u32 is not greater than the allowed size:
> 
> drivers/block/rbd.c:6079:17: error: result of comparison of constant 2305843009213693948 with expression of type 'u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
w
>              ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> This is harmless, so just change the type of the temporary to size_t
> to shut up that warning.

This fixes the warning, but then the now size_t value is passed
to ceph_decode_32_safe(), which implies a different type conversion.
That too is not harmful, but...

Could we just cast the value in the comparison instead?

   if ((size_t)snap_count > (SIZE_MAX - sizeof (struct ceph_snap_context))

You could drop the space between sizeof and ( while
you're at it (I always used the space back then).

					-Alex

> 
> Fixes: bb23e37acb2a ("rbd: refactor rbd_header_from_disk()")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   drivers/block/rbd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 26ff5cd2bf0a..cb25ee513ada 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -6062,7 +6062,7 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev,
>   	void *p;
>   	void *end;
>   	u64 seq;
> -	u32 snap_count;
> +	size_t snap_count;
>   	struct ceph_snap_context *snapc;
>   	u32 i;
>   


  reply	other threads:[~2024-03-28 14:53 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28 14:30 [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare Arnd Bergmann
2024-03-28 14:30 ` [PATCH 1/9] dm integrity: fix out-of-range warning Arnd Bergmann
2024-03-28 18:36   ` Mikulas Patocka
2024-03-28 21:58   ` Justin Stitt
2024-03-28 14:30 ` [PATCH 2/9] libceph: avoid clang " Arnd Bergmann
2024-03-28 22:53   ` Justin Stitt
2024-03-29  0:06   ` Xiubo Li
2024-03-28 14:30 ` [PATCH 3/9] rbd: avoid " Arnd Bergmann
2024-03-28 14:53   ` Alex Elder [this message]
2024-03-29  0:05     ` Xiubo Li
2024-03-28 14:30 ` [PATCH 4/9] kcov: avoid clang " Arnd Bergmann
2024-03-28 22:22   ` Justin Stitt
2024-03-28 14:30 ` [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS Arnd Bergmann
2024-03-28 14:38   ` Eric Dumazet
2024-03-28 16:39     ` Arnd Bergmann
2024-03-28 14:30 ` [PATCH 6/9] nilfs2: fix out-of-range warning Arnd Bergmann
2024-03-28 15:21   ` Philipp Stanner
2024-03-28 16:12     ` Arnd Bergmann
2024-03-28 22:04   ` Justin Stitt
2024-03-28 22:25     ` Arnd Bergmann
2024-03-29  9:20   ` Ryusuke Konishi
2024-04-01  8:50   ` (subset) " Christian Brauner
2024-03-28 14:30 ` [PATCH 7/9] infiniband: uverbs: avoid out-of-range warnings Arnd Bergmann
2024-03-28 22:12   ` Justin Stitt
2024-04-03 15:45   ` Jason Gunthorpe
2024-04-03 20:16     ` Arnd Bergmann
2024-03-28 14:30 ` [PATCH 8/9] mlx5: stop warning for 64KB pages Arnd Bergmann
2024-03-28 15:37   ` Maxim Mikityanskiy
2024-03-28 22:09   ` Justin Stitt
2024-03-28 22:21     ` Arnd Bergmann
2024-03-28 22:39   ` Tariq Toukan
2024-03-28 14:30 ` [PATCH 9/9] kbuild: enable tautological-constant-out-of-range-compare Arnd Bergmann
2024-03-29 20:00 ` [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare patchwork-bot+netdevbpf

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=b8e848fe-96d8-4f75-a2e9-2ed5c11a2fd7@ieee.org \
    --to=elder@ieee.org \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=ceph-devel@vger.kernel.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=dongsheng.yang@easystack.cn \
    --cc=elder@inktank.com \
    --cc=elder@linaro.org \
    --cc=hare@suse.de \
    --cc=idryomov@gmail.com \
    --cc=josh.durgin@inktank.com \
    --cc=justinstitt@google.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=ricardo@marliere.net \
    --cc=ruanjinjie@huawei.com \
    /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®